forked from dotnet-architecture/eShopOnWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to remove items from the basket setting quantity to zero
- Loading branch information
Showing
7 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tests/IntegrationTests/Repositories/BasketRepositoryTests/SetQuantities.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
tests/UnitTests/ApplicationCore/Services/BasketServiceTests/TransferBasket.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters