Example #1
0
        public async Task UpdateUserSellerPreferences_Updates_User_Settings()
        {
            // Arrange
            await _dbContext.Database.EnsureDeletedAsync();

            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());
            _dbContext.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());
            _dbContext.tblExcludedSellers.AddRange(listOfExclSellers);

            await _dbContext.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);
        }