// Todo : think if mapper is doing too much private RentalDto MapCartEquipment(CartEquipment cartEquipment) { var price = _mapPriceCalculatorLogic .Create(cartEquipment.Equipment.EquipmentType) .Calculate(cartEquipment.RentDurationDays, _mutablePriceConfiguration); return(new RentalDto { Name = cartEquipment.Equipment.EquipmentName, Price = price }); }
public CartDto SubmitRentRequest(EquipmentRentRequestDto equipmentRentRequestDto) { if (equipmentRentRequestDto == null) { throw new ArgumentNullException(nameof(equipmentRentRequestDto)); } if (equipmentRentRequestDto.EquipmentRentDtos == null) // todo exception { throw new Exception(nameof(equipmentRentRequestDto)); } // Todo add messageing Bus.RaiseEvent(new CartStatusPending(cart)); var cart = new Cart { AddedDate = _dateTimeProvider.Now, ModifiedDate = _dateTimeProvider.Now }; _carts.Insert(cart); foreach (var equipmentRentDto in equipmentRentRequestDto.EquipmentRentDtos) { var equipment = _equipments.GetById(equipmentRentDto.EquipmentId); var rentDurationInDays = equipmentRentDto.DurationInDays; var cartEquipment = new CartEquipment { Cart = cart, Equipment = equipment, RentDurationDays = rentDurationInDays, RentState = RentState.StartPending, AddedDate = _dateTimeProvider.Now, ModifiedDate = _dateTimeProvider.Now, ReturnDate = null }; _cartEquipments.Insert(cartEquipment); } _writeDbContext.SaveChanges(); return(new CartDto { CartId = cart.Id }); }
public static IEnumerable <TestCaseData> HandleValidTestCases() { var loyaltyPoints = 0; var cartDto = new CartDto(); var cartEquipments = new CartEquipment[0]; var invoiceDto = new InvoiceDto { Title = $"Invoice id : {cartDto.CartId}", Rentals = Enumerable.Empty <RentalDto>(), LoyaltyPoints = 0, TotalPrice = 0 }; yield return(new TestCaseData(cartDto, cartEquipments, invoiceDto, loyaltyPoints) .SetName("HandleValidTestCases - No elements")); loyaltyPoints = 1; cartDto = new CartDto { CartId = 1 }; cartEquipments = new[] { new CartEquipment { Equipment = new Equipment { EquipmentName = "Kuvaldo H1", EquipmentType = EquipmentType.Heavy }, Id = 3, RentDurationDays = 1 } }; invoiceDto = new InvoiceDto { Title = $"Invoice id : {cartDto.CartId}", Rentals = new[] { new RentalDto { Name = "Kuvaldo H1", Price = 1 } }, LoyaltyPoints = 1, TotalPrice = 1 }; yield return(new TestCaseData(cartDto, cartEquipments, invoiceDto, loyaltyPoints) .SetName("HandleValidTestCases - 1 element")); loyaltyPoints = 2; cartDto = new CartDto { CartId = 1 }; cartEquipments = new[] { new CartEquipment { Equipment = new Equipment { EquipmentName = "Kuvaldo H1", EquipmentType = EquipmentType.Heavy }, RentDurationDays = 1 }, new CartEquipment { Equipment = new Equipment { EquipmentName = "Kuvaldo H2", EquipmentType = EquipmentType.Heavy }, RentDurationDays = 2 }, new CartEquipment { Equipment = new Equipment { EquipmentName = "Kuvaldo H3", EquipmentType = EquipmentType.Heavy }, RentDurationDays = 3 }, new CartEquipment { Equipment = new Equipment { EquipmentName = "Kuvaldo S1", EquipmentType = EquipmentType.Specialized }, RentDurationDays = 1 }, new CartEquipment { Equipment = new Equipment { EquipmentName = "Kuvaldo S2", EquipmentType = EquipmentType.Specialized }, RentDurationDays = 2 }, new CartEquipment { Equipment = new Equipment { EquipmentName = "Kuvaldo S3", EquipmentType = EquipmentType.Specialized }, RentDurationDays = 3 }, new CartEquipment { Equipment = new Equipment { EquipmentName = "Kuvaldo R1", EquipmentType = EquipmentType.Regular }, RentDurationDays = 1 }, new CartEquipment { Equipment = new Equipment { EquipmentName = "Kuvaldo R2", EquipmentType = EquipmentType.Regular }, RentDurationDays = 2 }, new CartEquipment { Equipment = new Equipment { EquipmentName = "Kuvaldo R3", EquipmentType = EquipmentType.Regular }, RentDurationDays = 3 } }; invoiceDto = new InvoiceDto { Title = $"Invoice id : {cartDto.CartId}", Rentals = new[] { new RentalDto { Name = "Kuvaldo H1", Price = 1 }, new RentalDto { Name = "Kuvaldo H2", Price = 1 }, new RentalDto { Name = "Kuvaldo H3", Price = 1 }, new RentalDto { Name = "Kuvaldo R1", Price = 2 }, new RentalDto { Name = "Kuvaldo R2", Price = 2 }, new RentalDto { Name = "Kuvaldo R3", Price = 2 }, new RentalDto { Name = "Kuvaldo S1", Price = 3 }, new RentalDto { Name = "Kuvaldo S2", Price = 3 }, new RentalDto { Name = "Kuvaldo S3", Price = 3 } }, LoyaltyPoints = 2, TotalPrice = 18 }; yield return(new TestCaseData(cartDto, cartEquipments, invoiceDto, loyaltyPoints) .SetName("HandleValidTestCases - 9 element variants {RentDurationDays, Equipment.EquipmentType}")); loyaltyPoints = 1; cartDto = new CartDto { CartId = 1 }; cartEquipments = Data.Equipments.Select(o => new CartEquipment { Equipment = o, Id = 1, RentDurationDays = 1 }).ToArray(); invoiceDto = new InvoiceDto { Title = $"Invoice id : {cartDto.CartId}", Rentals = new[] { new RentalDto { Name = "Caterpillar bulldozer", Price = 1 }, new RentalDto { Name = "KamAZ truck", Price = 2 }, new RentalDto { Name = "Komatsu crane", Price = 1 }, new RentalDto { Name = "Volvo steamroller", Price = 2 }, new RentalDto { Name = "Bosch jackhammer", Price = 3 } }, LoyaltyPoints = 1, TotalPrice = 9 }; yield return(new TestCaseData(cartDto, cartEquipments, invoiceDto, loyaltyPoints) .SetName("HandleValidTestCases - Seed data")); }