public UserSettingsServiceTests() { _options = new DbContextOptionsBuilder <StockNotificationContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; _dbContext = new StockNotificationContext(_options); _userSettingsService = new UserSettingsService(_dbContext); }
public static void Initialize(StockNotificationContext stockNotificationContext) { var listOfExcludedSellers = new List <tblExcludedSellers>(); listOfExcludedSellers.Add(new tblExcludedSellersBuilder().WithUsername("bjorn").WithSellerId(7).Build()); listOfExcludedSellers.Add(new tblExcludedSellersBuilder().WithUsername("bjorn").WithSellerId(8).Build()); stockNotificationContext.tblExcludedSellers.AddRange(listOfExcludedSellers); stockNotificationContext.SaveChanges(); }
public static void Initialize(StockNotificationContext stockNotificationContext) { var listOfSellers = new List <tblSellers>(); listOfSellers.Add(new tblSellersBuilder().WithId(1).WithName("Amazon").WithUrl("https://www.amazon.co.uk").Build()); listOfSellers.Add(new tblSellersBuilder().WithId(2).WithName("Ebay").WithUrl("https://www.ebay.co.uk").Build()); listOfSellers.Add(new tblSellersBuilder().WithId(3).WithName("Currys PC World").WithUrl("https://www.currys.co.uk").Build()); listOfSellers.Add(new tblSellersBuilder().WithId(4).WithName("Argos").WithUrl("https://www.argos.co.uk").Build()); listOfSellers.Add(new tblSellersBuilder().WithId(5).WithName("Smyths").WithUrl("https://www.smythstoys.com").Build()); listOfSellers.Add(new tblSellersBuilder().WithId(6).WithName("Target").WithUrl("https://www.target.com").Build()); listOfSellers.Add(new tblSellersBuilder().WithId(7).WithName("Best Buy").WithUrl("https://www.bestbuy.com").Build()); listOfSellers.Add(new tblSellersBuilder().WithId(8).WithName("Walmart").WithUrl("https://www.walmart.com").Build()); stockNotificationContext.tblSellers.AddRange(listOfSellers); stockNotificationContext.SaveChanges(); }
public async Task UpdateUserSellerPreferences_Updates_User_Settings_Two() { // Arrange await _dbContext.Database.EnsureDeletedAsync(); using (var seedingContext = new StockNotificationContext(_options)) { var listOfSellers = new List <tblSellers>(); listOfSellers.Add(new tblSellersBuilder().WithId(1).WithName("Amazon").WithUrl("https://www.amazon.co.uk").Build()); listOfSellers.Add(new tblSellersBuilder().WithId(2).WithName("Ebay").WithUrl("https://www.ebay.co.uk").Build()); listOfSellers.Add(new tblSellersBuilder().WithId(3).WithName("Currys PC World").WithUrl("https://www.currys.co.uk").Build()); listOfSellers.Add(new tblSellersBuilder().WithId(4).WithName("Argos").WithUrl("https://www.argos.co.uk").Build()); listOfSellers.Add(new tblSellersBuilder().WithId(5).WithName("Smyths").WithUrl("https://www.smythstoys.com").Build()); listOfSellers.Add(new tblSellersBuilder().WithId(6).WithName("Target").WithUrl("https://www.target.com").Build()); seedingContext.tblSellers.AddRange(listOfSellers); var listOfExclSellers = new List <tblExcludedSellers>(); listOfExclSellers.Add(new tblExcludedSellersBuilder().WithUsername(_username).WithSellerId(5).Build()); listOfExclSellers.Add(new tblExcludedSellersBuilder().WithUsername(_username).WithSellerId(6).Build()); seedingContext.tblExcludedSellers.AddRange(listOfExclSellers); await seedingContext.SaveChangesAsync(); } var newListOfSellers = new List <int>() { 1, 2, 3, 5 }; // Act var task = _userSettingsService.UpdateUserSellerPreferences(_username, newListOfSellers); await task; // Assert var updatedList = _dbContext.tblExcludedSellers.Where(x => x.Username == _username).Select(x => x.SellerId).ToList(); Assert.Equal(2, updatedList.Count); Assert.Contains(4, updatedList); Assert.Contains(6, updatedList); }
public UserSettingsService(StockNotificationContext dbContext) { _dbContext = dbContext; }