public void AddRestaurantToBlacklistShouldSucceedIfUserAndRestaurantAreValid(string username, string rId, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; AppUserRepo uRepo; RestaurantRepo rRepo; Blacklist result; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); rRepo = new RestaurantRepo(context); if (useAsync) { uRepo.AddRestaurantToBlacklistAsync(username, rId, rRepo).Wait(); } else { uRepo.AddRestaurantToBlacklist(username, rId, rRepo); } result = context.Blacklist.Find(rId, username); } //Assert Assert.Equal(username, result.Username); Assert.Equal(rId, result.RestaurantId); }
public void AddRestaurantToBlacklistShouldThrowExceptionIfRestrauntAlreadyInUsersBlacklist(string username, string rId, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "EmptyAddTesting4DB") .Options; AppUserRepo uRepo; RestaurantRepo rRepo; bool result = false; using (var context = new Project2DBContext(options)) { context.Blacklist.Add(new Blacklist { Username = username, RestaurantId = rId }); } //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); rRepo = new RestaurantRepo(context); try { if (useAsync) { uRepo.AddRestaurantToBlacklistAsync(username, rId, rRepo).Wait(); } else { uRepo.AddRestaurantToBlacklist(username, rId, rRepo); } } catch (DbUpdateException) { result = true; } catch (AggregateException) { result = true; } } //Assert Assert.True(result); }
public void AddRestaurantToBlacklistShouldThrowExceptionIfUserNotInDB(string username, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "EmptyDB8") .Options; AppUserRepo uRepo; RestaurantRepo rRepo; bool result = false; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); rRepo = new RestaurantRepo(context); try { if (useAsync) { uRepo.AddRestaurantToBlacklistAsync(username, "anything", rRepo).Wait(); } else { uRepo.AddRestaurantToBlacklist(username, "anything", rRepo); } } catch (DbUpdateException) { result = true; } catch (AggregateException) { result = true; } } //Assert Assert.True(result); }