public async void GetFavRetailer_CanGetFavRetailerById(int numForFavRetailerId, int numToTest, int numForUserId, bool expectedBool) { DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanGetFavRetailerById").Options; using (RimrockDBContext context = new RimrockDBContext(options)) { // Arrange FavRetailer newFavRetailer = new FavRetailer(); newFavRetailer.Id = numForFavRetailerId; newFavRetailer.UserId = numForUserId; newFavRetailer.RegionId = 2; newFavRetailer.Name = "Grand Teton"; newFavRetailer.Specialty = "Mountaineering"; FavRetailerService favRetailerService = new FavRetailerService(context); await context.FavRetailers.AddAsync(newFavRetailer); await context.SaveChangesAsync(); // Act List <FavRetailer> favRetailerListFromDb = await favRetailerService.GetFavRetailers(newFavRetailer.UserId); // Boolean test (needed for Theory-type unit test) bool actualBool = false; if (numToTest == favRetailerListFromDb[0].UserId) { actualBool = true; } // Assert Assert.Equal(actualBool, expectedBool); }; }
public async void DeleteFavRetailer_CanDeleteFavRetailerById() { DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanDeleteFavRetailerById").Options; using (RimrockDBContext context = new RimrockDBContext(options)) { // Arrange FavRetailer newFavRetailer = new FavRetailer(); newFavRetailer.Id = 1; newFavRetailer.Name = "Second Ascents"; newFavRetailer.Specialty = "Climbing"; // Act FavRetailerService favRetailerService = new FavRetailerService(context); await context.FavRetailers.AddAsync(newFavRetailer); await context.SaveChangesAsync(); // Act await favRetailerService.DeleteFavRetailer(1); List <FavRetailer> listOfRetailersInDb = await context.FavRetailers.Where(fr => fr.UserId == newFavRetailer.Id).ToListAsync(); // Assert Assert.Empty(listOfRetailersInDb); }; }
public async void CreateFavRetailer_CanAddNewFavRetailerInDatabase() { DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanCreateNewFavRetailer").Options; using (RimrockDBContext context = new RimrockDBContext(options)) { // Arrange FavRetailer favRetailer = new FavRetailer(); favRetailer.Id = 1; favRetailer.Name = "Second Ascents"; favRetailer.Specialty = "Climbing"; // Act FavRetailerService favRetailerService = new FavRetailerService(context); await favRetailerService.CreateFavRetailer(favRetailer); FavRetailer favRetailersFromDb = await context.FavRetailers .FirstOrDefaultAsync(fl => fl.Name == favRetailer.Name); // Assert Assert.Equal(favRetailersFromDb, favRetailer); }; }