示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        [Fact] // async Task<bool> CreateListingAsync(OwnerCreateListingServiceModel model)
        public async Task CreateListingAsync_WithGivenInputModel_ShouldCreateOwnerListingAndReturnTrue()
        {
            // Arrange
            const string modelName        = "New house close to the beach.";
            const string modelDescription = "That we can tuck in our children at night and know that they are fed and clothed and safe from harm. I wanted to be part of something larger. And yet, it has only been in the last couple of weeks that the discussion of race in this campaign has taken a particularly divisive turn.";
            const string modelAddress     = "10, G.M. Dimitrov, 1700";

            var owner   = UserCreator.Create("Prasemir", "Butonoskov", "prasio", "*****@*****.**");
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);
            var image   = ImageCreator.CreateForModel();

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

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

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

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

            await this.Context.SaveChangesAsync();

            var model = new OwnerCreateListingServiceModel
            {
                Name        = modelName,
                Description = modelDescription,
                Address     = modelAddress,
                CityId      = city.Id,
                Price       = 1000,
                Status      = HomeStatus.ToRent,
                Category    = HomeCategory.House,
                Owner       = owner,
                Image       = image,
            };

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

            // Act
            var result = await service.CreateListingAsync(model);

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

            var expected = true;

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

            savedEntry.Should().NotBeNull();
            savedEntry.Name.Should().Match(modelName);
            savedEntry.Description.Should().Match(modelDescription);
            savedEntry.OwnerId.Should().Match(owner.Id);
            savedEntry.Images.Any(i => i.PictureUrl == image.PictureUrl);
        }
示例#4
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);
        }
示例#5
0
        [Fact] // async Task<bool> StartRent(string id, byte[] fileContent)
        public async void StartRent_ForGivenOwnerId_ShouldSuccessfullyInitiateRentAndReturnTrue()
        {
            // 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.CreateRentApproved(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, "Tenant");

            var requestService = new Mock <IOwnerRequestService>();

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

            var listingService = new Mock <IOwnerListingService>();

            listingService
            .Setup(x => x.ChangeHomeStatusAsync(approvedRequest))
            .Returns(Task.FromResult(approvedRequest.HomeId));

            var rental = new Rental
            {
                Id       = 1,
                RentDate = DateTime.UtcNow,
                HomeId   = home.Id,
                TenantId = user.Id,
            };

            var rentalServiceMock = new Mock <IOwnerRentalService>();

            rentalServiceMock.Setup(y => y.CreateRental(home.Id, user.Id))
            .Returns(Task.FromResult(rental));

            var contractService = new Mock <IOwnerContractService>();

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

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

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

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

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

            // Assert
            result.Should().BeTrue();
            rentalInfo.TenantId.Should().Equals(user.Id);
            changedUser.Rentals.Count().Should().Be(1);
        }