73 lines
2.6 KiB
C#
73 lines
2.6 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using System.Configuration;
|
|
using System.Reflection;
|
|
using Models.Models;
|
|
using Models.Repositories;
|
|
|
|
namespace phronCare.Test
|
|
{
|
|
[TestFixture]
|
|
public class TicketRepositoryTests
|
|
{
|
|
private TicketRepository _ticketRepository;
|
|
private PhronCareOperationsHubContext _context;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
#if NETCOREAPP
|
|
// Copiar el archivo config para asegurarse de que ConfigurationManager lo encuentre
|
|
string configFile = $"{Assembly.GetExecutingAssembly().Location}.config";
|
|
string outputConfigFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
|
|
File.Copy(configFile, outputConfigFile, true);
|
|
#endif
|
|
|
|
// Obtener la cadena de conexión desde app.config usando ConfigurationManager
|
|
var connectionString = ConfigurationManager.ConnectionStrings["OperationsHub"]?.ConnectionString;
|
|
|
|
if (string.IsNullOrEmpty(connectionString))
|
|
{
|
|
throw new InvalidOperationException("No se encontró la cadena de conexión 'OperationsHub'.");
|
|
}
|
|
|
|
var optionsBuilder = new DbContextOptionsBuilder<PhronCareOperationsHubContext>();
|
|
optionsBuilder.UseSqlServer(connectionString);
|
|
|
|
_context = new PhronCareOperationsHubContext(optionsBuilder.Options);
|
|
_ticketRepository = new TicketRepository(_context);
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
// Verifica que _context no sea null antes de llamarlo
|
|
_context?.Dispose();
|
|
}
|
|
[Test]
|
|
public async Task GetSummaryAsync_ShouldReturnValidSummaryData()
|
|
{
|
|
// Act
|
|
var summaryData = await _ticketRepository.GetSummaryAsync();
|
|
|
|
// Assert
|
|
Assert.That(summaryData, Is.Not.Null, "El resumen no debe ser nulo");
|
|
Assert.That(summaryData.Any(), Is.True, "El resumen debe contener al menos un elemento");
|
|
|
|
foreach (var item in summaryData)
|
|
{
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(item.Estado, Is.Not.Null, "El campo Estado no debe ser nulo");
|
|
Assert.That(item.Cantidad, Is.GreaterThanOrEqualTo(0), "La cantidad debe ser mayor o igual a cero");
|
|
});
|
|
}
|
|
}
|
|
[Test]
|
|
public async Task GetAllAsync_ReturnsAllTickets()
|
|
{
|
|
var tickets = await _ticketRepository.GetAllAsync();
|
|
Assert.That(tickets, Is.Not.Null);
|
|
Assert.That(tickets.Any(), Is.True);
|
|
}
|
|
}
|
|
} |