Beispiel #1
0
        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")));
        }
Beispiel #2
0
        public async Task TerminateAsync_ShouldReturn_True_IfEntityExistInDb()
        {
            var db     = GetDatabase();
            var mapper = GetMapper();
            var firstMonthlyConsumable = new MonthlyPaymentConsumable
            {
                Id                    = 1,
                DeadLine              = new DateTime(2018, 12, 12),
                ElectricityDay        = 1,
                ElectricityNight      = 2,
                ElectricityPeak       = 3,
                PaymentForElectricity = 4,
                PaymentForWater       = 5,
                WaterReport           = 6
            };
            var secondMonthlyConsumable = new MonthlyPaymentConsumable
            {
                Id                    = 2,
                DeadLine              = new DateTime(2018, 12, 24),
                ElectricityDay        = 7,
                ElectricityNight      = 8,
                ElectricityPeak       = 9,
                PaymentForElectricity = 10,
                PaymentForWater       = 11,
                WaterReport           = 12
            };
            await db.MonthlyPaymentConsumables.AddRangeAsync(firstMonthlyConsumable, secondMonthlyConsumable);

            await db.SaveChangesAsync();

            var consumabelService = new MonthlyConsumablesService(mapper, db);
            //Act
            var result = await consumabelService.TerminateAsync(2);

            var terminatedEntity = await db.MonthlyPaymentRents.FindAsync(2);

            //Assert
            result
            .Should()
            .BeTrue();
            terminatedEntity
            .Should()
            .BeNull();
        }
Beispiel #3
0
        public async Task AllOverduConsumablesAsync_ShouldReturn_CollectionWithPendigPayments_IfSuchExistInDb()
        {
            var db     = GetDatabase();
            var mapper = GetMapper();
            var firstMonthlyConsumable = new MonthlyPaymentConsumable
            {
                Id       = 1,
                DeadLine = new DateTime(2016, 12, 12),
                PaymentForElectricity = 4,
                PaymentForWater       = 5,
            };
            var secondMonthlyConsumable = new MonthlyPaymentConsumable
            {
                Id       = 2,
                DeadLine = new DateTime(2017, 12, 24),
                PaymentForElectricity = 10,
                PaymentForWater       = 11,
            };
            var thirdMonthlyConsumable = new MonthlyPaymentConsumable
            {
                Id       = 3,
                DeadLine = new DateTime(2050, 12, 24),
                PaymentForElectricity = 14,
                PaymentForWater       = 17,
            };
            await db.MonthlyPaymentConsumables.AddRangeAsync(firstMonthlyConsumable, secondMonthlyConsumable, thirdMonthlyConsumable);

            await db.SaveChangesAsync();

            var consumabelService = new MonthlyConsumablesService(mapper, db);
            //Act
            var result = await consumabelService.AllOverduConsumablesAsync();

            //Assert
            result
            .Should()
            .HaveCount(2)
            .And
            .BeOfType <List <OverdueMonthlyConsumablesListingModel> >()
            .And
            .Match(x => x.ElementAt(0).PaymentForElectricity == 4 &&
                   x.ElementAt(1).PaymentForWater == 11);
        }
Beispiel #4
0
        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();
        }
Beispiel #5
0
        public async Task CreateMonthlyConsumable_ShouldReturn_False_IfInputIsNotCorrect()
        {
            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 = 2
            };
            //Act
            var result = await consumabelService.CreateAsync(consumableInput);

            var createdConsumable = await db.MonthlyPaymentConsumables
                                    .FirstOrDefaultAsync(x => x.ElectricityDay == 1 && x.PaymentForWater == 5);

            //Assert
            result
            .Should()
            .BeFalse();
            createdConsumable
            .Should()
            .BeNull();
        }