[Fact] // 2. async Task<RentalInfoServiceModel> GetDetailsAsync(int id)
        public async void GetDetailsAsync_WithGivenRenalId_ShouldReturnModelWithDetails()
        {
            // Arrange
            var ownerId        = Guid.NewGuid().ToString();
            var anotherOwnerId = Guid.NewGuid().ToString();
            var country        = CountryCreator.Create();
            var city           = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateOwnerHome(ownerId, city.Id);
            var home2 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home3 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home4 = HomeCreator.CreateManagedHome(anotherOwnerId, city.Id);

            var user1 = UserCreator.Create("Debelin", "Butov", "but4eto", "*****@*****.**");
            var user2 = UserCreator.Create("Shunko", "Shpekov", "shpeka", "*****@*****.**");
            var user3 = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");

            int id1 = 1;
            int id2 = 2;
            int id3 = 3;
            int id4 = 4;

            var contract1 = ContractCreator.CreateRentalContract(id1);
            var contract2 = ContractCreator.CreateRentalContract(id2);
            var contract3 = ContractCreator.CreateRentalContract(id3);
            var contract4 = ContractCreator.CreateRentalContract(id4);

            var rental1 = RentalCreator.Create(id1, country, city, user1, home1, contract1);
            var rental2 = RentalCreator.Create(id2, country, city, user2, home2, contract2);
            var rental3 = RentalCreator.Create(id3, country, city, user3, home3, contract3);
            var rental4 = RentalCreator.Create(id4, country, city, user3, home4, contract4);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddRangeAsync(home1, home2, home3, home4);

            await this.Context.Users.AddRangeAsync(user1, user2, user3);

            await this.Context.Rentals.AddRangeAsync(rental1, rental2, rental3, rental4);

            await this.Context.Contracts.AddRangeAsync(contract1, contract2, contract3, contract4);

            await this.Context.SaveChangesAsync();

            var service = new RentalService(this.Context);

            // Act
            var result = await service.GetDetailsAsync(rental1.Id);

            var expected = await this.Context.Rentals
                           .Where(r => r.Id == rental1.Id)
                           .FirstOrDefaultAsync();

            // Assert
            result.Should().BeOfType <RentalInfoServiceModel>();
            result.HomeId.Should().Be(expected.Home.Id);
        }
예제 #2
0
        [Fact] // async Task<IEnumerable<OwnerTransactionListOfRentalsServiceModel>> GetTransactionRentalsAsync(string userId)
        public async void GetTransactionRentalsAsync_ForGivenOwnerId_ShouldReturnListOfRentalsForSelectList()
        {
            // Arrange
            var ownerId        = Guid.NewGuid().ToString();
            var anotherOwnerId = Guid.NewGuid().ToString();
            var country        = CountryCreator.Create();
            var city           = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateOwnerHome(ownerId, city.Id);
            var home2 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home3 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home4 = HomeCreator.CreateManagedHome(anotherOwnerId, city.Id);

            var user1 = UserCreator.Create("Debelin", "Butov", "but4eto", "*****@*****.**");
            var user2 = UserCreator.Create("Shunko", "Shpekov", "shpeka", "*****@*****.**");
            var user3 = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");

            int id1 = 1;
            int id2 = 2;
            int id3 = 3;
            int id4 = 4;

            var contract1 = ContractCreator.CreateRentalContract(id1);
            var contract2 = ContractCreator.CreateRentalContract(id2);
            var contract3 = ContractCreator.CreateRentalContract(id3);
            var contract4 = ContractCreator.CreateRentalContract(id4);

            var rental1 = RentalCreator.Create(id1, country, city, user1, home1, contract1);
            var rental2 = RentalCreator.Create(id2, country, city, user2, home2, contract2);
            var rental3 = RentalCreator.Create(id3, country, city, user3, home3, contract3);
            var rental4 = RentalCreator.Create(id4, country, city, user3, home4, contract4);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddRangeAsync(home1, home2, home3, home4);

            await this.Context.Users.AddRangeAsync(user1, user2, user3);

            await this.Context.Rentals.AddRangeAsync(rental1, rental2, rental3, rental4);

            await this.Context.Contracts.AddRangeAsync(contract1, contract2, contract3, contract4);

            await this.Context.SaveChangesAsync();

            var service = new OwnerRentalService(this.Context, null, null, null, null);

            // Act
            var result        = (await service.GetTransactionRentalsAsync(ownerId)).ToList();
            var expectedCount = this.Context.Rentals
                                .Where(r => r.Home.OwnerId == ownerId)
                                .Count();

            // Assert
            result.Should().AllBeOfType <OwnerTransactionListOfRentalsServiceModel>();
            result.Should().HaveCount(expectedCount);
            result.Should().HaveCount(3);
        }
        [Fact] // 1. async Task<IEnumerable<UserRentalListServiceModel>> GetUserRentalsListAsync(string userId)
        public async void GetUserRentalsListAsync_WithGivenUserId_ShouldReturnCollectionOfRentedPropertiesModel()
        {
            // Arrange
            var ownerId        = Guid.NewGuid().ToString();
            var anotherOwnerId = Guid.NewGuid().ToString();
            var country        = CountryCreator.Create();
            var city           = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateOwnerHome(ownerId, city.Id);
            var home2 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home3 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home4 = HomeCreator.CreateManagedHome(anotherOwnerId, city.Id);

            var user1 = UserCreator.Create("Debelin", "Butov", "but4eto", "*****@*****.**");
            var user2 = UserCreator.Create("Shunko", "Shpekov", "shpeka", "*****@*****.**");
            var user3 = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");

            int id1 = 1;
            int id2 = 2;
            int id3 = 3;
            int id4 = 4;

            var contract1 = ContractCreator.CreateRentalContract(id1);
            var contract2 = ContractCreator.CreateRentalContract(id2);
            var contract3 = ContractCreator.CreateRentalContract(id3);
            var contract4 = ContractCreator.CreateRentalContract(id4);

            var rental1 = RentalCreator.Create(id1, country, city, user1, home1, contract1);
            var rental2 = RentalCreator.Create(id2, country, city, user2, home2, contract2);
            var rental3 = RentalCreator.Create(id3, country, city, user3, home3, contract3);
            var rental4 = RentalCreator.Create(id4, country, city, user3, home4, contract4);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddRangeAsync(home1, home2, home3, home4);

            await this.Context.Users.AddRangeAsync(user1, user2, user3);

            await this.Context.Rentals.AddRangeAsync(rental1, rental2, rental3, rental4);

            await this.Context.Contracts.AddRangeAsync(contract1, contract2, contract3, contract4);

            await this.Context.SaveChangesAsync();

            var service = new RentalService(this.Context);

            // Act
            var result   = (await service.GetUserRentalsListAsync(rental1.TenantId)).ToList();
            var expected = await this.Context.Rentals
                           .Where(r => r.TenantId == rental1.TenantId)
                           .ToListAsync();

            // Assert
            result.Should().AllBeOfType <UserRentalListServiceModel>();
            result.Should().HaveCount(expected.Count());
            result.Should().HaveCount(1, "Because the tenant has 1 rented property.");
        }
예제 #4
0
        [Fact] // async Task<IEnumerable<OwnerAllTransactionRequestsServiceModel>> GetAllTransactionRequestsAsync(string userId)
        public async void GetAllTransactionRequestsAsync_ForGivenOwnerId_ShouldReturnModelCollection()
        {
            // Arrange
            var id      = 1;
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);
            var tenant  = UserCreator.Create("Shunko", "Svinski", "shunkata", "*****@*****.**");
            var owner   = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");

            var home  = HomeCreator.CreateOwnerHome(owner.Id, city.Id);
            var home2 = HomeCreator.CreateManagedHome(owner.Id, city.Id);

            var contract = ContractCreator.CreateRentalContract(id);
            var rental   = RentalCreator.Create(id, country, city, tenant, home, contract);

            var anotherId       = 2;
            var anotherTenant   = UserCreator.Create("Fileslav", "Karadjolanov", "fileto", "*****@*****.**");
            var anotherOwner    = UserCreator.Create("Prasemir", "Babek", "nadenicata", "*****@*****.**");
            var anotherHome     = HomeCreator.CreateOwnerHome(anotherOwner.Id, city.Id);
            var anotherContract = ContractCreator.CreateRentalContract(anotherId);
            var anotherRental   = RentalCreator.Create(anotherId, country, city, anotherTenant, anotherHome, anotherContract);

            var trId  = Guid.NewGuid().ToString();
            var trId2 = Guid.NewGuid().ToString();
            var trId5 = Guid.NewGuid().ToString();

            var transactionRequest  = TransactionRequestCreator.CreateForRental(trId, tenant.Id, owner.Id, rental.Id);
            var transactionRequest2 = TransactionRequestCreator.CreateForManager(trId2, owner.Id, home2.ManagerId, home2.Id);
            var transactionRequest5 = TransactionRequestCreator.CreateForRental(trId5, anotherTenant.Id, anotherOwner.Id, anotherRental.Id);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Users.AddRangeAsync(owner, tenant, anotherTenant);

            await this.Context.Homes.AddRangeAsync(home, home2);

            await this.Context.Contracts.AddRangeAsync(contract, anotherContract);

            await this.Context.Rentals.AddRangeAsync(rental, anotherRental);

            await this.Context
            .TransactionRequests
            .AddRangeAsync(transactionRequest, transactionRequest2, transactionRequest5);

            await this.Context.SaveChangesAsync();

            var service = new OwnerTransactionRequestService(this.Context);

            // Act
            var result = await service.GetAllTransactionRequestsAsync(owner.Id);

            // Assert
            result.Should().AllBeOfType <OwnerAllTransactionRequestsServiceModel>();
            result.Should().HaveCount(2, "because there are 2 different contracts - one home rented and another managed");
        }
예제 #5
0
        [Fact] // async Task<string> CreateAsync(string recipientId, OwnerTransactionRequestsCreateInputServiceModel model)
        public async void CreateAsync_WithGivenRecipientIdAndRequestModel_ShouldCreateTransactionRequest()
        {
            // Arrange
            var id      = 1;
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);
            var tenant  = UserCreator.Create("Shunko", "Svinski", "shunkata", "*****@*****.**");
            var owner   = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");

            var home = HomeCreator.CreateOwnerHome(owner.Id, city.Id);

            var contract = ContractCreator.CreateRentalContract(id);
            var rental   = RentalCreator.Create(id, country, city, tenant, home, contract);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Users.AddRangeAsync(owner, tenant);

            await this.Context.Homes.AddAsync(home);

            await this.Context.Contracts.AddAsync(contract);

            await this.Context.Rentals.AddRangeAsync(rental);

            await this.Context.SaveChangesAsync();

            var recipientId = Guid.NewGuid().ToString();

            var model = new OwnerTransactionRequestsCreateInputServiceModel
            {
                Id                = Guid.NewGuid().ToString(),
                Reason            = Guid.NewGuid().ToString(),
                RecurringSchedule = RecurringScheduleType.Monthly,
                IsRecurring       = true,
                RentalId          = id,
            };

            var service = new OwnerTransactionRequestService(this.Context);

            // Act
            var result = await service.CreateAsync(owner.Id, model);

            var expected = await this.Context.TransactionRequests
                           .Where(x => x.RecipientId == owner.Id)
                           .FirstOrDefaultAsync();

            // Assert
            result.Should().BeOfType <string>();
            result.Should().Equals(expected.Id);
        }
        [Fact] // 4. async Task<bool> EditPaymentStatusAsync(string paymentId, string userId, PaymentStatus status, DateTime? date)
        public async void EditPaymentStatusAsync_WithGivenPaymentId_UserId_PaymentStatusEnum_Date__ShouldReturnTrueIfEdited()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateAny(city.Id);                         // rented
            var home2 = HomeCreator.CreateManagedHome(home1.Owner.Id, city.Id); // managed

            var tenant1 = UserCreator.Create("Debelin", "Dignibutov", "but4eto", "*****@*****.**");

            int id1       = 1;
            var contract1 = ContractCreator.CreateRentalContract(id1);
            var rental1   = RentalCreator.Create(id1, country, city, tenant1, home1, contract1);

            var payment1 = PaymentCreator.CreateForTenant(home1.Owner, tenant1.Id, rental1.Id);
            var payment2 = PaymentCreator.CreateForManager(home1.Owner.Id, home2.Manager.Id, home2.Id);

            rental1.Payments.Add(payment1);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddRangeAsync(home1, home2);

            await this.Context.Users.AddAsync(tenant1);

            await this.Context.Rentals.AddAsync(rental1);

            await this.Context.Payments.AddRangeAsync(payment1, payment2);

            await this.Context.Contracts.AddRangeAsync(contract1);

            await this.Context.SaveChangesAsync();

            var testService = new PaymentCommonService(this.Context, null, null, null);

            // Act
            var date   = DateTime.UtcNow;
            var result = await testService.EditPaymentStatusAsync(payment1.Id, tenant1.Id, PaymentStatus.Complete, date);

            // Assert
            result.Should().BeTrue();
        }
예제 #7
0
        [Fact] // async Task<bool> IsHomeDeletable(string id)
        public async Task IsHomeDeletable_WithGivenHomeId_ShouldConfirmIf_HomeHasTenantManagerOrNone()
        {
            // Arrange
            var id      = 1;
            var ownerId = Guid.NewGuid().ToString();
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home1       = HomeCreator.CreateOwnerHome(ownerId, city.Id);
            var homeManaged = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var homeRented  = HomeCreator.CreateOwnerHome(ownerId, city.Id);
            var tenant      = UserCreator.Create("Shunko", "Svinski", "shunkata", "*****@*****.**");

            var contract = ContractCreator.Create();

            var rental = RentalCreator.Create(id, country, city, tenant, homeRented, contract);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddRangeAsync(home1, homeManaged, homeRented);

            await this.Context.Users.AddAsync(tenant);

            await this.Context.Contracts.AddAsync(contract);

            await this.Context.Rentals.AddAsync(rental);

            await this.Context.SaveChangesAsync();

            var service = new OwnerListingService(this.Context, null, null, null);

            // Act
            var result1 = await service.IsHomeDeletable(home1.Id);

            var resultManaged = await service.IsHomeDeletable(homeManaged.Id);

            var resultRented = await service.IsHomeDeletable(homeRented.Id);

            // Assert
            result1.Should().Be(true);
            resultManaged.Should().Be(false);
            resultRented.Should().Be(false);
        }
        [Fact] // 3. async Task<UserPaymentDetailsServiceModel> GetPaymentDetailsAsync(string paymentId, string userId)
        public async void GetPaymentDetailsAsync_WithGivenPaymentIdAndUserId_ShouldReturnDetailsModel()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateAny(city.Id);                         // rented
            var home2 = HomeCreator.CreateManagedHome(home1.Owner.Id, city.Id); // managed

            var tenant1 = UserCreator.Create("Debelin", "Dignibutov", "but4eto", "*****@*****.**");

            int id1       = 1;
            var contract1 = ContractCreator.CreateRentalContract(id1);
            var rental1   = RentalCreator.Create(id1, country, city, tenant1, home1, contract1);

            var payment1 = PaymentCreator.CreateForTenant(home1.Owner, tenant1.Id, rental1.Id);
            var payment2 = PaymentCreator.CreateForManager(home1.Owner.Id, home2.Manager.Id, home2.Id);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddRangeAsync(home1, home2);

            await this.Context.Users.AddAsync(tenant1);

            await this.Context.Rentals.AddAsync(rental1);

            await this.Context.Payments.AddRangeAsync(payment1, payment2);

            await this.Context.Contracts.AddRangeAsync(contract1);

            await this.Context.SaveChangesAsync();

            var testService = new PaymentCommonService(this.Context, null, null, null);

            // Act

            // Assert
        }
예제 #9
0
        [Fact] // async Task<UserPaymentDetailsServiceModel> GetPaymentDetailsAsync(string paymentId, string userId)
        public async void GetPaymentDetailsAsync_ForGivenOwnerIdAndPaymentId_ShouldReturnPaymentDetailsModel()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);
            var manager = UserCreator.Create("Georgi", "Butov", "joro", "*****@*****.**");

            var home1 = HomeCreator.CreateAny(city.Id);                         // rented
            var home2 = HomeCreator.CreateManagedHome(home1.Owner.Id, city.Id); // managed
            var home4 = HomeCreator.CreateAny(city.Id);                         // another owner with tenant

            var tenant1 = UserCreator.Create("Debelin", "Dignibutov", "but4eto", "*****@*****.**");
            var tenant4 = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");

            int id1 = 1;
            int id4 = 4;

            var contract1 = ContractCreator.CreateRentalContract(id1);
            var contract4 = ContractCreator.CreateRentalContract(id4);

            var rental1 = RentalCreator.Create(id1, country, city, tenant1, home1, contract1);
            var rental4 = RentalCreator.Create(id4, country, city, tenant4, home4, contract4);

            var payment1        = PaymentCreator.CreateForTenant(home1.Owner, tenant1.Id, rental1.Id);
            var payment2        = PaymentCreator.CreateForManager(home1.Owner.Id, home2.Manager.Id, home2.Id);
            var paymentAnother5 = PaymentCreator.CreateForTenant(home4.Owner, tenant4.Id, rental4.Id);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddRangeAsync(home1, home2, home4);

            await this.Context.Users.AddRangeAsync(tenant1, tenant4);

            await this.Context.Rentals.AddRangeAsync(rental1, rental4);

            await this.Context.Payments.AddRangeAsync(payment1, payment2, paymentAnother5);

            await this.Context.Contracts.AddRangeAsync(contract1, contract4);

            await this.Context.SaveChangesAsync();

            var service = new OwnerPaymentService(this.Context);

            // Act
            var rentals = await this.Context.Rentals.ToListAsync();

            var result1 = await service.GetPaymentDetailsAsync(payment1.Id, tenant1.Id);

            var result2 = await service.GetPaymentDetailsAsync(payment2.Id, home1.Owner.Id);

            var result3 = await service.GetPaymentDetailsAsync(paymentAnother5.Id, tenant4.Id);

            var expected1 = await this.Context.Rentals
                            .Where(r => r.TenantId == tenant1.Id)
                            .SelectMany(r => r.Payments)
                            .Where(p => p.Id == payment1.Id)
                            .FirstOrDefaultAsync();

            var expected2 = await this.Context.Payments
                            .Where(p => p.Id == payment2.Id)
                            .FirstOrDefaultAsync();

            var expected3 = await this.Context.Rentals
                            .Where(r => r.TenantId == tenant4.Id)
                            .SelectMany(r => r.Payments)
                            .Where(p => p.Id == paymentAnother5.Id)
                            .FirstOrDefaultAsync();

            // Assert
            result1.Should().BeOfType <UserPaymentDetailsServiceModel>();
            result1.To.Should().Equals(home1.Owner.FirstName + home1.Owner.LastName);
            result1.Address.Should().Equals(expected1.Rental.Home.Address);

            result2.To.Should().Equals(home2.Manager.FirstName + home2.Manager.LastName);
            result2.Address.Should().Equals(expected2.Home.Address);

            result3.To.Should().Equals(home4.Owner.FirstName + home4.Owner.LastName);
            result3.Address.Should().Equals(expected3.Rental.Home.Address);
        }
예제 #10
0
        [Fact] // async Task<IEnumerable<OwnerAllPaymentsServiceModel>> AllPayments(string userId)
        public async void AllPayments_ForGivenOwnerId_ShouldReturnAllRelatedPayments()
        {
            // Arrange
            var ownerId        = Guid.NewGuid().ToString();
            var anotherOwnerId = Guid.NewGuid().ToString();
            var country        = CountryCreator.Create();
            var city           = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateAny(city.Id);                         // rented
            var home2 = HomeCreator.CreateManagedHome(home1.Owner.Id, city.Id); // managed
            var home3 = HomeCreator.CreateManagedHome(home1.Owner.Id, city.Id); // managed & rented
            var home4 = HomeCreator.CreateAny(city.Id);                         // another owner with tenant

            var tenant1 = UserCreator.Create("Debelin", "Butov", "but4eto", "*****@*****.**");
            var tenant3 = UserCreator.Create("Shunko", "Shpekov", "shpeka", "*****@*****.**");
            var tenant4 = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");

            int id1 = 1;
            int id3 = 3;
            int id4 = 4;

            var contract1 = ContractCreator.CreateRentalContract(id1);
            var contract3 = ContractCreator.CreateRentalContract(id3);
            var contract4 = ContractCreator.CreateRentalContract(id4);

            var rental1 = RentalCreator.Create(id1, country, city, tenant1, home1, contract1);
            var rental3 = RentalCreator.Create(id3, country, city, tenant3, home3, contract3);
            var rental4 = RentalCreator.Create(id4, country, city, tenant4, home4, contract4);

            var payment1        = PaymentCreator.CreateForTenant(home1.Owner, tenant1.Id, rental1.Id);
            var payment2        = PaymentCreator.CreateForManager(home1.Owner.Id, home2.Manager.Id, home2.Id);
            var payment3        = PaymentCreator.CreateForManager(home1.Owner.Id, home3.Manager.Id, home3.Id);
            var payment4        = PaymentCreator.CreateForTenant(home1.Owner, tenant3.Id, rental3.Id);
            var paymentAnother5 = PaymentCreator.CreateForTenant(home4.Owner, tenant4.Id, rental4.Id);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddRangeAsync(home1, home2, home3, home4);

            await this.Context.Users.AddRangeAsync(tenant1, tenant3, tenant4);

            await this.Context.Rentals.AddRangeAsync(rental1, rental3, rental4);

            await this.Context.Payments.AddRangeAsync(payment1, payment2, payment3, payment4, paymentAnother5);

            await this.Context.Contracts.AddRangeAsync(contract1, contract3, contract4);

            await this.Context.SaveChangesAsync();

            var service = new OwnerPaymentService(this.Context);

            // Act
            var result        = (await service.AllPayments(home1.Owner.Id)).ToList();
            var expectedCount = this.Context.Payments
                                .Where(p => p.Home.OwnerId == home1.Owner.Id || p.Rental.Home.OwnerId == home1.Owner.Id)
                                .Count();

            // Assert
            result.Should().AllBeOfType <OwnerAllPaymentsServiceModel>();
            result.Should().HaveCount(expectedCount);
            result.Should().HaveCount(4, "because there are 3 properties where one has tenant + manager, which makes 4");
        }
        [Fact] // 7. async Task<bool> MarkPaymentAsCompletedAsync(Session session)
        public async void MarkPaymentAsCompletedAsync_WithGivenSession_()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateAny(city.Id);                         // rented
            var home2 = HomeCreator.CreateManagedHome(home1.Owner.Id, city.Id); // managed

            var tenant1 = UserCreator.Create("Debelin", "Dignibutov", "but4eto", "*****@*****.**");

            int id1       = 1;
            var contract1 = ContractCreator.CreateRentalContract(id1);
            var rental1   = RentalCreator.Create(id1, country, city, tenant1, home1, contract1);

            var payment1 = PaymentCreator.CreateForTenant(home1.Owner, tenant1.Id, rental1.Id);
            var payment2 = PaymentCreator.CreateForManager(home1.Owner.Id, home2.Manager.Id, home2.Id);

            var id = Guid.NewGuid().ToString();
            var toStripeAccountId = "acct_1GUy2RB3QW0Kx8nS";

            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },

                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        Quantity = 1,
                        Amount   = (long)payment1.Amount * 100,
                        Currency = CurrencyUSD,

                        Name = $"Rent Payment for {DateTime.UtcNow.ToString("MMMM")}/ {DateTime.UtcNow.Year}",
                    },
                },

                PaymentIntentData = new SessionPaymentIntentDataOptions
                {
                    ApplicationFeeAmount = (long)((payment1.Amount * 0.01m) * 100),
                    CaptureMethod        = "automatic",
                    Description          = payment1.Id,

                    TransferData = new SessionPaymentIntentTransferDataOptions
                    {
                        Destination = toStripeAccountId,
                    },
                },

                SuccessUrl = "https://homy.azurewebsites.net/checkout/success?sessionId={CHECKOUT_SESSION_ID}",
                CancelUrl  = "https://homy.azurewebsites.net/checkout/cancel",
            };

            var     service = new SessionService();
            Session session = service.Create(options, new RequestOptions
            {
                ApiKey = HomyTestSecretKey,
            });

            var sessionForDb = new StripeCheckoutSession
            {
                Id                = session.Id,
                PaymentId         = payment1.Id,
                ToStripeAccountId = toStripeAccountId,
            };

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddRangeAsync(home1, home2);

            await this.Context.Users.AddAsync(tenant1);

            await this.Context.Rentals.AddAsync(rental1);

            await this.Context.Payments.AddRangeAsync(payment1, payment2);

            await this.Context.Contracts.AddRangeAsync(contract1);

            await this.Context.StripeCheckoutSessions.AddAsync(sessionForDb);

            await this.Context.SaveChangesAsync();

            var testService = new PaymentCommonService(this.Context, null, null, null);

            // Act
            var result = await testService.MarkPaymentAsCompletedAsync(session);

            bool expected = await this.Context.Payments.Where(p => p.Id == payment1.Id)
                            .AnyAsync(p => p.Status == PaymentStatus.Complete);

            // Assert
            result.Should().Equals(expected);
            result.Should().BeTrue();
        }
        [Fact] // 5. async Task<bool> AddPaymentRequestToUserAsync(string userId, string requestId)
        public async void AddPaymentRequestToUserAsync_WithGivenUserIdAndRequestId_ShouldAddPaymentToUserSuccessfully()
        {
            // Arrange
            var ownerId        = Guid.NewGuid().ToString();
            var anotherOwnerId = Guid.NewGuid().ToString();
            var country        = CountryCreator.Create();
            var city           = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateAny(city.Id);                  // rented
            var home2 = HomeCreator.CreateManagedHome(ownerId, city.Id); // managed

            var tenant1 = UserCreator.Create("Debelin", "Butov", "but4eto", "*****@*****.**");

            int id1       = 1;
            var contract1 = ContractCreator.CreateRentalContract(id1);
            var rental1   = RentalCreator.Create(id1, country, city, tenant1, home1, contract1);

            var payment1 = PaymentCreator.CreateForTenant(home1.Owner, tenant1.Id, rental1.Id);
            var payment2 = PaymentCreator.CreateForManager(home1.Owner.Id, home2.Manager.Id, home2.Id);

            var senderId    = Guid.NewGuid().ToString();
            var recipientId = Guid.NewGuid().ToString();

            var trId = Guid.NewGuid().ToString();

            var transactionRequest = TransactionRequestCreator
                                     .CreateForManager(trId, home1.Owner.Id, home2.Manager.Id, home2.Id);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddAsync(home1);

            await this.Context.Users.AddAsync(tenant1);

            await this.Context.Rentals.AddRangeAsync(rental1);

            await this.Context.Payments.AddRangeAsync(payment1, payment2);

            await this.Context.Contracts.AddRangeAsync(contract1);

            await this.Context.TransactionRequests.AddRangeAsync(transactionRequest);

            await this.Context.SaveChangesAsync();

            var transactionRequestService = new Mock <IOwnerTransactionRequestService>();

            transactionRequestService.Setup(x => x.FindByIdAsync(trId))
            .Returns(Task.FromResult(transactionRequest));

            var service = new PaymentCommonService(
                this.Context,
                transactionRequestService.Object,
                this.UserManager.Object,
                null);

            // Act
            var result = await service.AddPaymentRequestToUserAsync(home1.Owner.Id, trId);

            var createdPaymentTo = await this.Context.Payments
                                   .Where(p => p.HomeId == home2.Id)
                                   .FirstOrDefaultAsync();

            // Assert
            result.Should().BeTrue();
            createdPaymentTo.Should().NotBeNull();
        }
예제 #13
0
        [Fact] // async Task<IEnumerable<OwnerIndexRentalServiceModel>> GetRentalsAsync(string userId)
        public async void GetRentalsAsync_ForGivenOwnerId_ShouldReturnModelOfAllRentedHomes()
        {
            // Arrange
            var ownerId        = Guid.NewGuid().ToString();
            var anotherOwnerId = Guid.NewGuid().ToString();
            var country        = CountryCreator.Create();
            var city           = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateOwnerHome(ownerId, city.Id);
            var home2 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home3 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home4 = HomeCreator.CreateManagedHome(anotherOwnerId, city.Id);

            var user1 = UserCreator.Create("Debelin", "Butov", "but4eto", "*****@*****.**");
            var user2 = UserCreator.Create("Shunko", "Shpekov", "shpeka", "*****@*****.**");
            var user3 = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");

            int id1 = 1;
            int id2 = 2;
            int id3 = 3;
            int id4 = 4;

            var contract1 = ContractCreator.CreateRentalContract(id1);
            var contract2 = ContractCreator.CreateRentalContract(id2);
            var contract3 = ContractCreator.CreateRentalContract(id3);
            var contract4 = ContractCreator.CreateRentalContract(id4);

            var rental1 = RentalCreator.Create(id1, country, city, user1, home1, contract1);
            var rental2 = RentalCreator.Create(id2, country, city, user2, home2, contract2);
            var rental3 = RentalCreator.Create(id3, country, city, user3, home3, contract3);
            var rental4 = RentalCreator.Create(id4, country, city, user3, home4, contract4);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddRangeAsync(home1, home2, home3, home4);

            await this.Context.Users.AddRangeAsync(user1, user2, user3);

            await this.Context.Rentals.AddRangeAsync(rental1, rental2, rental3, rental4);

            await this.Context.Contracts.AddRangeAsync(contract1, contract2, contract3, contract4);

            await this.Context.SaveChangesAsync();

            var service = new OwnerRentalService(this.Context, null, null, null, null);

            // Act
            var result        = (await service.GetRentalsAsync(ownerId)).ToList();
            var expectedCount = this.Context.Rentals
                                .Where(r => r.Home.OwnerId == ownerId)
                                .Count();

            // Assert
            result.Should().AllBeOfType <OwnerIndexRentalServiceModel>();
            result.Should().HaveCount(expectedCount);
            result.Should().HaveCount(3, "because I've put 3 rentals associated with this owner");
            result[0].Should().BeOfType <OwnerIndexRentalServiceModel>()
            .Which.StartDate
            .Should().Be(rental1.RentDate.ToString(StandartDateFormat));
            result[0].Should().BeOfType <OwnerIndexRentalServiceModel>()
            .Which.Duration
            .Should().Be(rental1.Duration);
            result[0].Should().BeOfType <OwnerIndexRentalServiceModel>()
            .Which.Tenant
            .Should().Be(string.Format(TenantFullName, rental1.Tenant.FirstName, rental1.Tenant.LastName));
        }
예제 #14
0
        [Fact] // async Task<OwnerListingFullDetailsServiceModel> GetDetailsAsync(string userId, string id)
        public async Task GetyDetailsAsync_WithGivenOwnerIdAndHomeId_ShouldReturnFullDetailsModel()
        {
            // Arrange
            var id       = 1;
            var country  = CountryCreator.Create();
            var city     = CityCreator.Create(country.Id);
            var tenant   = UserCreator.Create("Shunko", "Svinski", "shunkata", "*****@*****.**");
            var owner    = UserCreator.Create("Suzdurma", "Saturov", "satrura", "*****@*****.**");
            var home     = HomeCreator.CreateOwnerHome(owner.Id, city.Id);
            var contract = ContractCreator.Create();

            var rental = RentalCreator.Create(id, country, city, tenant, home, contract);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Users.AddAsync(tenant);

            await this.Context.Homes.AddAsync(home);

            await this.Context.Contracts.AddAsync(contract);

            await this.Context.Rentals.AddAsync(rental);

            await this.Context.SaveChangesAsync();

            var rentalInfo = new OwnerRentalInfoServiceModel
            {
                RentalDate      = rental.RentDate.ToString(),
                Duration        = rental.Duration,
                ManagerFullName = null,
                TenantFullName  = string.Format(
                    "{0} {1}", rental.Tenant.FirstName, rental.Tenant.LastName),
            };

            var model = new OwnerListingFullDetailsServiceModel
            {
                Id          = home.Id,
                Name        = home.Name,
                City        = home.City.Name,
                Country     = home.City.Country.Name,
                Address     = home.Address,
                Description = home.Description,
                Price       = home.Price,
                Status      = home.Status,
                Category    = home.Category,
                Image       = home.Images.Select(i => i.PictureUrl).FirstOrDefault(),
                RentalInfo  = rentalInfo,
            };

            var service = new OwnerListingService(this.Context, null, null, null);

            // Act
            var savedEntry = await this.Context.Homes.Where(h => h.OwnerId == owner.Id).FirstOrDefaultAsync();

            var savedRental = await this.Context.Rentals.Where(r => r.Home.Id == home.Id).FirstOrDefaultAsync();

            var result = await service.GetDetailsAsync(owner.Id, home.Id);

            // Assert
            result.Should().BeOfType <OwnerListingFullDetailsServiceModel>();
            result.RentalInfo.RentalDate.Should().Match(savedRental.RentDate.ToString("dd/MM/yyyy"));

            savedEntry.Should().NotBeNull();
            savedEntry.Id.Should().Be(home.Id);
            savedEntry.Name.Should().Match(model.Name);
            savedEntry.Description.Should().Match(model.Description);
        }