public async Task UploadContractAsync_SouldReturn_True_IfEntityExistAndContentIsCorrect() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var firstRent = new RentAgreement { Id = 1, Description = "Some", ParkingSlotDescription = "None", MonthlyPrice = 2000, StartDate = new DateTime(2018, 3, 3), IsActual = true }; await db.RentAgreements.AddAsync(firstRent); await db.SaveChangesAsync(); var rentService = new RentsService(mapper, db, null); var contractContent = new byte[] { 121 }; //Act var result = await rentService.UploadContractAsync(contractContent, 1); var uploadedRent = await db.RentAgreements.FindAsync(1); //Assert result .Should() .BeTrue(); uploadedRent .Should() .Match <RentAgreement>(ra => ra.Contracts .Any(x => x.ScannedContract.Length == contractContent.Length)); }
public async Task UploadContractAsync_SouldReturn_False_IfEntityD0NotExist() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var firstRent = new RentAgreement { Id = 1, Description = "Some", ParkingSlotDescription = "None", MonthlyPrice = 2000, StartDate = new DateTime(2018, 3, 3), IsActual = true }; await db.RentAgreements.AddAsync(firstRent); await db.SaveChangesAsync(); var rentService = new RentsService(mapper, db, null); var contractContent = new byte[] { 121 }; //Act var result = await rentService.UploadContractAsync(contractContent, 2); var uploadedRent = await db.RentAgreements.FindAsync(2); //Assert result .Should() .BeFalse(); uploadedRent .Should() .BeNull(); }
public async Task EditDescriptionAsync_SouldReturn_False_IfInputIsNotCorrect() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var firstRent = new RentAgreement { Id = 1, Description = "Some", ParkingSlotDescription = "None" }; await db.RentAgreements.AddAsync(firstRent); await db.SaveChangesAsync(); var rentService = new RentsService(mapper, db, null); var result = await rentService.EditDescriptionsAsync("Property Description", "Parking description", 2); var editedRent = await db.RentAgreements.FindAsync(2); result .Should() .BeFalse(); editedRent .Should() .BeNull(); }
public async Task TerminateAsync_SouldReturn_False_IfEntityDoNotExist() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var firstRent = new RentAgreement { Id = 1, Description = "Some", ParkingSlotDescription = "None", MonthlyPrice = 2000, StartDate = new DateTime(2018, 3, 3), IsActual = true }; await db.RentAgreements.AddAsync(firstRent); await db.SaveChangesAsync(); var rentService = new RentsService(mapper, db, null); var result = await rentService.TerminateAsync(2); var tereminatedRent = await db.RentAgreements.FindAsync(2); result .Should() .BeFalse(); tereminatedRent .Should() .BeNull(); }
public async Task EditDescriptionAsync_SouldReturn_True_IfInputIsCorrect() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var firstRent = new RentAgreement { Id = 1, Description = "Some", ParkingSlotDescription = "None" }; await db.RentAgreements.AddAsync(firstRent); await db.SaveChangesAsync(); var rentService = new RentsService(mapper, db, null); var result = await rentService.EditDescriptionsAsync("Property Description", "Parking description", 1); var editedRent = await db.RentAgreements.FindAsync(1); result .Should() .BeTrue(); editedRent .Should() .BeOfType <RentAgreement>() .And .Match <RentAgreement>(c => c.ParkingSlotDescription == "Parking description" && c.Description == "Property Description"); }
public async Task CreateAsync_ShouldReturn_True_IfRentagreementExist() { var db = GetDatabase(); var mapper = GetMapper(); var firstRent = new RentAgreement { Id = 1 }; var secndRent = new RentAgreement { Id = 2 }; await db.RentAgreements.AddRangeAsync(firstRent, secndRent); await db.SaveChangesAsync(); var rentPaymentService = new MonthlyRentsService(mapper, db); //Act var result = await rentPaymentService.CreateAsync(1, 1234, new DateTime(2018, 12, 12)); var createdRentPayment = await db.MonthlyPaymentRents .FirstOrDefaultAsync(x => x.TotalPayment == 1234 *1.20m && x.DeadLine == new DateTime(2018, 12, 12)); //Assert result .Should() .BeTrue(); createdRentPayment .Should() .NotBeNull(); }
public async Task GetDetailsAsync_SouldReturn_DetaildInformation_IfEntityExist() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var client = new Client { Id = 1, Name = "Margaritka 89" }; await db.Clients.AddAsync(client); var property = new Property { Id = 1, Area = 2000, Name = "Warehouse" }; await db.Properties.AddAsync(property); var firstRent = new RentAgreement { Id = 1, Description = "Some", ParkingSlotDescription = "None", MonthlyPrice = 2000, StartDate = new DateTime(2018, 3, 3), Client = client, PropertyRents = new List <PropertyRent>() { new PropertyRent { Property = property } } }; await db.RentAgreements.AddAsync(firstRent); await db.SaveChangesAsync(); var rentService = new RentsService(mapper, db, null); var result = await rentService.GetDetailsAsync(1); result .Should() .BeOfType <RentDetailsModel>() .And .Match <RentDetailsModel>(r => r.Client == "Margaritka 89" && r.Description == "Some" && r.EndDate == null && r.MonthlyPrice == 2000 && r.ParkingSlotDescription == "None" && r.Properties.Any(x => x.Area == 2000) && r.StartDate == new DateTime(2018, 3, 3) ); }
public async Task GetDetailsAsync_ShouldReturn_CorrectModel_IfRentAgreementExistInDb() { var db = GetDatabase(); var mapper = GetMapper(); var firstRentAgreement = new RentAgreement { Id = 1, MonthlyPrice = 1000, PropertyRents = new List <PropertyRent> { new PropertyRent { Property = new Property { Id = 1, Name = "Room", Area = 10, IsActual = true } } }, Client = new Client { Id = 1, Name = "Petar" }, ParkingSlots = new List <ParkingSlot> { new ParkingSlot { Id = 1, Quantity = 10, Price = 10 }, new ParkingSlot { Id = 2, Quantity = 2, Price = 2 } } }; await db.RentAgreements.AddAsync(firstRentAgreement); await db.SaveChangesAsync(); var rentPaymentService = new MonthlyRentsService(mapper, db); //Act var result = await rentPaymentService.GetDetailsAsync(1); //Assert result .Should() .Match <CreateMonthlyRentFormViewModel>(x => x.Client == "Petar" && x.ParkingSlotsQty == 12 && x.Properties.Contains("Room с площ: 10") && x.TotalPayment == 1104 && x.RentAgreementId == 1); }
public async Task AllAsync_SouldReturn_CollectionWithActualRentAgreements_FromDb() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var firstRent = new RentAgreement { Id = 1, MonthlyPrice = 800, IsActual = false, Client = new Client { Id = 1, Name = "Asen" } }; var secondRent = new RentAgreement { Id = 2, MonthlyPrice = 900, IsActual = true, Client = new Client { Id = 2, Name = "Boris" } }; var thirdRent = new RentAgreement { Id = 3, MonthlyPrice = 1900, IsActual = true, Client = new Client { Id = 3, Name = "Ceco" } }; var forthRent = new RentAgreement { Id = 4, MonthlyPrice = 2900, IsActual = true, Client = new Client { Id = 4, Name = "Asen" } }; await db.RentAgreements.AddRangeAsync(firstRent, secondRent, thirdRent, forthRent); await db.SaveChangesAsync(); var rentService = new RentsService(mapper, db, null); var result = await rentService.AllAsync(); result .Should() .NotBeEmpty() .And .BeOfType <List <RentListingViewModel> >() .And .HaveCount(3) .And .Match(c => c.ElementAt(0).Id == 4 && c.ElementAt(1).Id == 2); }
public async Task CreateMonthlyConsumable_ShouldReturn_True_IfInputCorrect() { var db = GetDatabase(); var mapper = GetMapper(); var rent = new RentAgreement { Id = 1, IsActual = true }; await db.RentAgreements.AddAsync(rent); await db.SaveChangesAsync(); var consumabelService = new MonthlyConsumablesService(mapper, db); var consumableInput = new MonthlyConsumablesBindingModel { DeadLine = new DateTime(2018, 12, 24), ElectricityDay = 1, ElectricityNight = 2, ElectricityPeak = 3, PaymentForElectricity = 4, PaymentForWater = 5, WaterReport = 6, rentId = 1 }; //Act var result = await consumabelService.CreateAsync(consumableInput); var createdConsumable = await db.MonthlyPaymentConsumables .FirstOrDefaultAsync(x => x.ElectricityDay == 1 && x.PaymentForWater == 5); //Assert result .Should() .BeTrue(); createdConsumable .Should() .Match <MonthlyPaymentConsumable>(x => x.DeadLine == new DateTime(2018, 12, 24) && x.ElectricityDay == 1 && x.ElectricityNight == 2 && x.ElectricityPeak == 3 && x.PaymentForElectricity == 4 && x.PaymentForWater == 5 && x.WaterReport == 6); }
public async Task GetCreateInfoAsync_ShouldReturn_CreateModel_IfRentExistInDb() { var db = GetDatabase(); var mapper = GetMapper(); var rent = new RentAgreement { Id = 1, IsActual = true, Client = new Client { Id = 1, Name = "Ivan", AccountableName = "Parkash" }, PropertyRents = new List <PropertyRent>() { new PropertyRent { Property = new Property { Id = 1, Name = "Office Grande", Area = 122 } }, new PropertyRent { Property = new Property { Id = 2, Name = "Room", Area = 20 } } } }; await db.RentAgreements.AddAsync(rent); await db.SaveChangesAsync(); var consumabelService = new MonthlyConsumablesService(mapper, db); //Act var result = await consumabelService.GetCreateInfoAsync(1); //Assert result .Should() .BeOfType <CreateMonthlyConsumablesModel>() .And .Match <CreateMonthlyConsumablesModel>(x => x.Client == "Ivan" && x.Properties.Any(p => p.Contains("Office Grande"))); }
public async Task GetDetailsAsync_ShouldReturn_Null_IfRentAgreementDoNotExistInDb() { var db = GetDatabase(); var mapper = GetMapper(); var firstRentAgreement = new RentAgreement { Id = 1, MonthlyPrice = 1000, PropertyRents = new List <PropertyRent> { new PropertyRent { Property = new Property { Id = 1, Name = "Room", Area = 10, IsActual = true } } }, Client = new Client { Id = 1, Name = "Petar" }, ParkingSlots = new List <ParkingSlot> { new ParkingSlot { Id = 1, Quantity = 10, Price = 10 }, new ParkingSlot { Id = 2, Quantity = 2, Price = 2 } } }; await db.RentAgreements.AddAsync(firstRentAgreement); await db.SaveChangesAsync(); var rentPaymentService = new MonthlyRentsService(mapper, db); //Act var result = await rentPaymentService.GetDetailsAsync(2); //Assert result .Should() .BeNull(); }
public async Task GetCreateInfoAsync_ShouldReturn_Null_IfRentDoNotExistInDb() { var db = GetDatabase(); var mapper = GetMapper(); var rent = new RentAgreement { Id = 1, IsActual = true, Client = new Client { Id = 1, Name = "Ivan", AccountableName = "Parkash" }, PropertyRents = new List <PropertyRent>() { new PropertyRent { Property = new Property { Id = 1, Name = "Office Grande", Area = 122 } }, new PropertyRent { Property = new Property { Id = 2, Name = "Room", Area = 20 } } } }; await db.RentAgreements.AddAsync(rent); await db.SaveChangesAsync(); var consumabelService = new MonthlyConsumablesService(mapper, db); //Act var result = await consumabelService.GetCreateInfoAsync(2); //Assert result .Should() .BeNull(); }
public async Task GetDetailsAsync_SouldReturn_Null_IfEntityDoNotExist() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var client = new Client { Id = 1, Name = "Margaritka 89" }; await db.Clients.AddAsync(client); var property = new Property { Id = 1, Area = 2000, Name = "Warehouse" }; await db.Properties.AddAsync(property); var firstRent = new RentAgreement { Id = 1, Description = "Some", ParkingSlotDescription = "None", MonthlyPrice = 2000, StartDate = new DateTime(2018, 3, 3), Client = client, PropertyRents = new List <PropertyRent>() { new PropertyRent { Property = property } } }; await db.RentAgreements.AddAsync(firstRent); await db.SaveChangesAsync(); var rentService = new RentsService(mapper, db, null); var result = await rentService.GetDetailsAsync(2); result .Should() .BeNull(); }
public async Task AllFreeAsync_SouldReturn_CollectionWithFreeProperties_FromDb() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var firstRentAgreement = new RentAgreement { Id = 1, EndDate = new DateTime(2000, 12, 12) }; var secondRentAgreement = new RentAgreement { Id = 2, EndDate = new DateTime(2002, 12, 12) }; var thirdRentAgreement = new RentAgreement { Id = 3, EndDate = new DateTime(2050, 12, 12) }; var forthtRentAgreement = new RentAgreement { Id = 4, EndDate = new DateTime(2004, 12, 12) }; var fifthRentAgreement = new RentAgreement { Id = 5, EndDate = null }; var firstProp = new Property { Id = 1, Name = "Голям склад", Area = 400, IsActual = true, PropertyRents = new List <PropertyRent>() { new PropertyRent { RentAgreement = firstRentAgreement }, new PropertyRent { RentAgreement = secondRentAgreement } } }; var secondProp = new Property { Id = 2, Name = "Голям склад", Area = 300, IsActual = true, PropertyRents = new List <PropertyRent>() { new PropertyRent { RentAgreement = thirdRentAgreement } } }; var thirdProp = new Property { Id = 3, Name = "Офис", Area = 80, IsActual = true, PropertyRents = new List <PropertyRent>() { new PropertyRent { RentAgreement = forthtRentAgreement } } }; var forthProp = new Property { Id = 4, Name = "Стая", Area = 20, IsActual = true, PropertyRents = new List <PropertyRent>() { new PropertyRent { RentAgreement = fifthRentAgreement } } }; await db.Properties.AddRangeAsync(firstProp, secondProp, thirdProp, forthProp); await db.SaveChangesAsync(); var propertyService = new PropertiesService(mapper, db); var result = await propertyService.AllFreeAsync(); result .Should() .NotBeEmpty() .And .HaveCount(2) .And .Match(c => c.ElementAt(0).Id == 1 && c.ElementAt(1).Area == 80); }
public async Task MonthIncomeStatisctic_ShouldReturn_CorrectStatisctic() { var db = GetDatabase(); var mapper = GetMapper(); var firstRent = new RentAgreement { Id = 1, MonthlyPrice = 100, ParkingSlots = new List <ParkingSlot> { new ParkingSlot { Id = 1, Price = 1, Quantity = 10, Area = ParkingSlotArea.BackParking }, new ParkingSlot { Id = 2, Price = 5, Quantity = 11, Area = ParkingSlotArea.FrontParking }, new ParkingSlot { Id = 3, Price = 10, Quantity = 20, Area = ParkingSlotArea.NoReserved }, }, MonthlyConsumables = new List <MonthlyPaymentConsumable> { new MonthlyPaymentConsumable { Id = 1, PaymentForElectricity = 250, PaymentForWater = 150, Payment = new Payment { Id = 1, Amount = 400, PaidOn = new DateTime(2018, 6, 6), CashPayment = true }, //this payment to be include in statistic DeadLine = new DateTime(2018, 6, 3) }, new MonthlyPaymentConsumable { Id = 2, PaymentForElectricity = 150, PaymentForWater = 150, Payment = new Payment { Id = 2, Amount = 300, PaidOn = new DateTime(2018, 7, 6), CashPayment = false }, DeadLine = new DateTime(2018, 7, 3) }, }, MonthlyRents = new List <MonthlyPaymentRent> { new MonthlyPaymentRent { Id = 1, ApplyVAT = true, Payments = new List <Payment> { new Payment { Id = 3, PaidOn = new DateTime(2018, 6, 6), Amount = 238, CashPayment = true }, //this payment to be include in statistic new Payment { Id = 4, PaidOn = new DateTime(2018, 6, 10), Amount = 200, CashPayment = false }, //this payment to be include in statistic }, DeadLine = new DateTime(2018, 6, 3) }, new MonthlyPaymentRent { Id = 2, ApplyVAT = true, Payments = new List <Payment> { new Payment { Id = 5, PaidOn = new DateTime(2018, 7, 6), Amount = 438, CashPayment = false }, }, DeadLine = new DateTime(2018, 7, 3) } } }; var secondRent = new RentAgreement { Id = 2, MonthlyPrice = 1000, ParkingSlots = new List <ParkingSlot> { new ParkingSlot { Id = 4, Price = 1, Quantity = 10, Area = ParkingSlotArea.BackParking }, new ParkingSlot { Id = 5, Price = 5, Quantity = 11, Area = ParkingSlotArea.FrontParking }, new ParkingSlot { Id = 6, Price = 10, Quantity = 20, Area = ParkingSlotArea.NoReserved }, }, MonthlyConsumables = new List <MonthlyPaymentConsumable> { new MonthlyPaymentConsumable { Id = 3, PaymentForElectricity = 250, PaymentForWater = 150, Payment = new Payment { Id = 6, Amount = 400, PaidOn = new DateTime(2018, 8, 6), CashPayment = true }, DeadLine = new DateTime(2018, 8, 3) }, new MonthlyPaymentConsumable { Id = 4, PaymentForElectricity = 150, PaymentForWater = 150, Payment = new Payment { Id = 7, Amount = 300, PaidOn = new DateTime(2018, 9, 6), CashPayment = false }, DeadLine = new DateTime(2018, 9, 3) }, }, MonthlyRents = new List <MonthlyPaymentRent> { new MonthlyPaymentRent { Id = 3, ApplyVAT = true, Payments = new List <Payment> { new Payment { Id = 8, PaidOn = new DateTime(2018, 8, 6), Amount = 238, CashPayment = true }, new Payment { Id = 9, PaidOn = new DateTime(2018, 8, 10), Amount = 200, CashPayment = false }, }, DeadLine = new DateTime(2018, 8, 3) }, new MonthlyPaymentRent { Id = 4, ApplyVAT = true, Payments = new List <Payment> { new Payment { Id = 10, PaidOn = new DateTime(2018, 9, 6), Amount = 438, CashPayment = false }, }, DeadLine = new DateTime(2018, 9, 3) } } }; await db.RentAgreements.AddRangeAsync(firstRent, secondRent); await db.SaveChangesAsync(); var paymentService = new PaymentsService(mapper, db, null); //Act var result = await paymentService.MonthIncomeStatistic(new DateTime(2018, 6, 20)); //Assert result .Should() .Match <MonthlyPaymentStatisticView>(x => x.ConsumablesInCash == 400 && x.RentInCash == 238 && x.TotalConsumablesPayment == 400 && x.TotalRentPayment == 438 && x.VAT == 73 && x.IncomeBackParking == 10 && x.IncomeFronParking == 55 && x.IncomeNoReservedParking == 200); }
public async Task <bool?> CreateAsync(CreateRentModel model) { var rentAgreement = new RentAgreement() { StartDate = model.StartDate, EndDate = model.EndDate, ClientId = model.ClientId, Description = model.Description, ParkingSlotDescription = model.ParkingSlotDescription, MonthlyPrice = model.MonthlyPrice }; if (model.PropertiesIds != null) { var listProperties = new List <PropertyRent>(); foreach (var propertyId in model.PropertiesIds) { listProperties.Add(new PropertyRent() { PropertyId = propertyId }); } rentAgreement.PropertyRents = listProperties; } var listParkingSlots = new List <ParkingSlot>(); if (model.CarSlots > 0) { listParkingSlots.Add(new ParkingSlot() { Type = ParkingSlotType.Car, Quantity = model.CarSlots, Price = model.CarMonthPrice, Area = model.CarsArea }); } if (model.BusSlots > 0) { listParkingSlots.Add(new ParkingSlot() { Type = ParkingSlotType.Bus, Quantity = model.BusSlots, Price = model.BusMonthPrice, Area = model.BusesArea }); } if (model.TruckSlots > 0) { listParkingSlots.Add(new ParkingSlot() { Type = ParkingSlotType.Truck, Quantity = model.TruckSlots, Price = model.TruckMonthPrice, Area = model.TrucksArea }); } if (model.BigTruckSlots > 0) { listParkingSlots.Add(new ParkingSlot() { Type = ParkingSlotType.BigTruck, Quantity = model.BigTruckSlots, Price = model.BigTruckMonthPrice, Area = model.BigTrucksArea }); } if (model.CarCageSlots > 0) { listParkingSlots.Add(new ParkingSlot() { Type = ParkingSlotType.CarCage, Quantity = model.CarCageSlots, Price = model.CarCageMonthPrice, Area = model.CarCagesArea }); } if (model.OtherSlots > 0) { listParkingSlots.Add(new ParkingSlot() { Type = ParkingSlotType.Other, Quantity = model.OtherSlots, Price = model.OtherMonthPrice, Area = model.OthersArea }); } rentAgreement.ParkingSlots = listParkingSlots; var result = await this.Db.RentAgreements.AddAsync(rentAgreement); try { await this.Db.SaveChangesAsync(); } catch (Exception) { return(false); } int deadlineYear = DateTime.UtcNow.Year; int deadlineMonth = DateTime.UtcNow.Month; var deadline = new DateTime(deadlineYear, deadlineMonth, 5); var totalPrice = result.Entity.MonthlyPrice + result.Entity.ParkingSlots.Sum(x => x.Price * x.Quantity); var isPaymentCreated = await this.monthlyRents.CreateAsync(result.Entity.Id, totalPrice, deadline); if (!isPaymentCreated) { return(null); } return(true); }
public async Task CreateAsync_SouldReturn_True_IfAllArguentsAreCorrect() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var thirdRent = new RentAgreement { Id = 3, MonthlyPrice = 1900, IsActual = true }; var forthRent = new RentAgreement { Id = 4, MonthlyPrice = 2900, IsActual = true }; await db.RentAgreements.AddRangeAsync(thirdRent, forthRent); var client = new Client { Id = 1, Name = "Ivan" }; await db.Clients.AddAsync(client); var propertyOne = new Property { Id = 1, Area = 800, IsActual = true }; var propertyTwo = new Property { Id = 2, Area = 600, IsActual = true }; await db.Properties.AddRangeAsync(propertyTwo, propertyOne); await db.SaveChangesAsync(); var createModel = new CreateRentModel { StartDate = new DateTime(2018, 3, 3), ClientId = 1, Description = "No Desc", ParkingSlotDescription = "Some Desc", MonthlyPrice = 2000, PropertiesIds = new List <int>() { 1, 2 }, CarSlots = 1, CarMonthPrice = 1, BusSlots = 2, BusMonthPrice = 2, TruckSlots = 3, TruckMonthPrice = 3, BigTruckSlots = 4, BigTruckMonthPrice = 4, CarCageSlots = 5, CarCageMonthPrice = 5, OtherSlots = 6, OtherMonthPrice = 6 }; var monthlyRentMock = new Mock <IMonthlyRentsService>(); monthlyRentMock .Setup(mr => mr.CreateAsync(It.IsAny <int>(), It.IsAny <decimal>(), It.IsAny <DateTime>())) .ReturnsAsync(true); var rentService = new RentsService(mapper, db, monthlyRentMock.Object); //Act var result = await rentService.CreateAsync(createModel); var createdRent = await db.RentAgreements .FirstOrDefaultAsync(x => x.Description == "No Desc"); //Assert result .Should() .BeTrue(); createdRent.Should().BeOfType <RentAgreement>().And .Match <RentAgreement>(r => r.ClientId == 1 && r.StartDate == new DateTime(2018, 3, 3) && r.ParkingSlotDescription == "Some Desc" && r.MonthlyPrice == 2000M && r.PropertyRents.Any(x => x.Property.Id == 2) && r.ParkingSlots.Any(x => x.Price == 1M || x.Price == 2M || x.Price == 3M || x.Price == 4M || x.Price == 5M || x.Price == 6M)); }