public void GetAvailableLodgingsByTouristSpotOk() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); Lodging lodgingOfConrad = new Lodging() { Id = Guid.NewGuid(), Name = "Hotel Enjoy Conrad", QuantityOfStars = 5, Address = "Parada 4 Playa Mansa, Rambla Claudio Williman", PricePerNight = 1500, TouristSpot = touristSpot, }; lodgingRepository.Add(lodging); lodgingRepository.Add(lodgingOfConrad); List <Lodging> listWithOriginalsLodgings = new List <Lodging>(); listWithOriginalsLodgings.Add(lodging); listWithOriginalsLodgings.Add(lodgingOfConrad); List <Lodging> listOfLodgingOfDb = lodgingRepository.GetAvailableLodgingsByTouristSpot(touristSpot.Id).ToList(); CollectionAssert.AreEqual(listWithOriginalsLodgings, listOfLodgingOfDb); }
public void GetAvailableLodgingsByTouristSpotNotFound() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); lodgingRepository.GetAvailableLodgingsByTouristSpot(touristSpot.Id).ToList(); }
public void TestRemoveLodgingDoesntExist() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); lodgingRepository.Remove(lodging); }
public void TestUpdateLodgingInvalid() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); lodgingRepository.Update(lodging); }
public async void Test_LodgingRepo_GetAsyncById() { var dbOptions = await NewDb(); using (var ctx = new LodgingContext(dbOptions)) { await ctx.Database.EnsureCreatedAsync(); await ctx.SaveChangesAsync(); // Add repo-specific setup here. await ctx.SaveChangesAsync(); } using (var ctx = new LodgingContext(dbOptions)) { var repo = new LodgingRepository(ctx); // Add repo-specific method calls here. var actual = await repo.GetAsync(1); // Add Asserts here. Assert.Null(actual); } }
public void GetReviewByReserveIdTest() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); IReviewRepository reviewRepo = new ReviewRepository(context); ITouristSpotRepository touristSpotRepo = new TouristSpotRepository(context); ILodgingRepository lodgingRepo = new LodgingRepository(context); IRepository <Reserve> reserveRepo = new BaseRepository <Reserve>(context); touristSpotRepo.Add(touristSpot); lodgingRepo.Add(lodging); reserveRepo.Add(reserve); Review reviewToAdd = new Review() { Id = Guid.NewGuid(), Description = "Me gusto mucho la estadia", IdOfReserve = reserve.Id, LastNameOfWhoComments = reserve.LastName, NameOfWhoComments = reserve.Name, LodgingOfReview = lodging, Score = 4 }; reviewRepo.Add(reviewToAdd); Review reviewResult = reviewRepo.GetReviewByReserveId(reserve.Id); Assert.IsTrue(reviewResult.Equals(reviewToAdd)); }
public void GetLodgingDoesntExist() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); Lodging lodgingOfDb = lodgingRepository.Get(lodging.Id); }
public void Test_GenerateOrderByFunc_EmptyKey() { var queryParams = new LodgingQueryParamsModel(); var orderByFunc = LodgingRepository.GenerateOrderByFunc(queryParams); Assert.Null(orderByFunc); }
public async void Test_Repository_DeleteAsync(LodgingModel lodging, RentalModel rental, ReviewModel review) { await _connection.OpenAsync(); try { using (var ctx = new LodgingContext(_options)) { await ctx.Database.EnsureCreatedAsync(); await ctx.Lodgings.AddAsync(lodging); await ctx.Rentals.AddAsync(rental); await ctx.Reviews.AddAsync(review); await ctx.SaveChangesAsync(); } using (var ctx = new LodgingContext(_options)) { var lodgings = new LodgingRepository(ctx); await lodgings.DeleteAsync(1); await ctx.SaveChangesAsync(); Assert.Empty(await ctx.Lodgings.ToListAsync()); } using (var ctx = new LodgingContext(_options)) { var rentals = new RentalRepository(ctx); await rentals.DeleteAsync(1); await ctx.SaveChangesAsync(); Assert.Empty(await ctx.Rentals.ToListAsync()); } using (var ctx = new LodgingContext(_options)) { var reviews = new ReviewRepository(ctx); await reviews.DeleteAsync(1); await ctx.SaveChangesAsync(); Assert.Empty(await ctx.Reviews.ToListAsync()); } } finally { await _connection.CloseAsync(); } }
public void TestGetLodgingOK() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); lodgingRepository.Add(lodging); Lodging lodgingOfDb = lodgingRepository.Get(lodging.Id); Assert.AreEqual(lodging, lodgingOfDb); }
public void Test_GenerateOrderByFunc(string sortKey) { var queryParams = new LodgingQueryParamsModel(); queryParams.SortKey = sortKey; var orderByFunc = LodgingRepository.GenerateOrderByFunc(queryParams); Assert.NotNull(orderByFunc); }
public void GetLodgingByNameAndTouristSpotTest() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); lodgingRepository.Add(lodging); Lodging lodgingObteined = lodgingRepository.GetLodgingByNameAndTouristSpot(lodging.Name, lodging.TouristSpot.Id); Assert.AreEqual(lodging, lodgingObteined); }
public void Test_GenerateOrderByFunc_InvalidKey() { var queryParams = new LodgingQueryParamsModel(); queryParams.SortKey = "missing"; var orderByFunc = LodgingRepository.GenerateOrderByFunc(queryParams); Assert.Null(orderByFunc); }
public void TestAddLodgingOK() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); lodgingRepository.Add(lodging); List <Lodging> listOfLodging = lodgingRepository.GetAll().ToList(); Assert.AreEqual(lodging, listOfLodging[0]); }
public void Test_GenerateFilterFuncs() { var queryParams = new LodgingQueryParamsModel(); queryParams.HasBedType = "King"; queryParams.HasAmenity = "Coffee"; queryParams.City = "test"; var funcs = LodgingRepository.GenerateFilterFuncs(queryParams); // 4 filters are always added, +3 more based on params. Assert.Equal(7, funcs.Count); }
public void TestUpdateLodgingOK() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); lodgingRepository.Add(lodging); lodging.Name = "Hotel Enjoy Conrad"; lodgingRepository.Update(lodging); List <Lodging> listOfLodgings = lodgingRepository.GetAll().ToList(); Assert.AreNotEqual("Hotel Las Cumbres", listOfLodgings[0].Name); }
public void TestGenerateReportWithoutLodgings() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); ITouristSpotRepository touristSpotRepository = new TouristSpotRepository(context); ICategoryRepository categoryRepository = new CategoryRepository(context); categoryRepository.Add(aCategory); touristSpotRepository.Add(touristSpot); lodgingRepository.Add(lodging); DateTime checkInDate = new DateTime(2020, 05, 24); DateTime checkOutDate = new DateTime(2020, 06, 11); List <Lodging> listOfLodgingsWithReserve = lodgingRepository.GetLodgingsWithReserves(touristSpot.Id, checkInDate, checkOutDate); }
public async void Test_Repository_GetAsync_ById() { await _connection.OpenAsync(); try { using (var ctx = new LodgingContext(_options)) { await ctx.Database.EnsureCreatedAsync(); } using (var ctx = new LodgingContext(_options)) { var lodgings = new LodgingRepository(ctx); var actual = await lodgings.GetAsync(1); Assert.Null(actual); } using (var ctx = new LodgingContext(_options)) { var rentals = new RentalRepository(ctx); var actual = await rentals.GetAsync(1); Assert.Null(actual); } using (var ctx = new LodgingContext(_options)) { var reviews = new ReviewRepository(ctx); var actual = await reviews.GetAsync(1); Assert.Null(actual); } } finally { await _connection.CloseAsync(); } }
public async void Test_LodgingRepo_GetAsyncById() { var dbOptions = await NewDb(); using (var ctx = new LodgingContext(dbOptions)) { await ctx.Database.EnsureCreatedAsync(); await ctx.SaveChangesAsync(); } using (var ctx = new LodgingContext(dbOptions)) { var repo = new LodgingRepository(ctx); var actual = await repo.GetAsync(1, new LodgingQueryParamsModel()); Assert.Null(actual); } }
public void Setup() { Options = new DbContextOptionsBuilder <UruguayNaturalContext>() .UseInMemoryDatabase("UruguayNaturalDBTest") .Options; Context = new UruguayNaturalContext(Options); Repository = new LodgingRepository(Context); TouristSpots = new List <TouristSpot> { CreateTouristSpot(1), CreateTouristSpot(2) }; Context.AddRange(TouristSpots); ReportModel = new ReportModel { TouristSpot = 1, CheckIn = DateTime.Now, CheckOut = DateTime.Now.AddDays(5) }; }
public void TestGenerateReportOKWithMoreReserves() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); ITouristSpotRepository touristSpotRepository = new TouristSpotRepository(context); ICategoryRepository categoryRepository = new CategoryRepository(context); IRepository <Reserve> reserveRepository = new BaseRepository <Reserve>(context); categoryRepository.Add(aCategory); touristSpotRepository.Add(touristSpot); lodgingRepository.Add(lodging); lodgingRepository.Add(lodging2); reserve.LodgingOfReserve = lodging3; reserveRepository.Add(reserve); reserveRepository.Add(reserve2); DateTime checkInDate = new DateTime(2020, 05, 24); DateTime checkOutDate = new DateTime(2020, 06, 11); List <Lodging> listOfLodgingsWithReserve = lodgingRepository.GetLodgingsWithReserves(touristSpot.Id, checkInDate, checkOutDate); Assert.IsTrue(listOfLodgingsWithReserve.Contains(lodging3)); }
public async void Test_LodgingRepo_GetAsync_IncludeImages() { var dbOptions = await NewDb(); using (var ctx = new LodgingContext(dbOptions)) { await ctx.Database.EnsureCreatedAsync(); await ctx.SaveChangesAsync(); } using (var ctx = new LodgingContext(dbOptions)) { var repo = new LodgingRepository(ctx); var queryParams = new LodgingQueryParamsModel(); queryParams.IncludeImages = true; var actual = await repo.GetAsync(queryParams); Assert.Empty(actual); } }
public void TestGenerateReportOK() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); ITouristSpotRepository touristSpotRepository = new TouristSpotRepository(context); ICategoryRepository categoryRepository = new CategoryRepository(context); IRepository <Reserve> reserveRepository = new BaseRepository <Reserve>(context); categoryRepository.Add(aCategory); touristSpotRepository.Add(touristSpot); lodgingRepository.Add(lodging); lodgingRepository.Add(lodging2); reserveRepository.Add(reserve); DateTime checkInDate = new DateTime(2020, 05, 24); DateTime checkOutDate = new DateTime(2020, 06, 11); List <Lodging> listOfLodgingsWithReserve = lodgingRepository.GetLodgingsWithReserves(touristSpot.Id, checkInDate, checkOutDate); Assert.IsTrue(listOfLodgingsWithReserve[0].Equals(lodging) && listOfLodgingsWithReserve.Count == 1 && listOfLodgingsWithReserve[0].QuantityOfReserveForThePeriod(checkInDate, checkOutDate) == 1); }
public async void Test_Repository_Update(LodgingModel lodging, RentalModel rental, ReviewModel review) { await _connection.OpenAsync(); try { using (var ctx = new LodgingContext(_options)) { await ctx.Database.EnsureCreatedAsync(); await ctx.Lodgings.AddAsync(lodging); await ctx.Rentals.AddAsync(rental); await ctx.Reviews.AddAsync(review); await ctx.SaveChangesAsync(); } using (var ctx = new LodgingContext(_options)) { var lodgings = new LodgingRepository(ctx); var expected = await ctx.Lodgings.FirstAsync(); expected.Name = "name"; lodgings.Update(expected); await ctx.SaveChangesAsync(); var actual = await ctx.Lodgings.FirstAsync(); Assert.Equal(expected, actual); } using (var ctx = new LodgingContext(_options)) { var rentals = new RentalRepository(ctx); var expected = await ctx.Rentals.FirstAsync(); expected.Name = "name"; rentals.Update(expected); await ctx.SaveChangesAsync(); var actual = await ctx.Rentals.FirstAsync(); Assert.Equal(expected, actual); } using (var ctx = new LodgingContext(_options)) { var reviews = new ReviewRepository(ctx); var expected = await ctx.Reviews.FirstAsync(); expected.Comment = "comment"; reviews.Update(expected); await ctx.SaveChangesAsync(); var actual = await ctx.Reviews.FirstAsync(); Assert.Equal(expected, actual); } } finally { await _connection.CloseAsync(); } }
public SimpleDataUnitOfWork(UnicornsContext context, IEnumerable <IInterceptor> interceptors) : base(context, interceptors) { Activity = new LodgingRepository(context); }