[Fact] // 5. public async Task<ManagedHomeInfoServiceModel> GetManagedDetailsAsync(string id)
        public async void GetManagedDetailsAsync_WithGivenListingId_ShouldReturnManagedListingModel()
        {
            // Arrange
            var ownerId = Guid.NewGuid().ToString();
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home4 = HomeCreator.CreateAny(city.Id);
            var home5 = HomeCreator.CreateAny(city.Id);

            home1.Owner = UserCreator.Create("Kanalin", "Tsolov", "tsola", "*****@*****.**");

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

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

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

            await this.Context.SaveChangesAsync();

            var service = new ListingService(this.Context);

            // Act
            var result = await service.GetManagedDetailsAsync(home1.Id);

            var expectedCount = this.Context.Homes
                                .Where(h => h.Id == home1.Id)
                                .Count();

            // Assert
            result.Should().BeOfType <ManagedHomeInfoServiceModel>();
            result.Owner.Should().Match(string.Format(OwnerFullName, home1.Owner.FirstName, home1.Owner.LastName));
        }
        [Fact] // 2. public async Task<IEnumerable<ManagerDashboardPropertiesServiceModel>> GetManagedPropertiesAsync(string Id)
        public async void GetManagedPropertiesAsync_ShouldReturnAllManagedProperties()
        {
            // Arrange
            var ownerId = Guid.NewGuid().ToString();
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home4 = HomeCreator.CreateAny(city.Id);
            var home5 = HomeCreator.CreateAny(city.Id);

            home1.Owner = UserCreator.Create("Kanalin", "Tsolov", "tsola", "*****@*****.**");

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

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

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

            await this.Context.SaveChangesAsync();

            var service = new ListingService(this.Context);

            // Act
            var result        = (await service.GetManagedPropertiesAsync(home1.ManagerId)).ToList();
            var expectedCount = this.Context.Homes
                                .Where(h => h.Status == HomeStatus.Managed && h.ManagerId == home1.ManagerId)
                                .Count();

            // Assert
            result.Should().AllBeOfType <ManagerDashboardPropertiesServiceModel>();
            result.Should().HaveCount(expectedCount);
            result.Should().HaveCount(1, "Because there is 1 managed home by this manager");
        }
示例#3
0
        [Fact] // async Task<IEnumerable<OwnerIndexListingsServiceModel>> GetMyPropertiesAsync(string id)
        public async void GetMyPropertiesAsync_ForGivenOwnerId_ShouldReturnCorrectlyAllOwnerListings()
        {
            // Arrange
            var ownerId = Guid.NewGuid().ToString();
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

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

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

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

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

            await this.Context.SaveChangesAsync();

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

            // Act
            var result        = (await service.GetMyPropertiesAsync(ownerId)).ToList();
            var expectedCount = this.Context.Homes
                                .Where(h => h.OwnerId == ownerId)
                                .Count();

            // Assert
            result.Should().AllBeOfType <OwnerIndexListingsServiceModel>();
            result.Should().HaveCount(expectedCount);
        }
示例#4
0
        [Fact] // async Task<bool> DeleteAsync(string id)
        public async Task DeleteAsync_WithGivenListingId_ShouldRemoveListingAndReturnTrue()
        {
            // Arrange
            var ownerId = Guid.NewGuid().ToString();
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateOwnerHome(ownerId, city.Id);

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

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

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

            await this.Context.SaveChangesAsync();

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

            // Act
            var result = await service.DeleteAsync(home1.Id);

            var expected = true;

            // Assert
            result.Should().Be(true);
            result.Should().Equals(expected);
        }
        [Fact] // 4. public async Task<PropertyDetailsServiceModel> GetDetailsAsync(string id)
        public async void GetDetailsAsync_WithGivenListingId_ShouldReturnModelWithDetails()
        {
            // Arrange
            var ownerId = Guid.NewGuid().ToString();
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home4 = HomeCreator.CreateAny(city.Id);
            var home5 = HomeCreator.CreateAny(city.Id);

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

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

            await this.Context.Homes.AddRangeAsync(home4, home5);

            await this.Context.SaveChangesAsync();

            var service = new ListingService(this.Context);

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

            var expectedCount = this.Context.Homes
                                .Where(h => h.Id == home4.Id)
                                .Count();

            // Assert
            result.Should().BeOfType <PropertyDetailsServiceModel>();
            result.Description.Should().Match(home4.Description);
        }
示例#6
0
        [Fact] // async Task<IEnumerable<OwnerTransactionListOfManagedHomesServiceModel>>GetManagedHomesAsync(string userId)
        public async Task GetManagedHomesAsync_WithGivenOwnerId_ShouldReturnManagedHomesModel()
        {
            // Arrange
            var ownerId = 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);

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

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

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

            await this.Context.SaveChangesAsync();

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

            // Act
            var result        = (await service.GetManagedHomesAsync(ownerId)).ToList();
            var expectedCount = this.Context.Homes
                                .Where(h => h.OwnerId == ownerId && h.Manager != null)
                                .Count();

            // Assert
            result.Should().AllBeOfType <OwnerTransactionListOfManagedHomesServiceModel>();
            result.Should().HaveCount(expectedCount);
        }
        [Fact] // 1. public async Task<IEnumerable<PropertyListServiceModel>> GetPropertiesAsync()
        public async void GetPropertiesAsync_ShouldReturnAllListings_ThatAreNotManaged()
        {
            // Arrange
            var ownerId = Guid.NewGuid().ToString();
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home2 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home3 = HomeCreator.CreateAny(city.Id);

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

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

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

            await this.Context.SaveChangesAsync();

            var service = new ListingService(this.Context);

            // Act
            var result        = (await service.GetPropertiesAsync()).ToList();
            var expectedCount = this.Context.Homes
                                .Where(h => h.Status != HomeStatus.Managed)
                                .Count();

            // Assert
            result.Should().AllBeOfType <PropertyListServiceModel>();
            result.Should().HaveCount(expectedCount);
            result.Should().HaveCount(1, "Because only one home is not with status [Managed]");
        }
        [Fact] // 3. public async Task<IEnumerable<PropertyListServiceModel>> GetAllByCategoryAsync(HomeCategory category)
        public async void GetAllByCategoryAsync_WithGivenCategory_ShouldReturnAll()
        {
            // Arrange
            var ownerId = Guid.NewGuid().ToString();
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home4 = HomeCreator.CreateAny(city.Id);
            var home5 = HomeCreator.CreateAny(city.Id);

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

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

            await this.Context.Homes.AddRangeAsync(home4, home5);

            await this.Context.SaveChangesAsync();

            var service = new ListingService(this.Context);

            // Act
            var result        = (await service.GetAllByCategoryAsync(HomeCategory.House)).ToList();
            var expectedCount = this.Context.Homes
                                .Where(h => h.Category == HomeCategory.House)
                                .Count();

            // Assert
            result.Should().AllBeOfType <PropertyListServiceModel>();
            result.Should().HaveCount(expectedCount);
            result.Should().HaveCount(2, "Because there 2 homes with category [House]");
        }
        [Fact] // 6. public async Task<PropertyCountServiceModel> GetPropertyCountByCategoryAsync(string category)
        public async void GetPropertyCountByCategoryAsync_WithGivenCategoryString_ShouldReturnCountOfListings()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home3 = HomeCreator.CreateAny(city.Id);
            var home4 = HomeCreator.CreateAny(city.Id);
            var home5 = HomeCreator.CreateAny(city.Id);

            home3.Category = HomeCategory.Room;

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

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

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

            await this.Context.SaveChangesAsync();

            var service = new ListingService(this.Context);

            // Act
            var result = await service.GetPropertyCountByCategoryAsync(HomeCategory.House.ToString());

            var expectedCount = this.Context.Homes
                                .Where(h => h.Category == HomeCategory.House)
                                .Count();

            // Assert
            result.Should().BeOfType <PropertyCountServiceModel>();
            result.Count.Should().Equals(expectedCount);
            result.Count.Should().Be(2, "Because there 2 homes with category [House]");
        }
        [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.");
        }
示例#11
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] // 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);
        }
示例#13
0
        [Fact] // async Task<bool> EditListingAsync(OwnerEditListingServiceModel model)
        public async Task EditHomeStatusAsync_WithGivenRequestObject_ShouldChangeStatusAndReturnString()
        {
            // Arrange
            string       newName        = "New house on the block";
            string       newDescription = "Well maintained house close to the beach";
            HomeStatus   newStatus      = HomeStatus.Rented;
            HomeCategory newCategory    = HomeCategory.Room;

            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);
            var image   = ImageCreator.CreateForModel();
            var home    = HomeCreator.CreateAny(city.Id);

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

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

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

            await this.Context.CloudImages.AddAsync(image);

            await this.Context.SaveChangesAsync();

            var model = new OwnerEditListingServiceModel
            {
                Id          = home.Id,
                Name        = newName,
                Description = newDescription,
                Price       = 1000m,
                Status      = newStatus,
                Category    = newCategory,
                Image       = image,
            };

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

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

            var result = await service.EditListingAsync(model);

            var expected = true;

            // Assert
            result.Should().Be(true);
            result.Should().Equals(expected);

            savedEntry.Should().NotBeNull();
            savedEntry.Id.Should().Be(model.Id);
            savedEntry.Name.Should().Match(model.Name);
            savedEntry.Description.Should().Match(model.Description);
            savedEntry.Price.Should().Be(model.Price);
            savedEntry.Status.Should().Be(model.Status);
            savedEntry.Category.Should().Be(model.Category);
            savedEntry.Images.Select(i => i.PictureUrl).FirstOrDefault()
            .Should()
            .Match(model.Image.PictureUrl);
        }
示例#14
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");
        }
示例#15
0
        [Fact] // async Task<bool> StartHomeManage(string id, byte[] fileContent)
        public async Task StartHomeManage_WithGivenRequestIdAndDocumentFile_ShouldInitiateManagementContract()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);
            var home    = HomeCreator.CreateAny(city.Id);
            var image   = ImageCreator.CreateForModel();

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

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

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

            await this.Context.CloudImages.AddAsync(image);

            var request = RequestCreator.Create(home);

            await this.Context.Requests.AddAsync(request);

            await this.Context.SaveChangesAsync();

            var approvedRequest = RequestCreator.CreateManageApproved(home, request.User, request.Id);

            var user = request.User;

            this.UserManager
            .Setup(u => u.FindByIdAsync(user.Id))
            .Returns(Task.FromResult(user));
            await this.UserManager.Object
            .AddToRoleAsync(user, "Manager");

            var requestService = new Mock <IOwnerRequestService>();

            requestService.Setup(x => x.ApproveRequestAsync(request.Id))
            .Returns(Task.FromResult(approvedRequest));

            var contractService = new Mock <IOwnerContractService>();

            contractService.Setup(x => x.CreateManageContractAsync(new byte[1024], request.User))
            .Returns(Task.FromResult(true));

            var service = new OwnerListingService(this.Context, this.UserManager.Object, requestService.Object, contractService.Object);

            // Act
            var result = await service.StartHomeManage(request.Id, new byte[1024]);

            var changedHomeInfo = await this.Context.Homes.Where(h => h.Id == home.Id).FirstOrDefaultAsync();

            var changedUser = await this.Context.Users.Where(u => u.Id == user.Id).FirstOrDefaultAsync();

            // Assert
            result.Should().BeTrue();
            changedHomeInfo.ManagerId.Should().Equals(user.Id);
            changedUser.ManagedHomes.Count().Should().Be(1);
        }
示例#16
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);
        }
示例#17
0
        [Fact] // 7. async Task<OwnerRequestDetailsServiceModel> GetRequestDetailsAsync(string requestId)
        public async void GetRequestDetailsAsync_WithGivenRequestId_ShouldReturnServiceModel()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);
            var owner   = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");
            var home    = HomeCreator.CreateOwnerHome(owner.Id, city.Id);

            var request = RequestCreator.Create(home);

            var doc = new byte[1024];

            request.Document = doc;

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

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

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

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

            await this.Context.Requests.AddAsync(request);

            await this.Context.SaveChangesAsync();

            var model = new OwnerRequestDetailsServiceModel
            {
                Id            = request.Id,
                Date          = request.Date.ToString("dd/MM/yyyy h:mm tt"),
                UserFirstName = request.User.FirstName,
                UserLastName  = request.User.LastName,
                Email         = request.User.Email,
                Phone         = request.User.PhoneNumber,
                RequestType   = request.Type.ToString(),
                Document      = doc,
            };

            var service = new OwnerRequestService(this.Context);

            // Act
            var result = await service.GetRequestDetailsAsync(request.Id);

            var expected = model;

            // Assert
            result.Should().BeOfType <OwnerRequestDetailsServiceModel>();
            result.Should().Equals(expected);
        }
        [Fact] // 9. private async Task<IEnumerable<PropertyListServiceModel>> GetAllByCategoryAsync(HomeCategory category, HomeStatus managedStatus)
        public async void GetAllByCategoryAsync_()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateAny(city.Id);
            var home2 = HomeCreator.CreateAny(city.Id);
            var home3 = HomeCreator.CreateAny(city.Id);
            var home4 = HomeCreator.CreateAny(city.Id);
            var home5 = HomeCreator.CreateAny(city.Id);

            home4.Status   = HomeStatus.Rented;
            home4.Category = HomeCategory.Room;
            home5.Status   = HomeStatus.Rented;
            home5.Category = HomeCategory.Room;

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

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

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

            await this.Context.SaveChangesAsync();

            var service = new ListingService(this.Context);

            // Act
            Type       type = typeof(ListingService);
            var        getAllByCategoryAsync = Activator.CreateInstance(type, this.Context);
            MethodInfo method = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
                                .Where(x => x.Name == "GetAllByCategoryAsync" && x.IsPrivate)
                                .First();

            var result = (Task <IEnumerable <PropertyListServiceModel> >)method
                         .Invoke(getAllByCategoryAsync, new object[] { HomeCategory.Room, HomeStatus.Managed });

            var resultList = (await result).ToList();

            var expectedCount = this.Context.Homes
                                .Where(h => h.Status != HomeStatus.ToRent && h.Category == HomeCategory.Room)
                                .Count();

            // Assert
            resultList.Should().AllBeOfType <PropertyListServiceModel>();
            resultList.Should().HaveCount(expectedCount);
            resultList.Should().HaveCount(2, "Because there 2 homes with status not [Managed] and in category [Room]");
        }
        [Fact] // 2. async Task<IEnumerable<ManagerPaymentListServiceModel>> GetManagerPaymentsListAsync(string userId)
        public async void GetManagerPaymentsListAsync_ForGivenManagerId_ShouldReturnCollectionModel()
        {
            // 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.CreateAny(city.Id); // managed
            var home3 = HomeCreator.CreateAny(city.Id); // managed

            home2.Manager   = manager;
            home2.OwnerId   = home2.Owner.Id;
            home2.ManagerId = manager.Id;
            home3.Manager   = manager;
            home3.OwnerId   = home3.Owner.Id;
            home3.ManagerId = manager.Id;

            var payment2 = PaymentCreator.CreateForManager(home2.Owner.Id, home2.Manager.Id, home2.Id);
            var payment3 = PaymentCreator.CreateForManager(home3.Owner.Id, home2.Manager.Id, home3.Id);

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

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

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

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

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

            await this.Context.SaveChangesAsync();

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

            // Act
            var result = await service.GetManagerPaymentsListAsync(home2.Manager.Id);

            var expected = await this.Context.Homes
                           .Where(h => h.ManagerId == home2.Manager.Id)
                           .SelectMany(h => h.Payments)
                           .ToListAsync();

            // Assert
            result.Should().AllBeOfType <ManagerPaymentListServiceModel>();
            result.Count().Should().Equals(2);
            result.Count().Should().Equals(expected.Count());
        }
        [Fact] // 11. PRIVATE async Task<PropertyCountServiceModel> GetByCategoryAsync(HomeStatus managed, HomeCategory category)
        public async void GetByStatusAsync_WithGivenCategoryEnumAndManagedStatusEnum_ShouldReturnModel()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateAny(city.Id);
            var home2 = HomeCreator.CreateAny(city.Id);
            var home3 = HomeCreator.CreateAny(city.Id);
            var home4 = HomeCreator.CreateAny(city.Id);
            var home5 = HomeCreator.CreateAny(city.Id);

            home4.Status   = HomeStatus.Rented;
            home4.Category = HomeCategory.Room;
            home5.Status   = HomeStatus.Rented;
            home5.Category = HomeCategory.Room;

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

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

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

            await this.Context.SaveChangesAsync();

            var service = new ListingService(this.Context);

            // Act
            Type       type = typeof(ListingService);
            var        getByCategoryAsync = Activator.CreateInstance(type, this.Context);
            MethodInfo method             = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
                                            .Where(x => x.Name == "GetByCategoryAsync" && x.IsPrivate)
                                            .First();

            var result = (Task <PropertyCountServiceModel>)method
                         .Invoke(getByCategoryAsync, new object[] { HomeStatus.Managed, HomeCategory.Room });

            var resultFinal = await result;

            var expectedCount = this.Context.Homes
                                .Where(h => h.Status != HomeStatus.Managed && h.Category == HomeCategory.Room)
                                .Count();

            // Assert
            resultFinal.Should().BeOfType <PropertyCountServiceModel>();
            resultFinal.Count.Should().Equals(expectedCount);
            resultFinal.Count.Should().Be(2, "Because there 2 homes with status which is not [Managed] and category [Room]");
        }
示例#21
0
        [Fact] // 2. async Task<IEnumerable<OwnerAllRequestsServiceModel>> GetAllRequestsWthDetailsAsync(string id)
        public async void GetAllRequestsWthDetailsAsync_WithGivenOwnerId_ShouldReturnCollectionOfRequests()
        {
            // Arrange
            var country      = CountryCreator.Create();
            var city         = CityCreator.Create(country.Id);
            var owner        = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");
            var anotherOwner = UserCreator.Create("Svinevud", "Kulchibutov", "kulkata", "*****@*****.**");
            var home         = HomeCreator.CreateOwnerHome(owner.Id, city.Id);
            var home2        = HomeCreator.CreateOwnerHome(owner.Id, city.Id);
            var homе3        = HomeCreator.CreateOwnerHome(owner.Id, city.Id);
            var homе4        = HomeCreator.CreateOwnerHome(anotherOwner.Id, city.Id);

            var request  = RequestCreator.Create(home);
            var request2 = RequestCreator.Create(home2);
            var request3 = RequestCreator.Create(homе3);
            var request4 = RequestCreator.Create(homе4);

            request2.User.UserName = "******";
            request3.User.UserName = "******";

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

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

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

            await this.Context.Homes.AddRangeAsync(home, home2, homе3, homе4);

            await this.Context.Requests.AddRangeAsync(request, request2, request3, request4);

            await this.Context.SaveChangesAsync();

            var service = new OwnerRequestService(this.Context);

            // Act
            var result   = (await service.GetAllRequestsWthDetailsAsync(owner.Id)).ToList();
            var expected = await this.Context.Requests.Where(r => r.Home.OwnerId == owner.Id).ToListAsync();

            // Assert
            result.Should().AllBeOfType <OwnerAllRequestsServiceModel>();
            result.Count().Should().Equals(expected.Count());
            result.Should().HaveCount(3, "because there are 3 homes for which the owner received requests individually");
            result[0].Username = request.User.UserName;  // shpeka
            result[1].Username = request2.User.UserName; // fileto
            result[2].Username = request3.User.UserName; // butcheto
        }
        [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();
        }
示例#23
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);
        }
示例#24
0
        [Fact] // 3. async Task<Request> ApproveRequestAsync(string id)
        public async void ApproveRequestAsync_WithGivenId_ShouldApproveRequest_AndReturnTheRequest()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);
            var owner   = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");
            var home    = HomeCreator.CreateOwnerHome(owner.Id, city.Id);
            var home2   = HomeCreator.CreateOwnerHome(owner.Id, city.Id);

            var request  = RequestCreator.Create(home);
            var request2 = RequestCreator.Create(home2);

            var requestStatusBefore  = request.Status;
            var request2StatusBefore = request2.Status;

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

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

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

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

            await this.Context.Requests.AddRangeAsync(request, request2);

            await this.Context.SaveChangesAsync();

            var service = new OwnerRequestService(this.Context);

            // Act
            var result = await service.ApproveRequestAsync(request.Id);

            var result2 = await service.ApproveRequestAsync(request2.Id);

            var expected  = RequestStatus.Approved;
            var expected2 = RequestStatus.Approved;

            // Assert
            result.Should().BeOfType <Request>();
            result.Status.Should().Equals(expected);
            result2.Status.Should().Equals(expected2);
            result.Status.Should().NotBe(requestStatusBefore);
            result2.Status.Should().NotBe(request2StatusBefore);
        }
示例#25
0
        [Fact] // async Task<string> CreateToAsync(string senderId, OwnerTransactionToRequestsCreateInputServiceModel model)
        public async void CreateToAsync_WithGivenSenderIdAndRequestModel_ShouldCreateTransactionRequest()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);
            var owner   = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");

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

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

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

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

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

            await this.Context.SaveChangesAsync();

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

            var model = new OwnerTransactionToRequestsCreateInputServiceModel
            {
                Id                = Guid.NewGuid().ToString(),
                Reason            = Guid.NewGuid().ToString(),
                RecurringSchedule = RecurringScheduleType.Monthly,
                IsRecurring       = true,
                HomeId            = home.Id,
            };

            var service = new OwnerTransactionRequestService(this.Context);

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

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

            // Assert
            result.Should().BeOfType <string>();
            result.Should().Equals(expected.Id);
        }
        [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
        }
示例#27
0
        [Fact] // 4. async Task<bool> RejectRequestAsync(string id)
        public async void RejectRequestAsync_WithGivenId_ShouldRejectRequest_AndReturnTrue()
        {
            // Arrange
            var country      = CountryCreator.Create();
            var city         = CityCreator.Create(country.Id);
            var owner        = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");
            var anotherOwner = UserCreator.Create("Svinevud", "Kulchibutov", "kulkata", "*****@*****.**");
            var home         = HomeCreator.CreateOwnerHome(owner.Id, city.Id);
            var home2        = HomeCreator.CreateOwnerHome(owner.Id, city.Id);

            var request  = RequestCreator.Create(home);
            var request2 = RequestCreator.Create(home2);

            var requestStatusBefore  = request.Status;
            var request2StatusBefore = request2.Status;

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

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

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

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

            await this.Context.Requests.AddRangeAsync(request, request2);

            await this.Context.SaveChangesAsync();

            var service = new OwnerRequestService(this.Context);

            // Act
            var result = await service.RejectRequestAsync(request.Id);

            var result2 = await service.RejectRequestAsync(request2.Id);

            // Assert
            result.Should().BeTrue();
            result2.Should().BeTrue();
        }
示例#28
0
        [Fact] // 5. async Task<byte[]> GetFileAsync(string requestId)
        public async void GetFileAsync_WithGivenRequestId_ShouldReturnByteArrayOfTheFile()
        {
            // Arrange
            var country      = CountryCreator.Create();
            var city         = CityCreator.Create(country.Id);
            var owner        = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**");
            var anotherOwner = UserCreator.Create("Svinevud", "Kulchibutov", "kulkata", "*****@*****.**");
            var home         = HomeCreator.CreateOwnerHome(owner.Id, city.Id);

            var request = RequestCreator.Create(home);

            request.Document = new byte [1024];

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

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

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

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

            await this.Context.Requests.AddAsync(request);

            await this.Context.SaveChangesAsync();

            var service = new OwnerRequestService(this.Context);

            // Act
            var result = await service.GetFileAsync(request.Id);

            var expected = await this.Context.Requests
                           .Where(r => r.Id == request.Id)
                           .Select(r => r.Document)
                           .FirstOrDefaultAsync();

            // Assert
            result.Should().BeOfType <byte[]>();
            result.Should().Equals(expected);
        }
示例#29
0
        [Fact] // async Task<string> ChangeHomeStatusAsync(Request request)
        public async Task ChangeHomeStatusAsync_WithGivenRequestObject_ShouldReturnHomeIdWhenSuccessful()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);
            var home    = HomeCreator.CreateAny(city.Id);
            var image   = ImageCreator.CreateForModel();

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

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

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

            await this.Context.CloudImages.AddAsync(image);

            var request = RequestCreator.Create(home);

            await this.Context.Requests.AddAsync(request);

            await this.Context.SaveChangesAsync();

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

            // Act
            var result = await service.ChangeHomeStatusAsync(request);

            var homeFromDb = await this.Context.Homes.Where(h => h.Id == home.Id).FirstOrDefaultAsync();

            // Assert
            result.Should().NotBeNull();
            result.Should().BeOfType <string>();
            result.Should().Match(home.Id);
            result.Should().Match(homeFromDb.Id);
            homeFromDb.Status.Should().NotBe(HomeStatus.ToRent);
            homeFromDb.Status.Should().Be(HomeStatus.Rented);
        }
        [Fact] // 7. public async Task<IEnumerable<PropertyListServiceModel>> FindAsync(string searchText)
        public async void FindAsync_WithGivenSearchStringForCity_ShouldReturnListModel()
        {
            // Arrange
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);
            var city2   = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateAny(city2.Id);

            home1.City = city2;
            var home2 = HomeCreator.CreateAny(city.Id);
            var home3 = HomeCreator.CreateAny(city.Id);
            var home4 = HomeCreator.CreateAny(city.Id);
            var home5 = HomeCreator.CreateAny(city.Id);

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

            await this.Context.Cities.AddRangeAsync(city, city2);

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

            await this.Context.SaveChangesAsync();

            string search  = city2.Name;
            var    service = new ListingService(this.Context);

            // Act
            var result        = (await service.FindAsync(search)).ToList();
            var expectedCount = this.Context.Homes
                                .Where(h => h.City.Name == search)
                                .Count();

            // Assert
            result.Should().AllBeOfType <PropertyListServiceModel>();
            result.Should().HaveCount(expectedCount);
            result.Should().HaveCount(1, "Because there is 1 home from the searched city");
        }