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 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 DeleteFavLocation_CanDeleteFavLocationById() { DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanDeleteFavLocById").Options; using (RimrockDBContext context = new RimrockDBContext(options)) { // Arrange FavLocation newFavLocation = new FavLocation(); newFavLocation.Id = 1; newFavLocation.UserId = 1; newFavLocation.RegionId = 2; newFavLocation.Name = "Grand Teton"; newFavLocation.Cost = "$$"; FavLocationService favLocService = new FavLocationService(context); await context.FavLocations.AddAsync(newFavLocation); await context.SaveChangesAsync(); // Act await favLocService.DeleteFavLocation(1); List <FavLocation> listOfLocationsInDb = await context.FavLocations.Where(fl => fl.UserId == newFavLocation.Id).ToListAsync(); // Assert Assert.Empty(listOfLocationsInDb); }; }
public async void GetFavLocation_CanGetFavLocationById ( int numForFavLocId, int numToTest, int numForUserId, bool expectedBool ) { DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanGetFavLocById").Options; using (RimrockDBContext context = new RimrockDBContext(options)) { // Arrange FavLocation newFavLocation = new FavLocation(); newFavLocation.Id = numForFavLocId; newFavLocation.UserId = numForUserId; newFavLocation.RegionId = 2; newFavLocation.Name = "Grand Teton"; newFavLocation.Cost = "$$"; FavLocationService favLocService = new FavLocationService(context); await context.FavLocations.AddAsync(newFavLocation); await context.SaveChangesAsync(); // Act List <FavLocation> favLocationListFromDb = await favLocService.GetFavLocations(newFavLocation.UserId); // Boolean test (needed for Theory-type unit test) bool actualBool = false; if (numToTest == favLocationListFromDb[0].UserId) { actualBool = true; } // Assert Assert.Equal(actualBool, expectedBool); }; }
public async void GetUser_CanGetSingleUser() { DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanGetSingleUserByName").Options; using (RimrockDBContext context = new RimrockDBContext(options)) { // Arrange User newUser = new User(); newUser.ID = 1; newUser.Name = "Jason Burns"; // Act UserService userService = new UserService(context); await context.Users.AddAsync(newUser); await context.SaveChangesAsync(); User userFromDb = await userService.GetUser(newUser.Name); // Assert Assert.Equal(userFromDb, newUser); }; }
public async void CreateUser_CanCreateSingleUser() { DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanCreateSingleUser").Options; using (RimrockDBContext context = new RimrockDBContext(options)) { // Arrange User newUser = new User(); newUser.ID = 1; newUser.Name = "Phil Werner"; // Act UserService userService = new UserService(context); await userService.CreateUser(newUser); User userFromDb = await context.Users .FirstOrDefaultAsync(u => u.Name == newUser.Name); // Assert Assert.Equal(userFromDb, newUser); }; }
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); }; }
public async void CreateFavLocation_CanAddNewFavLocationInDatabase() { DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanCreateNewFavLocation").Options; using (RimrockDBContext context = new RimrockDBContext(options)) { // Arrange FavLocation favLocation = new FavLocation(); favLocation.Id = 1; favLocation.Name = "Yosemite"; favLocation.Cost = "$$"; // Act FavLocationService favLocService = new FavLocationService(context); await favLocService.CreateFavLocation(favLocation); FavLocation favLocationFromDb = await context.FavLocations .FirstOrDefaultAsync(fl => fl.Name == favLocation.Name); // Assert Assert.Equal(favLocationFromDb, favLocation); }; }
public UserService(RimrockDBContext context) { _context = context; }
public FavRetailerService(RimrockDBContext context) { _context = context; }
public FavLocationService(RimrockDBContext context) { _context = context; }