Exemple #1
0
        public async Task TestGetListingViewModelByIdAsyncInvalidId()
        {
            // Arrange
            var options = BuildDbContextOptions();

            ListingViewModel result;

            await using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var repository = new ListingRepository(context);

                var service = new ListingService(repository,
                                                 null,
                                                 null,
                                                 null,
                                                 null,
                                                 _mapper);

                // Act
                result = await service.GetListingViewModelByIdAsync(666);

                context.Database.EnsureDeleted();
            }

            // Assert
            Assert.Null(result);
        }
 /// <summary>
 /// Constructor for Inventor controller containing all required services
 /// </summary>
 /// <param name="service"></param>
 /// <param name="listingService"></param>
 /// <param name="optionsService"></param>
 /// <param name="imageService"></param>
 public InventoryController(DbService service, ListingService listingService, OptionsService optionsService, ImageService imageService)
 {
     _dbService      = service;
     _listingService = listingService;
     _optionsService = optionsService;
     _imageService   = imageService;
 }
        [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]");
        }
Exemple #4
0
        public void Setup()
        {
            var dataContext = new DataContext(_dbContextOptions);

            _listingService    = new ListingService(dataContext);
            _listingController = new ListingController(_listingService);
        }
        [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");
        }
Exemple #6
0
        public async Task TestGetFilteredListingViewModelsValidQuery()
        {
            // Arrange
            var options = BuildDbContextOptions();

            IEnumerable <ListingViewModel> result;

            await using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var repository = new ListingRepository(context);

                var service = new ListingService(repository,
                                                 null,
                                                 null,
                                                 null,
                                                 null,
                                                 _mapper);

                // Act
                result = await service.GetFilteredListingViewModels(1, "Ford");

                context.Database.EnsureDeleted();
            }

            // Assert
            var enumerable = result.ToList();

            Assert.NotEmpty(enumerable);
            Assert.IsAssignableFrom <IEnumerable <ListingViewModel> >(result);
            Assert.Equal(2, enumerable.Count);
        }
        [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));
        }
        public void Delete()
        {
            // Delete non existance of file.
            try
            {
                ListingService.Delete(path + @"\delete.txt");
                Assert.Fail();
            }
            catch (ByteTurnNotFoundException byteturnex)
            {
                Assert.AreEqual(typeof(ByteTurnNotFoundException), byteturnex.GetType());
            }

            // Illegal characters.
            try
            {
                ListingService.Delete(path + @"\dele|te.txt");
                Assert.Fail();
            }
            catch (ByteTurnNotSupportedException byteturnex)
            {
                Assert.AreEqual(typeof(ByteTurnNotSupportedException), byteturnex.GetType());
            }

            var p = ListingService.Create("testfile-3.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction);

            ListingService.Delete(path + @"\testfile-3.txt");
        }
Exemple #9
0
        public async Task TestGetListingViewModelByIdAsyncIdValid()
        {
            // Arrange
            var options = BuildDbContextOptions();

            ListingViewModel result;

            await using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var repository = new ListingRepository(context);

                var service = new ListingService(repository,
                                                 null,
                                                 null,
                                                 null,
                                                 null,
                                                 _mapper);

                // Act
                result = await service.GetListingViewModelByIdAsync(1);

                context.Database.EnsureDeleted();
            }

            // Assert
            Assert.NotNull(result);
            Assert.IsAssignableFrom <ListingViewModel>(result);
            Assert.Equal("1991 Mazda Miata", result.Title);
        }
        [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);
        }
Exemple #11
0
        public async Task TestIndex()
        {
            // Arrange
            var options = BuildDbContextOptions();

            IActionResult result;

            await using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var repository = new ListingRepository(context);

                var service = new ListingService(repository,
                                                 null,
                                                 null,
                                                 null,
                                                 null,
                                                 new Mapper(GetMapperConfig()));

                var controller = new HomeController(service);

                // Act
                result = await controller.Index(null);

                context.Database.EnsureDeleted();
            }

            // Assert
            var viewResult  = Assert.IsAssignableFrom <ViewResult>(result);
            var modelResult = Assert.IsAssignableFrom <IEnumerable <ListingViewModel> >(viewResult.Model);
        }
        [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]");
        }
Exemple #13
0
        public async void TestGetListingById()
        {
            // Arrange
            var     options = BuildDbContextOptions();
            Listing result;

            // Act
            await using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var repository = new ListingRepository(context);

                var service = new ListingService(repository, null, null, null, null, null);

                result = await service.GetListingByIdAsync(1);
            }

            // Assert
            await using (var context = new ApplicationDbContext(options))
            {
                Assert.Equal(1, result.Id);

                context.Database.EnsureDeleted();
            }
        }
Exemple #14
0
        public void Init()
        {
            path       = Path.GetFullPath(path);
            parentPath = Path.GetFullPath(parentPath);
            testPath   = Path.GetFullPath(testPath);

            if (!ListingService.Exists(path))
            {
                ListingService.Create("Test", parentPath, Data.Listing.ListingTypeOption.Directory, Data.Listing.DuplicateListingActionOption.NoAction);
            }

            var deleteFiles = ListingService.GetListingByDirectory(path, true, true);

            foreach (var f in deleteFiles)
            {
                ListingService.Delete(f.FullFilePath);
            }

            var testFiles = ListingService.GetListingByDirectory(testPath, false, true);

            foreach (var f in testFiles)
            {
                ListingService.Copy(f.FullFilePath, path + @"\" + f.Name);
            }
        }
Exemple #15
0
        public async Task TestAddListingAsyncInputModelNull()
        {
            // Arrange
            var options = BuildDbContextOptions();

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var repository = new ListingRepository(context);

                var service = new ListingService(repository,
                                                 null,
                                                 null,
                                                 null,
                                                 null,
                                                 null);

                Assert.Equal(6, context.Listing.Count());

                // Act
                await service.AddListingAsync(null);
            }

            await using (var context = new ApplicationDbContext(options))
            {
                // Assert
                Assert.Equal(6, context.Listing.Count());

                context.Database.EnsureDeleted();
            }
        }
Exemple #16
0
        public async Task TestGetAllListingsAsync()
        {
            // Arrange
            var options = BuildDbContextOptions();
            IEnumerable <Listing> result;

            // Act
            await using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var repository = new ListingRepository(context);

                var service = new ListingService(repository, null, null, null, null, null);

                result = await service.GetAllListings();
            }

            // Assert
            await using (var context = new ApplicationDbContext(options))
            {
                Assert.Equal(
                    context.Listing.ToList().Count, result.Count());

                context.Database.EnsureDeleted();
            }
        }
        [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]");
        }
Exemple #18
0
        public async Task TestGetFilteredListingViewModelsInvalidQuery(string query)
        {
            // Arrange
            var options = BuildDbContextOptions();

            IEnumerable <ListingViewModel> result;

            await using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var repository = new ListingRepository(context);

                var service = new ListingService(repository,
                                                 null,
                                                 null,
                                                 null,
                                                 null,
                                                 _mapper);

                // Act
                result = await service.GetFilteredListingViewModels(1, query);

                context.Database.EnsureDeleted();
            }

            // Assert
            Assert.NotNull(result);
            Assert.Empty(result);
            Assert.IsAssignableFrom <IEnumerable <ListingViewModel> >(result);
        }
Exemple #19
0
        public async Task TestGetAllListingsAsViewModelEmptyContext()
        {
            // Arrange
            var options = BuildDbContextOptions();

            IEnumerable <ListingViewModel> result;

            await using (var context = new ApplicationDbContext(options))
            {
                var repository = new ListingRepository(context);

                var service = new ListingService(repository,
                                                 null,
                                                 null,
                                                 null,
                                                 null,
                                                 _mapper);

                // Act
                result = await service.GetAllListingsAsViewModel();
            }

            // Assert
            Assert.NotNull(result);
            Assert.Empty(result);
            Assert.IsAssignableFrom <IEnumerable <ListingViewModel> >(result);
        }
Exemple #20
0
        public void TestAddNullObject()
        {
            // Arrange
            var options = BuildDbContextOptions();
            ListingInputModel testObject = null;

            // Act
            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var repository = new ListingRepository(context);

                var service = new ListingService(repository, null, null, null, null, null);

                service.AddListingAsync(testObject);
            }

            // Assert
            using (var context = new ApplicationDbContext(options))
            {
                var result = context.Listing.ToList();

                Assert.Equal(6, result.Count);

                context.Database.EnsureDeleted();
            }
        }
 /// <summary>
 /// Default constructor. Has services passed in through dependency injection
 /// </summary>
 /// <param name="userManager">The user manager for IdentityUsers</param>
 /// <param name="roleManager">The role manager for IdentityRoles</param>
 public AccountController(DbService dbService,
                          IdentityService identityService,
                          BannerService bannerService,
                          ListingService listingService)
 {
     _dbService       = dbService;
     _identityService = identityService;
     _bannerService   = bannerService;
     _listingService  = listingService;
 }
        public void ShouldDeserializeLargePropertyListing()
        {
            var listingJson = StubDataLoader.LoadJsonFile("LargeListings.json");

            IListingService service = new ListingService(new MoxiWorksClient(new StubContextClient(listingJson)));

            var response = service.GetListingsUpdatedSinceAsync("moxi_works_company_id", AgentIdType.AgentUuid, "some_uuid", DateTime.Now).Result;

            Assert.IsType <ListingResults>(response.Item);
            Assert.True(response.Item.Listings.Count == 1);
        }
Exemple #23
0
        public static void Main(string[] args)
        {
            var listingService = new ListingService();

            var listing1 = listingService.Create(new FreeListing
            {
                Name = "Restaurante Las Antillas"
            });

            var listing2 = listingService.Create(null);
        }
        public ActionResult Index(HttpPostedFileBase FileUpload)
        {
            var allowedFileExtensions = new List <string>();

            allowedFileExtensions.Add("jpg");
            allowedFileExtensions.Add("gif");
            allowedFileExtensions.Add("png");

            var path = ListingService.Upload(FileUpload.InputStream, FileUpload.FileName, Server.MapPath(@"Upload\2\4"), allowedFileExtensions, Data.Listing.DuplicateListingActionOption.AppendNumber);

            return(View());
        }
Exemple #25
0
        public ReportResult Post([FromBody] FileData fileData)
        {
            if (fileData == null || string.IsNullOrEmpty(fileData.listingFile))
            {
                throw new FileNotFoundException("File is not attached");
            }

            ListingService service = new ListingService();

            var result = service.GetReportResult(fileData.listingFile);

            return(result);
        }
Exemple #26
0
        public void Move()
        {
            // Create 3 text files.
            var p = ListingService.Create("testfile-5.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction);

            ListingService.Create("testfile-51.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction);
            ListingService.Create("testfile-53.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction);

            // No action - file does not exist.
            var f = ListingService.Move(path + @"\testfile-5.txt", path + @"\testfile-52.txt", DuplicateListingActionOption.NoAction);

            Assert.AreEqual(f, path + @"\testfile-52.txt");
            Assert.AreEqual(ListingService.Exists(path + @"\testfile-52.txt"), true);
            Assert.AreEqual(ListingService.Exists(path + @"\testfile-5.txt"), false);

            // No action - file exists.
            try
            {
                f = ListingService.Move(path + @"\testfile-51.txt", path + @"\testfile-52.txt", DuplicateListingActionOption.NoAction);
                Assert.Fail();
            }
            catch (ByteTurnExistsException byteturnex)
            {
                Assert.AreEqual(typeof(ByteTurnExistsException), byteturnex.GetType());
            }

            // Illegal characters.
            try
            {
                f = ListingService.Move(path + @"\testf|ile-51.txt", path + @"\testfil|e-52.txt", DuplicateListingActionOption.NoAction);
                Assert.Fail();
            }
            catch (ByteTurnNotSupportedException byteturnex)
            {
                Assert.AreEqual(typeof(ByteTurnNotSupportedException), byteturnex.GetType());
            }

            // Overwrite
            f = ListingService.Move(path + @"\testfile-51.txt", path + @"\testfile-52.txt", DuplicateListingActionOption.Overwrite);
            Assert.AreEqual(f, path + @"\testfile-52.txt");
            Assert.AreEqual(ListingService.Exists(path + @"\testfile-52.txt"), true);
            Assert.AreEqual(ListingService.Exists(path + @"\testfile-51.txt"), false);

            // Append number
            f = ListingService.Move(path + @"\testfile-53.txt", path + @"\testfile-52.txt", DuplicateListingActionOption.AppendNumber);
            Assert.AreEqual(f, path + @"\(1) testfile-52.txt");
            Assert.AreEqual(ListingService.Exists(path + @"\(1) testfile-52.txt"), true);
            Assert.AreEqual(ListingService.Exists(path + @"\testfile-53.txt"), false);
        }
        public void ShouldUpdateListingInfo()
        {
            var listingJson = StubDataLoader.LoadJsonFile("listings.json");

            IListingService service = new ListingService(new MoxiWorksClient(new StubContextClient(listingJson)));
            var             update  = new ListingUpdate
            {
                VirtualTourURL = "http://www.example.com"
            };

            var response = service.UpdateListingDataAsync(update).Result;

            Assert.IsType <ListingResults>(response.Item);
            Assert.True(response.Item.Listings.Count == 1);
        }
        [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]");
        }
        [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]");
        }
Exemple #30
0
        public void Create()
        {
            try
            {
                ListingService.Create("testfile.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction);
                Assert.Fail();
            }
            catch (ByteTurnExistsException byteturnex)
            {
                Assert.AreEqual(typeof(ByteTurnExistsException), byteturnex.GetType());
            }

            // Illegal characters.
            try
            {
                ListingService.Create("testfile|.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction);
                Assert.Fail();
            }
            catch (ByteTurnNotSupportedException byteturnex)
            {
                Assert.AreEqual(typeof(ByteTurnNotSupportedException), byteturnex.GetType());
            }

            var p = ListingService.Create("testfile-2.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction);

            Assert.AreEqual(p, path + @"\testfile-2.txt");
            Assert.AreEqual(ListingService.Exists(path + @"\testfile-2.txt"), true);

            p = ListingService.Create("testfile.txt", path, ListingTypeOption.File, DuplicateListingActionOption.AppendNumber);

            Assert.AreEqual(p, path + @"\(1) testfile.txt");
            Assert.AreEqual(ListingService.Exists(path + @"\(1) testfile.txt"), true);

            p = ListingService.Create("testfile.txt", path, ListingTypeOption.File, DuplicateListingActionOption.Overwrite);

            Assert.AreEqual(p, path + @"\testfile.txt");

            var f = new FileData(p);

            Assert.AreEqual(f.Size.IsEqual(new FileSize(0)), true);
        }