Files
eShopOnWeb/tests/IntegrationTests/Repositories/BasketRepositoryTests/SetQuantities.cs
Steve Smith 8a45a2c858 Update Specification and other packages to latest version (#582)
* Updating repositories and specification version
Need to fix broken tests

* removing test that would just be testing mocked result now

* Refactored from IAsyncRepository and removed it.
Tests pass.

* Update packages
2021-10-25 15:13:02 -04:00

42 lines
1.6 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
using Microsoft.eShopWeb.ApplicationCore.Services;
using Microsoft.eShopWeb.Infrastructure.Data;
using Microsoft.eShopWeb.UnitTests.Builders;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.eShopWeb.IntegrationTests.Repositories.BasketRepositoryTests
{
public class SetQuantities
{
private readonly CatalogContext _catalogContext;
private readonly EfRepository<Basket> _basketRepository;
private readonly BasketBuilder BasketBuilder = new BasketBuilder();
public SetQuantities()
{
var dbOptions = new DbContextOptionsBuilder<CatalogContext>()
.UseInMemoryDatabase(databaseName: "TestCatalog")
.Options;
_catalogContext = new CatalogContext(dbOptions);
_basketRepository = new EfRepository<Basket>(_catalogContext);
}
[Fact]
public async Task RemoveEmptyQuantities()
{
var basket = BasketBuilder.WithOneBasketItem();
var basketService = new BasketService(_basketRepository, null);
await _basketRepository.AddAsync(basket);
_catalogContext.SaveChanges();
await basketService.SetQuantities(BasketBuilder.BasketId, new Dictionary<string, int>() { { BasketBuilder.BasketId.ToString(), 0 } });
Assert.Equal(0, basket.Items.Count);
}
}
}