public async Task GetPropertiesForUserShouldReturnOnlyPropertiesThatBelongsToTheUser()
        {
            var db = GetDatabase();

            AutoMapperConfig.RegisterMappings(typeof(VisualisePropertiesViewModel).Assembly);
            var property = new Property()
            {
                Id   = 1,
                Name = "Name",
            };
            var property2 = new Property()
            {
                Id   = 2,
                Name = "Name",
            };
            var property3 = new Property()
            {
                Id   = 3,
                Name = "Name",
            };
            var propertiesRepository = new EfDeletableEntityRepository <Property>(db);

            var service = new PropertiesService(propertiesRepository);
            await db.Properties.AddRangeAsync(property, property2, property3);

            await db.SaveChangesAsync();

            var lol = service.GetProperties <VisualisePropertiesViewModel>(2);

            Assert.Equal(2, lol.Count());
        }
Exemple #2
0
        public async Task GetPropertiesShouldThrow(double lat, double lng)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var db = new ApplicationDbContext(options);

            var service = new PropertiesService(db);

            await Assert.ThrowsAnyAsync <Exception>(async() => await service.GetProperties(lat, lng));
        }
Exemple #3
0
        public async Task GetPropertiesShouldReturn4Hotels(double lat, double lng)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var db = new ApplicationDbContext(options);

            var service = new PropertiesService(db);

            var result = await service.GetProperties(lat, lng);

            Assert.Equal(4, result.Length);
        }
Exemple #4
0
        public async Task GetPropertiesShouldReturnValidHotels(double lat, double lng)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var db = new ApplicationDbContext(options);

            var service = new PropertiesService(db);

            var result = await service.GetProperties(lat, lng);

            foreach (var hotel in result)
            {
                Assert.NotNull(hotel.Name);
            }
        }
 public async Task <IActionResult> GetProperties([FromQuery] PropertiesParameters parameters) =>
 await Utilities.Utilities.TryCatchAsync(
     async() =>
 {
     if (!parameters.ValidYearRange)
     {
         return(BadRequest("Max year cannot be less than min year"));
     }
     if (!parameters.ValidPriceRange)
     {
         return(BadRequest("Max price cannot be less than min price"));
     }
     return(Ok(await _service.GetProperties(parameters)));
 },
     HttpErrorHandler
     );