forked from dotnet-architecture/eShopOnWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetQuantities.cs
42 lines (37 loc) · 1.6 KB
/
SetQuantities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
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 Xunit;
namespace Microsoft.eShopWeb.IntegrationTests.Repositories.BasketRepositoryTests
{
public class SetQuantities
{
private readonly CatalogContext _catalogContext;
private readonly IAsyncRepository<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);
}
}
}