|
@ -2,7 +2,6 @@ |
|
|
using Basket.API.Model; |
|
|
using Basket.API.Model; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; |
|
|
|
|
|
using Microsoft.eShopOnContainers.Services.Basket.API.Controllers; |
|
|
using Microsoft.eShopOnContainers.Services.Basket.API.Controllers; |
|
|
using Microsoft.eShopOnContainers.Services.Basket.API.Model; |
|
|
using Microsoft.eShopOnContainers.Services.Basket.API.Model; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
@ -11,6 +10,7 @@ using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Security.Claims; |
|
|
using System.Security.Claims; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using DotNetCore.CAP; |
|
|
using Xunit; |
|
|
using Xunit; |
|
|
using IBasketIdentityService = Microsoft.eShopOnContainers.Services.Basket.API.Services.IIdentityService; |
|
|
using IBasketIdentityService = Microsoft.eShopOnContainers.Services.Basket.API.Services.IIdentityService; |
|
|
|
|
|
|
|
@ -20,14 +20,14 @@ namespace UnitTest.Basket.Application |
|
|
{ |
|
|
{ |
|
|
private readonly Mock<IBasketRepository> _basketRepositoryMock; |
|
|
private readonly Mock<IBasketRepository> _basketRepositoryMock; |
|
|
private readonly Mock<IBasketIdentityService> _identityServiceMock; |
|
|
private readonly Mock<IBasketIdentityService> _identityServiceMock; |
|
|
private readonly Mock<IEventBus> _serviceBusMock; |
|
|
|
|
|
|
|
|
private readonly Mock<ICapPublisher> _serviceBusMock; |
|
|
private readonly Mock<ILogger<BasketController>> _loggerMock; |
|
|
private readonly Mock<ILogger<BasketController>> _loggerMock; |
|
|
|
|
|
|
|
|
public BasketWebApiTest() |
|
|
public BasketWebApiTest() |
|
|
{ |
|
|
{ |
|
|
_basketRepositoryMock = new Mock<IBasketRepository>(); |
|
|
_basketRepositoryMock = new Mock<IBasketRepository>(); |
|
|
_identityServiceMock = new Mock<IBasketIdentityService>(); |
|
|
_identityServiceMock = new Mock<IBasketIdentityService>(); |
|
|
_serviceBusMock = new Mock<IEventBus>(); |
|
|
|
|
|
|
|
|
_serviceBusMock = new Mock<ICapPublisher>(); |
|
|
_loggerMock = new Mock<ILogger<BasketController>>(); |
|
|
_loggerMock = new Mock<ILogger<BasketController>>(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -42,7 +42,7 @@ namespace UnitTest.Basket.Application |
|
|
.Returns(Task.FromResult(fakeCustomerBasket)); |
|
|
.Returns(Task.FromResult(fakeCustomerBasket)); |
|
|
_identityServiceMock.Setup(x => x.GetUserIdentity()).Returns(fakeCustomerId); |
|
|
_identityServiceMock.Setup(x => x.GetUserIdentity()).Returns(fakeCustomerId); |
|
|
|
|
|
|
|
|
_serviceBusMock.Setup(x => x.Publish(It.IsAny<UserCheckoutAcceptedIntegrationEvent>())); |
|
|
|
|
|
|
|
|
_serviceBusMock.Setup(x => x.Publish(nameof(UserCheckoutAcceptedIntegrationEvent), It.IsAny<UserCheckoutAcceptedIntegrationEvent>(), null)); |
|
|
|
|
|
|
|
|
//Act
|
|
|
//Act
|
|
|
var basketController = new BasketController( |
|
|
var basketController = new BasketController( |
|
@ -54,7 +54,6 @@ namespace UnitTest.Basket.Application |
|
|
var actionResult = await basketController.GetBasketByIdAsync(fakeCustomerId); |
|
|
var actionResult = await basketController.GetBasketByIdAsync(fakeCustomerId); |
|
|
|
|
|
|
|
|
//Assert
|
|
|
//Assert
|
|
|
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK); |
|
|
|
|
|
Assert.Equal(((CustomerBasket)actionResult.Value).BuyerId, fakeCustomerId); |
|
|
Assert.Equal(((CustomerBasket)actionResult.Value).BuyerId, fakeCustomerId); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -68,7 +67,7 @@ namespace UnitTest.Basket.Application |
|
|
_basketRepositoryMock.Setup(x => x.UpdateBasketAsync(It.IsAny<CustomerBasket>())) |
|
|
_basketRepositoryMock.Setup(x => x.UpdateBasketAsync(It.IsAny<CustomerBasket>())) |
|
|
.Returns(Task.FromResult(fakeCustomerBasket)); |
|
|
.Returns(Task.FromResult(fakeCustomerBasket)); |
|
|
_identityServiceMock.Setup(x => x.GetUserIdentity()).Returns(fakeCustomerId); |
|
|
_identityServiceMock.Setup(x => x.GetUserIdentity()).Returns(fakeCustomerId); |
|
|
_serviceBusMock.Setup(x => x.Publish(It.IsAny<UserCheckoutAcceptedIntegrationEvent>())); |
|
|
|
|
|
|
|
|
_serviceBusMock.Setup(x => x.Publish(nameof(UserCheckoutAcceptedIntegrationEvent), It.IsAny<UserCheckoutAcceptedIntegrationEvent>(), null)); |
|
|
|
|
|
|
|
|
//Act
|
|
|
//Act
|
|
|
var basketController = new BasketController( |
|
|
var basketController = new BasketController( |
|
@ -80,7 +79,6 @@ namespace UnitTest.Basket.Application |
|
|
var actionResult = await basketController.UpdateBasketAsync(fakeCustomerBasket); |
|
|
var actionResult = await basketController.UpdateBasketAsync(fakeCustomerBasket); |
|
|
|
|
|
|
|
|
//Assert
|
|
|
//Assert
|
|
|
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK); |
|
|
|
|
|
Assert.Equal(((CustomerBasket)actionResult.Value).BuyerId, fakeCustomerId); |
|
|
Assert.Equal(((CustomerBasket)actionResult.Value).BuyerId, fakeCustomerId); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -132,7 +130,7 @@ namespace UnitTest.Basket.Application |
|
|
//Act
|
|
|
//Act
|
|
|
var result = await basketController.CheckoutAsync(new BasketCheckout(), Guid.NewGuid().ToString()) as AcceptedResult; |
|
|
var result = await basketController.CheckoutAsync(new BasketCheckout(), Guid.NewGuid().ToString()) as AcceptedResult; |
|
|
|
|
|
|
|
|
_serviceBusMock.Verify(mock => mock.Publish(It.IsAny<UserCheckoutAcceptedIntegrationEvent>()), Times.Once); |
|
|
|
|
|
|
|
|
_serviceBusMock.Verify(mock => mock.Publish(nameof(UserCheckoutAcceptedIntegrationEvent), It.IsAny<UserCheckoutAcceptedIntegrationEvent>(), null), Times.Once); |
|
|
|
|
|
|
|
|
Assert.NotNull(result); |
|
|
Assert.NotNull(result); |
|
|
} |
|
|
} |
|
|