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.
Merge branch 'main' into tw-bootstrap
- Loading branch information
Showing
13 changed files
with
129 additions
and
96 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
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
24 changes: 13 additions & 11 deletions
24
tests/UnitTests/ApplicationCore/Services/BasketServiceTests/AddItemToBasket.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 |
---|---|---|
@@ -1,44 +1,46 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; | ||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; | ||
using Microsoft.eShopWeb.ApplicationCore.Interfaces; | ||
using Microsoft.eShopWeb.ApplicationCore.Services; | ||
using Microsoft.eShopWeb.ApplicationCore.Specifications; | ||
using Moq; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests; | ||
|
||
public class AddItemToBasket | ||
{ | ||
private readonly string _buyerId = "Test buyerId"; | ||
private readonly Mock<IRepository<Basket>> _mockBasketRepo = new(); | ||
private readonly Mock<IAppLogger<BasketService>> _mockLogger = new(); | ||
private readonly IRepository<Basket> _mockBasketRepo = Substitute.For<IRepository<Basket>>(); | ||
private readonly IAppLogger<BasketService> _mockLogger = Substitute.For<IAppLogger<BasketService>>(); | ||
|
||
[Fact] | ||
public async Task InvokesBasketRepositoryGetBySpecAsyncOnce() | ||
{ | ||
var basket = new Basket(_buyerId); | ||
basket.AddItem(1, It.IsAny<decimal>(), It.IsAny<int>()); | ||
_mockBasketRepo.Setup(x => x.FirstOrDefaultAsync(It.IsAny<BasketWithItemsSpecification>(), default)).ReturnsAsync(basket); | ||
basket.AddItem(1, 1.5m); | ||
|
||
var basketService = new BasketService(_mockBasketRepo.Object, _mockLogger.Object); | ||
_mockBasketRepo.FirstOrDefaultAsync(Arg.Any<BasketWithItemsSpecification>(), default).Returns(basket); | ||
|
||
var basketService = new BasketService(_mockBasketRepo, _mockLogger); | ||
|
||
await basketService.AddItemToBasket(basket.BuyerId, 1, 1.50m); | ||
|
||
_mockBasketRepo.Verify(x => x.FirstOrDefaultAsync(It.IsAny<BasketWithItemsSpecification>(), default), Times.Once); | ||
await _mockBasketRepo.Received().FirstOrDefaultAsync(Arg.Any<BasketWithItemsSpecification>(), default); | ||
} | ||
|
||
[Fact] | ||
public async Task InvokesBasketRepositoryUpdateAsyncOnce() | ||
{ | ||
var basket = new Basket(_buyerId); | ||
basket.AddItem(1, It.IsAny<decimal>(), It.IsAny<int>()); | ||
_mockBasketRepo.Setup(x => x.FirstOrDefaultAsync(It.IsAny<BasketWithItemsSpecification>(), default)).ReturnsAsync(basket); | ||
basket.AddItem(1, 1.1m, 1); | ||
_mockBasketRepo.FirstOrDefaultAsync(Arg.Any<BasketWithItemsSpecification>(), default).Returns(basket); | ||
|
||
var basketService = new BasketService(_mockBasketRepo.Object, _mockLogger.Object); | ||
var basketService = new BasketService(_mockBasketRepo, _mockLogger); | ||
|
||
await basketService.AddItemToBasket(basket.BuyerId, 1, 1.50m); | ||
|
||
_mockBasketRepo.Verify(x => x.UpdateAsync(basket, default), Times.Once); | ||
await _mockBasketRepo.Received().UpdateAsync(basket, default); | ||
} | ||
} |
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
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
Oops, something went wrong.