diff --git a/Hotel.Domain/Controllers/InvoiceController.cs b/Hotel.Domain/Controllers/InvoiceController.cs index 1abd532..14ee6c8 100644 --- a/Hotel.Domain/Controllers/InvoiceController.cs +++ b/Hotel.Domain/Controllers/InvoiceController.cs @@ -28,7 +28,7 @@ public async Task GetAsync( [FromQuery] int? skip, [FromQuery] int? take, [FromQuery] string? number, - [FromQuery] EPaymentMethod? paymentMethod, + [FromQuery] string? paymentMethod, [FromQuery] decimal? totalAmount, [FromQuery] string? totalAmountOperator, [FromQuery] EStatus? status, @@ -42,9 +42,7 @@ [FromQuery] string? issueDateOperator ) { var queryParameters = new InvoiceQueryParameters( - skip, take, number, paymentMethod, totalAmount, totalAmountOperator, status, - customerId, reservationId, serviceId, taxInformation, taxInformationOperator, - issueDate, issueDateOperator + skip, take, paymentMethod, totalAmount, totalAmountOperator, customerId, reservationId, serviceId ); return Ok(await _handler.HandleGetAsync(queryParameters)); diff --git a/Hotel.Domain/DTOs/InvoiceDTOs/GetInvoice.cs b/Hotel.Domain/DTOs/InvoiceDTOs/GetInvoice.cs index b0ae300..f55012f 100644 --- a/Hotel.Domain/DTOs/InvoiceDTOs/GetInvoice.cs +++ b/Hotel.Domain/DTOs/InvoiceDTOs/GetInvoice.cs @@ -1,30 +1,25 @@ -using Hotel.Domain.Enums; + +using Hotel.Domain.DTOs.ServiceDTOs; namespace Hotel.Domain.DTOs.InvoiceDTOs; public class GetInvoice : IDataTransferObject { - public GetInvoice(Guid id, string number, EPaymentMethod paymentMethod, Guid reservationId, DateTime issueDate, decimal totalAmount, EStatus status, decimal taxInformation, Guid customerId) + public GetInvoice(Guid id, string paymentMethod, Guid reservationId, decimal totalAmount, Guid customerId, IEnumerable services) { Id = id; PaymentMethod = paymentMethod; - TaxInformation = taxInformation; ReservationId = reservationId; - Number = number; - IssueDate = issueDate; TotalAmount = totalAmount; - Status = status; CustomerId = customerId; + Services = services; } public Guid? Id { get; private set; } - public EPaymentMethod PaymentMethod { get; private set; } - public decimal TaxInformation { get; private set; } + public string PaymentMethod { get; private set; } public Guid ReservationId { get; private set; } - public string Number { get; private set; } - public DateTime IssueDate { get; private set; } public decimal TotalAmount { get; private set; } - public EStatus Status { get; private set; } public Guid CustomerId { get; private set; } + public IEnumerable Services { get; private set; } } diff --git a/Hotel.Domain/DTOs/InvoiceDTOs/InvoiceQueryParameters.cs b/Hotel.Domain/DTOs/InvoiceDTOs/InvoiceQueryParameters.cs index ff22ee3..b8acf9e 100644 --- a/Hotel.Domain/DTOs/InvoiceDTOs/InvoiceQueryParameters.cs +++ b/Hotel.Domain/DTOs/InvoiceDTOs/InvoiceQueryParameters.cs @@ -4,35 +4,23 @@ namespace Hotel.Domain.DTOs.InvoiceDTOs; public class InvoiceQueryParameters : IDataTransferObject { - public InvoiceQueryParameters(int? skip, int? take, string? number, EPaymentMethod? paymentMethod, decimal? totalAmount, string? totalAmountOperator, EStatus? status, Guid? customerId, Guid? reservationId, Guid? serviceId, decimal? taxInformation, string? taxInformationOperator, DateTime? issueDate, string? issueDateOperator) + public InvoiceQueryParameters(int? skip, int? take, string? paymentMethod, decimal? totalAmount, string? totalAmountOperator, Guid? customerId, Guid? reservationId, Guid? serviceId) { Skip = skip; Take = take; - Number = number; - IssueDate = issueDate; TotalAmount = totalAmount; - Status = status; PaymentMethod = paymentMethod; CustomerId = customerId; ReservationId = reservationId; ServiceId = serviceId; - TaxInformation = taxInformation; - IssueDateOperator = issueDateOperator; TotalAmountOperator = totalAmountOperator; - TaxInformationOperator = taxInformationOperator; } public int? Skip { get; private set; } public int? Take { get; private set; } - public string? Number { get; private set; } - public DateTime? IssueDate { get; private set; } - public string? IssueDateOperator { get; private set; } public decimal? TotalAmount { get; private set; } public string? TotalAmountOperator { get; private set; } - public EStatus? Status { get; private set; } - public EPaymentMethod? PaymentMethod { get; private set; } + public string? PaymentMethod { get; private set; } public Guid? CustomerId { get; set; } public Guid? ReservationId { get; private set; } public Guid? ServiceId { get; private set; } - public decimal? TaxInformation { get; private set; } - public string? TaxInformationOperator { get; private set; } } diff --git a/Hotel.Domain/Data/Mappings/InvoiceMapping.cs b/Hotel.Domain/Data/Mappings/InvoiceMapping.cs index 312cbb3..802703a 100644 --- a/Hotel.Domain/Data/Mappings/InvoiceMapping.cs +++ b/Hotel.Domain/Data/Mappings/InvoiceMapping.cs @@ -13,33 +13,13 @@ public void Configure(EntityTypeBuilder builder) builder.ToTable("Invoices"); - builder.Property(x => x.Number) - .IsRequired() - .HasMaxLength(50); - - builder.HasIndex(x => x.Number) - .IsUnique(); - - builder.Property(x => x.IssueDate) - .IsRequired(); - builder.Property(x => x.TotalAmount) .IsRequired() .HasColumnType("DECIMAL(18,2)"); - ; - - builder.Property(x => x.Status) - .IsRequired() - .HasConversion(); builder.Property(x => x.PaymentMethod) - .IsRequired() - .HasConversion(); - - builder.Property(x => x.TaxInformation) - .IsRequired() - .HasColumnType("DECIMAL(18,2)"); - + .IsRequired(); + builder.Property(x => x.ReservationId) .IsRequired() .HasColumnType("UNIQUEIDENTIFIER"); diff --git a/Hotel.Domain/Entities/Interfaces/IInvoice.cs b/Hotel.Domain/Entities/Interfaces/IInvoice.cs index 2640e80..ff2fd5b 100644 --- a/Hotel.Domain/Entities/Interfaces/IInvoice.cs +++ b/Hotel.Domain/Entities/Interfaces/IInvoice.cs @@ -2,18 +2,13 @@ using Hotel.Domain.Entities.CustomerEntity; using Hotel.Domain.Entities.ReservationEntity; using Hotel.Domain.Entities.ServiceEntity; -using Hotel.Domain.Enums; namespace Hotel.Domain.Entities.Interfaces; public interface IInvoice : IEntity { - string Number { get; } - DateTime IssueDate { get; } decimal TotalAmount { get; } - EStatus Status { get; } - EPaymentMethod PaymentMethod { get; } - decimal TaxInformation { get; } + string PaymentMethod { get; } Customer? Customer { get; } Guid ReservationId { get; } Reservation? Reservation { get; } diff --git a/Hotel.Domain/Entities/InvoiceEntity/Invoice.cs b/Hotel.Domain/Entities/InvoiceEntity/Invoice.cs index 728330d..3f683db 100644 --- a/Hotel.Domain/Entities/InvoiceEntity/Invoice.cs +++ b/Hotel.Domain/Entities/InvoiceEntity/Invoice.cs @@ -3,7 +3,6 @@ using Hotel.Domain.Entities.Interfaces; using Hotel.Domain.Entities.ReservationEntity; using Hotel.Domain.Entities.ServiceEntity; -using Hotel.Domain.Enums; namespace Hotel.Domain.Entities.InvoiceEntity; @@ -11,17 +10,12 @@ public partial class Invoice : Entity, IInvoice { internal Invoice() { } - public Invoice(EPaymentMethod paymentMethod, Reservation reservation, decimal taxInformation = 0) + public Invoice(Reservation reservation) { TotalAmount = reservation.TotalAmount(); - Number = Guid.NewGuid().ToString(); //Serviço para gerar número - IssueDate = DateTime.Now; - Status = EStatus.Pending; - PaymentMethod = paymentMethod; - TaxInformation = taxInformation; + PaymentMethod = "card"; CustomerId = reservation.CustomerId; Customer = reservation.Customer; - Reservation = reservation; ReservationId = reservation.Id; Services = reservation.Services; @@ -29,12 +23,8 @@ public Invoice(EPaymentMethod paymentMethod, Reservation reservation, decimal ta } - public string Number { get; private set; } = string.Empty; - public DateTime IssueDate { get; private set; } public decimal TotalAmount { get; private set; } - public EStatus Status { get; private set; } - public EPaymentMethod PaymentMethod { get; private set; } - public decimal TaxInformation { get; private set; } + public string PaymentMethod { get; private set; } = null!; public Guid CustomerId { get; private set; } public Customer? Customer { get; private set; } public Guid ReservationId { get; private set; } diff --git a/Hotel.Domain/Entities/InvoiceEntity/UpdateProperties.cs b/Hotel.Domain/Entities/InvoiceEntity/UpdateProperties.cs deleted file mode 100644 index e129ed1..0000000 --- a/Hotel.Domain/Entities/InvoiceEntity/UpdateProperties.cs +++ /dev/null @@ -1,13 +0,0 @@ - -using Hotel.Domain.Enums; - -namespace Hotel.Domain.Entities.InvoiceEntity; - -public partial class Invoice -{ - public void FinishInvoice() - { - Status = EStatus.Finish; - } - -} \ No newline at end of file diff --git a/Hotel.Domain/Entities/InvoiceEntity/Validate.cs b/Hotel.Domain/Entities/InvoiceEntity/Validate.cs deleted file mode 100644 index 50e1211..0000000 --- a/Hotel.Domain/Entities/InvoiceEntity/Validate.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Hotel.Domain.Enums; -using Hotel.Domain.Exceptions; - -namespace Hotel.Domain.Entities.InvoiceEntity; - -public partial class Invoice -{ - public override void Validate() - { - if (Reservation?.Status != EReservationStatus.CheckedOut) - throw new ValidationException("Reserva não finalizada."); - - ValidateTaxInformation(TaxInformation); - ValidatePaymentMethod(PaymentMethod); - TotalAmount += TaxInformation; - - base.Validate(); - } - - public void ValidateTaxInformation(decimal taxInformation) - { - if (taxInformation < 0) - throw new ValidationException("O imposto da fatura não pode ser menor que 0."); - } - - public void ValidatePaymentMethod(EPaymentMethod paymentMethod) - { - if ((int)paymentMethod > 2 || (int)paymentMethod < 1) - throw new ValidationException("Método de pagamento inválido."); - - } - -} \ No newline at end of file diff --git a/Hotel.Domain/Entities/ReservationEntity/Finish.cs b/Hotel.Domain/Entities/ReservationEntity/Finish.cs index 086e889..196a7c3 100644 --- a/Hotel.Domain/Entities/ReservationEntity/Finish.cs +++ b/Hotel.Domain/Entities/ReservationEntity/Finish.cs @@ -1,6 +1,5 @@ using Hotel.Domain.Entities.InvoiceEntity; using Hotel.Domain.Enums; -using Hotel.Domain.Exceptions; namespace Hotel.Domain.Entities.ReservationEntity; @@ -28,7 +27,7 @@ public Invoice Finish() UpdateCheckOut(DateTime.Now) .ToCheckOut(); // Muda o status para CheckedOut - Invoice = new Invoice(EPaymentMethod.CreditCard, this, 0); //Gera uma instância de uma fatura + Invoice = new Invoice(this); //Gera uma instância de uma fatura Room?.ChangeStatus(ERoomStatus.OutOfService); //troca o status do quarto para 'OutOfService'(Fora de serviço) diff --git a/Hotel.Domain/Repositories/InvoiceRepository.cs b/Hotel.Domain/Repositories/InvoiceRepository.cs index 647bdfa..4c2816a 100644 --- a/Hotel.Domain/Repositories/InvoiceRepository.cs +++ b/Hotel.Domain/Repositories/InvoiceRepository.cs @@ -1,5 +1,6 @@ using Hotel.Domain.Data; using Hotel.Domain.DTOs.InvoiceDTOs; +using Hotel.Domain.DTOs.ServiceDTOs; using Hotel.Domain.Entities.InvoiceEntity; using Hotel.Domain.Extensions; using Hotel.Domain.Repositories.Base; @@ -12,14 +13,22 @@ public class InvoiceRepository : GenericRepository, IInvoiceRepository { public InvoiceRepository(HotelDbContext context) : base(context) { } - public async Task GetByIdAsync(Guid id) { return await _context .Invoices .AsNoTracking() .Where(x => x.Id == id) - .Select(x => new GetInvoice(x.Id, x.Number, x.PaymentMethod, x.ReservationId, x.IssueDate, x.TotalAmount, x.Status, x.TaxInformation, x.CustomerId)) + .Include(x => x.Services) + .Select(x => + new GetInvoice( + x.Id, + x.PaymentMethod, + x.ReservationId, + x.TotalAmount, + x.CustomerId, + x.Services.Select(s => + new GetService(s.Id, s.Name, s.Price, s.Priority, s.IsActive, s.TimeInMinutes, s.CreatedAt)))) .FirstOrDefaultAsync(); } @@ -28,19 +37,7 @@ public async Task> GetAsync(InvoiceQueryParameters query { var query = _context.Invoices.AsQueryable(); - if (queryParameters.Number != null) - query = query.Where(x => x.Number.Contains(queryParameters.Number)); - - if (queryParameters.IssueDate.HasValue) - query = query.FilterByOperator(queryParameters.IssueDateOperator, x => x.IssueDate, queryParameters.IssueDate); - - if (queryParameters.TotalAmount.HasValue) - query = query.FilterByOperator(queryParameters.TotalAmountOperator, x => x.TotalAmount, queryParameters.TotalAmount); - - if (queryParameters.Status.HasValue) - query = query.Where(x => x.Status == queryParameters.Status); - - if (queryParameters.PaymentMethod.HasValue) + if (queryParameters.PaymentMethod != null) query = query.Where(x => x.PaymentMethod == queryParameters.PaymentMethod); if (queryParameters.CustomerId.HasValue) @@ -52,22 +49,20 @@ public async Task> GetAsync(InvoiceQueryParameters query if (queryParameters.ServiceId.HasValue) query = query.Where(x => x.Services.Any(x => x.Id == queryParameters.ServiceId)); - if (queryParameters.TaxInformation.HasValue) - query = query.FilterByOperator(queryParameters.TaxInformationOperator, x => x.TaxInformation, queryParameters.TaxInformation); + if (queryParameters.TotalAmount.HasValue) + query = query.FilterByOperator(queryParameters.TotalAmountOperator, x => x.TotalAmount, queryParameters.TotalAmount); query = query.Skip(queryParameters.Skip ?? 0).Take(queryParameters.Take ?? 1); query = query.AsNoTracking(); return await query.Select(x => new GetInvoice( - x.Id, - x.Number, - x.PaymentMethod, - x.ReservationId, - x.IssueDate, - x.TotalAmount, - x.Status, - x.TaxInformation, - x.CustomerId + x.Id, + x.PaymentMethod, + x.ReservationId, + x.TotalAmount, + x.CustomerId, + x.Services.Select(s => + new GetService(s.Id, s.Name, s.Price, s.Priority, s.IsActive, s.TimeInMinutes, s.CreatedAt)) )).ToListAsync(); } } \ No newline at end of file diff --git a/Hotel.Tests/UnitTests/Entities/InvoiceEntityTest.cs b/Hotel.Tests/UnitTests/Entities/InvoiceEntityTest.cs index 1cb4167..1ffc17d 100644 --- a/Hotel.Tests/UnitTests/Entities/InvoiceEntityTest.cs +++ b/Hotel.Tests/UnitTests/Entities/InvoiceEntityTest.cs @@ -10,30 +10,6 @@ namespace Hotel.Tests.UnitTests.Entities; [TestClass] public class InvoiceEntityTest { - - [TestMethod] - public void ValidInvoice_MustBeValid() - { - var room = new Room("Quarto",1, 50, 3, "Quarto padrão", TestParameters.Category); - var reservation = new Reservation(room, DateTime.Now.Date, DateTime.Now.AddDays(1), TestParameters.Customer, 2); - - reservation.ToCheckIn(); - reservation.Finish(); - Assert.IsTrue(reservation?.Invoice?.IsValid); - } - - [TestMethod] - [ExpectedException(typeof(ValidationException))] - public void InvoiceWithoutCheckOutStatusReservation_ExpectedException() - { - var room = new Room("Quarto",1, 50, 3, "Quarto padrão", TestParameters.Category); - var reservation = new Reservation(room, DateTime.Now.Date, DateTime.Now.AddDays(1), TestParameters.Customer, 2); - reservation.ToCheckIn(); - - new Invoice(EPaymentMethod.Pix, reservation); - Assert.Fail(); - } - [TestMethod] public void TheCustomersInReservation_MustBeSameOnInvoice() { @@ -45,19 +21,4 @@ public void TheCustomersInReservation_MustBeSameOnInvoice() Assert.AreEqual(reservation.Customer, invoice.Customer); } - [TestMethod] - public void ChangeToFinishInvoiceStatus_MustBeFinishStatus() - { - var room = new Room("Quarto",1, 50, 3, "Quarto padrão", TestParameters.Category); - var reservation = new Reservation(room, DateTime.Now.Date, DateTime.Now.AddDays(1), TestParameters.Customer, 2); - reservation.ToCheckIn(); - - var invoice = reservation.Finish(); - invoice.FinishInvoice(); - Assert.AreEqual(EStatus.Finish, invoice.Status); - } - - - - } \ No newline at end of file diff --git a/Hotel.Tests/UnitTests/Repositories/InvoiceRepositoryTest.cs b/Hotel.Tests/UnitTests/Repositories/InvoiceRepositoryTest.cs index 6942395..248cd40 100644 --- a/Hotel.Tests/UnitTests/Repositories/InvoiceRepositoryTest.cs +++ b/Hotel.Tests/UnitTests/Repositories/InvoiceRepositoryTest.cs @@ -1,5 +1,4 @@ using Hotel.Domain.DTOs.InvoiceDTOs; -using Hotel.Domain.Enums; using Hotel.Domain.Repositories; using Hotel.Tests.UnitTests.Repositories.Mock; using Microsoft.EntityFrameworkCore; @@ -24,19 +23,14 @@ public async Task GetByIdAsync_ReturnsWithCorrectParameters() Assert.IsNotNull(roomInvoice); Assert.AreEqual(BaseRepositoryTest.Invoices[0].Id, roomInvoice.Id); Assert.AreEqual(BaseRepositoryTest.Invoices[0].PaymentMethod, roomInvoice.PaymentMethod); - Assert.AreEqual(BaseRepositoryTest.Invoices[0].TaxInformation, roomInvoice.TaxInformation); Assert.AreEqual(BaseRepositoryTest.Invoices[0].ReservationId, roomInvoice.ReservationId); - Assert.AreEqual(BaseRepositoryTest.Invoices[0].Number, roomInvoice.Number); - Assert.AreEqual(BaseRepositoryTest.Invoices[0].IssueDate, roomInvoice.IssueDate); Assert.AreEqual(Math.Round(BaseRepositoryTest.Invoices[0].TotalAmount), Math.Round(roomInvoice.TotalAmount)); - Assert.AreEqual(BaseRepositoryTest.Invoices[0].Status, roomInvoice.Status); - } [TestMethod] public async Task GetAsync_ReturnWithCorrectParameters() { - var parameters = new InvoiceQueryParameters(0, 100, null, BaseRepositoryTest.Invoices[0].PaymentMethod, BaseRepositoryTest.Invoices[0].TotalAmount, "eq", null, null, null, null, null, null, null, null); + var parameters = new InvoiceQueryParameters(0, 100, BaseRepositoryTest.Invoices[0].PaymentMethod, BaseRepositoryTest.Invoices[0].TotalAmount, "eq", null, null, null); var roomInvoices = await InvoiceRepository.GetAsync(parameters); var roomInvoice = roomInvoices.ToList()[0]; @@ -44,30 +38,26 @@ public async Task GetAsync_ReturnWithCorrectParameters() Assert.IsNotNull(roomInvoice); Assert.AreEqual(BaseRepositoryTest.Invoices[0].Id, roomInvoice.Id); Assert.AreEqual(BaseRepositoryTest.Invoices[0].PaymentMethod, roomInvoice.PaymentMethod); - Assert.AreEqual(BaseRepositoryTest.Invoices[0].TaxInformation, roomInvoice.TaxInformation); Assert.AreEqual(BaseRepositoryTest.Invoices[0].ReservationId, roomInvoice.ReservationId); - Assert.AreEqual(BaseRepositoryTest.Invoices[0].Number, roomInvoice.Number); - Assert.AreEqual(BaseRepositoryTest.Invoices[0].IssueDate, roomInvoice.IssueDate); Assert.AreEqual(Math.Round(BaseRepositoryTest.Invoices[0].TotalAmount), Math.Round(roomInvoice.TotalAmount)); - Assert.AreEqual(BaseRepositoryTest.Invoices[0].Status, roomInvoice.Status); } [TestMethod] - public async Task GetAsync_WherePaymentMethodEqualsCreditCard_ReturnsInvoices() + public async Task GetAsync_WhereCardPaymentMethod_ReturnsInvoices() { - var parameters = new InvoiceQueryParameters(0, 100, null, EPaymentMethod.CreditCard, null, null, null, null, null, null, null, null, null, null); + var parameters = new InvoiceQueryParameters(0, 100, "card", null, null, null, null, null); var roomInvoices = await InvoiceRepository.GetAsync(parameters); Assert.IsTrue(roomInvoices.Any()); foreach (var roomInvoice in roomInvoices) - Assert.AreEqual(EPaymentMethod.CreditCard, roomInvoice.PaymentMethod); + Assert.AreEqual("card", roomInvoice.PaymentMethod); } [TestMethod] public async Task GetAsync_WhereTotalAmountGratherThan9_ReturnsInvoices() { - var parameters = new InvoiceQueryParameters(0, 100, null, null, 9m, "gt", null, null, null, null, null, null, null, null); + var parameters = new InvoiceQueryParameters(0, 100, null, 9m, "gt", null, null, null); var roomInvoices = await InvoiceRepository.GetAsync(parameters); Assert.IsTrue(roomInvoices.Any()); @@ -80,7 +70,7 @@ public async Task GetAsync_WhereTotalAmountGratherThan9_ReturnsInvoices() [TestMethod] public async Task GetAsync_WhereTotalAmountLessThan100_ReturnsInvoices() { - var parameters = new InvoiceQueryParameters(0, 100, null, null, 100m, "lt", null, null, null, null, null, null, null, null); + var parameters = new InvoiceQueryParameters(0, 100, null, 100m, "lt", null, null, null); var roomInvoices = await InvoiceRepository.GetAsync(parameters); Assert.IsTrue(roomInvoices.Any()); @@ -92,48 +82,24 @@ public async Task GetAsync_WhereTotalAmountLessThan100_ReturnsInvoices() [TestMethod] public async Task GetAsync_WhereTotalAmountEquals_ReturnsInvoices() { - var parameters = new InvoiceQueryParameters(0, 100, null, null, BaseRepositoryTest.Invoices[3].TotalAmount, "eq", null, null, null, null, null, null, null, null); + var totalAmount = BaseRepositoryTest.Invoices[3].TotalAmount; + var parameters = new InvoiceQueryParameters(0, 100, null, totalAmount, "eq", null, null, null); var roomInvoices = await InvoiceRepository.GetAsync(parameters); Assert.IsTrue(roomInvoices.Any()); foreach (var roomInvoice in roomInvoices) - Assert.AreEqual(Math.Round(BaseRepositoryTest.Invoices[3].TotalAmount), Math.Round(roomInvoice.TotalAmount)); + Assert.AreEqual(Math.Round(totalAmount), Math.Round(roomInvoice.TotalAmount)); } - [TestMethod] - public async Task GetAsync_WhereStatusEqualsPending_ReturnsInvoices() - { - var parameters = new InvoiceQueryParameters(0, 100, null, null, null, null, EStatus.Pending, null, null, null, null, null, null, null); - var roomInvoices = await InvoiceRepository.GetAsync(parameters); - - Assert.IsTrue(roomInvoices.Any()); - foreach (var roomInvoice in roomInvoices) - Assert.AreEqual(EStatus.Pending, roomInvoice.Status); - - - } - - [TestMethod] - public async Task GetAsync_WhereStatusEqualsFinish_ReturnsInvoices() - { - - var parameters = new InvoiceQueryParameters(0, 100, null, null, null, null, EStatus.Finish, null, null, null, null, null, null, null); - var roomInvoices = await InvoiceRepository.GetAsync(parameters); - - Assert.IsTrue(roomInvoices.Any()); - foreach (var roomInvoice in roomInvoices) - Assert.AreEqual(EStatus.Finish, roomInvoice.Status); - } - [TestMethod] public async Task GetAsync_WhereCustomerId_ReturnsInvoices() { var customerWithInvoice = await BaseRepositoryTest.MockConnection.Context.Customers .FirstOrDefaultAsync(x => x.Invoices.Count > 0); - var parameters = new InvoiceQueryParameters(0, 100, null, null, null, null, null, customerWithInvoice?.Id, null, null, null, null, null, null); + var parameters = new InvoiceQueryParameters(0, 100, null, null, null, customerWithInvoice?.Id, null, null); var roomInvoices = await InvoiceRepository.GetAsync(parameters); Assert.IsTrue(roomInvoices.Any()); @@ -144,7 +110,7 @@ public async Task GetAsync_WhereCustomerId_ReturnsInvoices() [TestMethod] public async Task GetAsync_WhereReservationId_ReturnsInvoices() { - var parameters = new InvoiceQueryParameters(0, 100, null, null, null, null, null, null, BaseRepositoryTest.Reservations[0].Id, null, null, null, null, null); + var parameters = new InvoiceQueryParameters(0, 100, null, null, null, null, BaseRepositoryTest.Reservations[0].Id, null); for (var i = 0; i < 10; i++) { var roomInvoices = await InvoiceRepository.GetAsync(parameters); @@ -163,7 +129,7 @@ public async Task GetAsync_WhereServiceId_ReturnsInvoices() { var serviceWithInvoices = await BaseRepositoryTest.MockConnection.Context.Services.FirstOrDefaultAsync(x => x.Invoices.Count > 0); - var parameters = new InvoiceQueryParameters(0, 100, null, null, null, null, null, null, null, serviceWithInvoices!.Id, null, null, null, null); + var parameters = new InvoiceQueryParameters(0, 100, null, null, null, null, null, serviceWithInvoices!.Id); var roomInvoices = await InvoiceRepository.GetAsync(parameters); Assert.IsTrue(roomInvoices.Any()); @@ -178,53 +144,4 @@ public async Task GetAsync_WhereServiceId_ReturnsInvoices() } } - [TestMethod] - public async Task GetAsync_WhereTaxInformationLessThan13_ReturnsInvoices() - { - var parameters = new InvoiceQueryParameters(0, 100, null, null, null, null, null, null, null, null, 13, "lt", null, null); - var roomInvoices = await InvoiceRepository.GetAsync(parameters); - - Assert.IsTrue(roomInvoices.Any()); - - foreach (var roomInvoice in roomInvoices) - Assert.IsTrue(13 > roomInvoice.TaxInformation); - - } - - [TestMethod] - public async Task GetAsync_WhereIssueDateGratherThanYesterday_ReturnsInvoices() - { - var parameters = new InvoiceQueryParameters(0, 100, null, null, null, null, null, null, null, null, null, null, DateTime.Now.AddDays(-1), "gt"); - var roomInvoices = await InvoiceRepository.GetAsync(parameters); - - Assert.IsTrue(roomInvoices.Any()); - foreach (var roomInvoice in roomInvoices) - Assert.IsTrue(DateTime.Now.AddDays(-1) < roomInvoice.IssueDate); - - } - - [TestMethod] - public async Task GetAsync_WhereIssueDateLessThanToday_ReturnsInvoices() - { - var parameters = new InvoiceQueryParameters(0, 100, null, null, null, null, null, null, null, null, null, null, DateTime.Now.AddDays(1), "lt"); - var roomInvoices = await InvoiceRepository.GetAsync(parameters); - - Assert.IsTrue(roomInvoices.Any()); - - foreach (var roomInvoice in roomInvoices) - Assert.IsTrue(DateTime.Now.AddDays(1) > roomInvoice.IssueDate); - - } - - [TestMethod] - public async Task GetAsync_WhereIssueDateEquals_ReturnsInvoices() - { - var parameters = new InvoiceQueryParameters(0, 100, null, null, null, null, null, null, null, null, null, null, BaseRepositoryTest.Invoices[0].IssueDate, "eq"); - var roomInvoices = await InvoiceRepository.GetAsync(parameters); - - Assert.IsTrue(roomInvoices.Any()); - foreach (var roomInvoice in roomInvoices) - Assert.AreEqual(BaseRepositoryTest.Invoices[0].IssueDate, roomInvoice.IssueDate); - } - } diff --git a/Hotel.Tests/UnitTests/Repositories/Mock/CreateData/CreateInvoices.cs b/Hotel.Tests/UnitTests/Repositories/Mock/CreateData/CreateInvoices.cs index d09fea9..f469acb 100644 --- a/Hotel.Tests/UnitTests/Repositories/Mock/CreateData/CreateInvoices.cs +++ b/Hotel.Tests/UnitTests/Repositories/Mock/CreateData/CreateInvoices.cs @@ -18,7 +18,6 @@ public static async Task Create() BaseRepositoryTest.ReservationsToFinish[1].Finish(), BaseRepositoryTest.ReservationsToFinish[2].Finish(), }; - roomInvoices[0].FinishInvoice(); await BaseRepositoryTest.MockConnection.Context.Invoices.AddRangeAsync(roomInvoices); await BaseRepositoryTest.MockConnection.Context.SaveChangesAsync();