public void CreateRentalWillCreateRentalObject() { //Arrange var testHelper = new TestHelper(); var testData = testHelper.CreateEquipmentList(); IRentalRepository rentalRepository = Substitute.For<IRentalRepository>(); IUnitOfWork uow = Substitute.For<IUnitOfWork>(); uow.RentalRepository.Returns(rentalRepository); RentalService rs = new RentalService(uow); Rental rental = new Rental(); rental.CustomerName = "Johan Eriksson"; rental.CustomerPhoneNumber = "0705556677"; rental.StartTime = DateTime.Now; rental.EquipmentId = testData[0].Id; RentalPlan rp = new RentalPlan(); rp.Id = 1; rp.Duration = 8; rp.Discount = 0; rental.RentalPlanId = rp.Id; //Act rs.CreateRental(rental); //Assert rentalRepository.Received().CreateRental(rental); }
public void CreateRentalShouldStoreRental() { int eqid; int rpid; using (var context = new SkiRentalContext()) { var uow = new UnitOfWork(context); Equipment e1 = new Equipment(); e1.ProductName = "EQtest1"; e1.EquipmentTypeId = 1; e1.EquipmentStateId = 1; e1.PurchaseDate = DateTime.Now; e1.PurchasePrice = 500; RentalPlan rp1 = new RentalPlan(); rp1.Duration = 8; rp1.Discount = 0.25; context.Equipments.Add(e1); context.RentalPlans.Add(rp1); uow.Save(); eqid = e1.Id; rpid = rp1.Id; } using (var context = new SkiRentalContext()) { var uow = new UnitOfWork(context); Rental rental = new Rental(); rental.CustomerName = "Johan Eriksson"; rental.CustomerPhoneNumber = "0705556677"; rental.StartTime = DateTime.Now; rental.EquipmentId = eqid; rental.RentalPlanId = rpid; uow.RentalRepository.CreateRental(rental); uow.Save(); } using (var context = new SkiRentalContext()) { context.Rentals.Should().NotBeNullOrEmpty(); context.Rentals.Where(r => r.CustomerName == "Johan Eriksson").Should().HaveCount(1); } }
public void GetAllRentalsShouldNotBeEmpty() { using (var context = new SkiRentalContext()) { var uow = new UnitOfWork(context); var eqList = CreateEquipmentList(); RentalPlan rp1 = new RentalPlan(); rp1.Duration = 8; rp1.Discount = 0.25; context.RentalPlans.Add(rp1); Rental rental = new Rental(); rental.CustomerName = "Johan Eriksson"; rental.CustomerPhoneNumber = "0705556677"; rental.StartTime = DateTime.Now; rental.EquipmentId = eqList[0].Id; rental.RentalPlanId = rp1.Id; Rental rental2 = new Rental(); rental2.CustomerName = "Anna Nilsson"; rental2.CustomerPhoneNumber = "0738887766"; rental2.StartTime = DateTime.Now; rental2.EquipmentId = eqList[1].Id; rental2.RentalPlanId = rp1.Id; uow.RentalRepository.CreateRental(rental); uow.RentalRepository.CreateRental(rental2); uow.Save(); } using (var context = new SkiRentalContext()) { var uow = new UnitOfWork(context); var rentals = uow.RentalRepository.GetAllRentals(); rentals.Should().NotBeEmpty(); } }
private string RentalPlanToDescription(RentalPlan plan) { StringBuilder description = new StringBuilder(); if (plan.Duration < 24) { AppendHours(description, plan.Duration); } else { int days = plan.Duration / 24; AppendDays(description, days); int hours = plan.Duration % 24; AppendHours(description, hours); } int discountPercentage = (int)(-plan.Discount * 100); description.AppendFormat(" ({0}%)", discountPercentage); return description.ToString(); }
public void GetAllRentalsShouldContainTwoRentals() { //Arrange var testHelper = new TestHelper(); var testData = testHelper.CreateEquipmentList(); RentalPlan rp = new RentalPlan(); rp.Id = 1; rp.Duration = 8; rp.Discount = 0; Rental rental = new Rental(); rental.CustomerName = "Johan Eriksson"; rental.CustomerPhoneNumber = "0705556677"; rental.StartTime = DateTime.Now; rental.EquipmentId = testData[0].Id; rental.RentalPlanId = rp.Id; Rental rental2 = new Rental(); rental2.CustomerName = "Johan Eriksson"; rental2.CustomerPhoneNumber = "0705556677"; rental2.StartTime = DateTime.Now; rental2.EquipmentId = testData[1].Id; rental2.RentalPlanId = rp.Id; IRentalRepository rentalRepository = Substitute.For<IRentalRepository>(); rentalRepository.GetAllRentals().Returns(new List<Rental> { rental, rental2}); IUnitOfWork uow = Substitute.For<IUnitOfWork>(); uow.RentalRepository.Returns(rentalRepository); RentalService rs = new RentalService(uow); //Act var rentals = rs.GetAllRentals(); //Assert rentals.Should().HaveCount(2); }
public void GetPriceReturnsRightPrice() { //Arrange RentalPlan rPlan = new RentalPlan { Id=1, Discount = 0.25, Duration = 8 }; EquipmentType eType = new EquipmentType { Id=1, TypeName = "SkiBoots", PricePerHour = 50 }; ITypesRepository typesRepository = Substitute.For<ITypesRepository>(); typesRepository.GetEquipmentTypeByEquipmentId(1).Returns(eType); IPlansRepository plansRepository = Substitute.For<IPlansRepository>(); plansRepository.GetRentalPlanById(1).Returns(rPlan); IUnitOfWork uow = Substitute.For<IUnitOfWork>(); uow.PlansRepository.Returns(plansRepository); uow.TypesRepository.Returns(typesRepository); PricesService pricesService = new PricesService(uow); //Act var price = pricesService.GetPrice(eType.Id, rPlan.Id); //Assert price.Should().Be(300); }
public async Task<double> GetRentalPriceAsync(RentalPlan plan, Equipment equipment) { var price = await restService.GetAsync<double>("api/prices?planId=" + plan.Id + "&equipmentId=" + equipment.Id); return price; }
public void GetEquipmentsByRentalStateReturnsEquipmentsWithCorrectRentalState() { int availableId; int rentedId; using (var context = new SkiRentalContext()) { var uow = new UnitOfWork(context); Equipment e1 = new Equipment(); e1.ProductName = "EQtest1"; e1.EquipmentTypeId = 1; e1.EquipmentStateId = 1; e1.PurchaseDate = DateTime.Now; e1.PurchasePrice = 500; Equipment e2 = new Equipment(); e2.ProductName = "EQtest2"; e2.EquipmentTypeId = 2; e2.EquipmentStateId = 2; e2.PurchaseDate = DateTime.Now; e2.PurchasePrice = 600; context.Equipments.Add(e1); context.Equipments.Add(e2); RentalPlan rp1 = new RentalPlan(); rp1.Duration = 8; rp1.Discount = 0.25; context.RentalPlans.Add(rp1); Rental rental = new Rental(); rental.CustomerName = "Johan Eriksson"; rental.CustomerPhoneNumber = "0705556677"; rental.StartTime = DateTime.Now; rental.Equipment = e1; rental.RentalPlan = rp1; uow.RentalRepository.CreateRental(rental); uow.Save(); availableId = e2.Id; rentedId = e1.Id; } using (var context = new SkiRentalContext()) { var uow = new UnitOfWork(context); var availableEq = uow.EquipmentRepository.GetEquipmentsByRentalState(false); var rentedEq = uow.EquipmentRepository.GetEquipmentsByRentalState(true); availableEq.Should().HaveCount(1); rentedEq.Should().HaveCount(1); availableEq[0].Id.Should().Be(availableId); rentedEq[0].Id.Should().Be(rentedId); } }