Mediatr example (#325)
* Updates based on documentation * Getting the build passing * Getting app functioning * A few cleanups to confirm it's working as expected * Fixing functional tests * Updating dockerfile for 3.0 * Functional Tests now run sequentially * Updating to latest version of moq * Adding migration for post 3.0 upgrades * Removing commented out lines * Moving address and catalogitemordered configuration in to classes that own them * Installing MediatR nuget packages * Configure MediatR in Startup * Creating GetMyOrders MediatR query and handler * Adding GetOrderDetails MediatR handler * Refactoring out default values * Added tests for GetOrderDetails mediator handler * Defaulting values on Models for now * Removing some spaces * Splitting files * Splitting out the GetOrderDetails files * Adding test for GetMyOrders * restructuing folders * Using constant
This commit is contained in:
committed by
Steve Smith
parent
1bae9e68d9
commit
29d1497a3f
@@ -0,0 +1,38 @@
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||
using Microsoft.eShopWeb.Web.Features.MyOrders;
|
||||
using Moq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.MediatorHandlers.OrdersTests
|
||||
{
|
||||
public class GetMyOrders_Should
|
||||
{
|
||||
private readonly Mock<IOrderRepository> _mockOrderRepository;
|
||||
|
||||
public GetMyOrders_Should()
|
||||
{
|
||||
var item = new OrderItem(new CatalogItemOrdered(1, "ProductName", "URI"), 10.00m, 10);
|
||||
var address = new Address(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>());
|
||||
Order order = new Order("buyerId", address, new List<OrderItem> { item });
|
||||
|
||||
_mockOrderRepository = new Mock<IOrderRepository>();
|
||||
_mockOrderRepository.Setup(x => x.ListAsync(It.IsAny<ISpecification<Order>>())).ReturnsAsync(new List<Order> { order });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NotReturnNull_If_OrdersArePresent()
|
||||
{
|
||||
var request = new GetMyOrders("SomeUserName");
|
||||
|
||||
var handler = new GetMyOrdersHandler(_mockOrderRepository.Object);
|
||||
|
||||
var result = await handler.Handle(request, CancellationToken.None);
|
||||
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||
using Microsoft.eShopWeb.Web.Features.OrderDetails;
|
||||
using Moq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.MediatorHandlers.OrdersTests
|
||||
{
|
||||
public class GetOrderDetails_Should
|
||||
{
|
||||
private readonly Mock<IOrderRepository> _mockOrderRepository;
|
||||
|
||||
public GetOrderDetails_Should()
|
||||
{
|
||||
var item = new OrderItem(new CatalogItemOrdered(1, "ProductName", "URI"), 10.00m, 10);
|
||||
var address = new Address(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>());
|
||||
Order order = new Order("buyerId", address, new List<OrderItem> { item });
|
||||
|
||||
_mockOrderRepository = new Mock<IOrderRepository>();
|
||||
_mockOrderRepository.Setup(x => x.ListAsync(It.IsAny<ISpecification<Order>>())).ReturnsAsync(new List<Order> { order });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NotBeNull_If_Order_Exists()
|
||||
{
|
||||
var request = new GetOrderDetails("SomeUserName", 0);
|
||||
|
||||
var handler = new GetOrderDetailsHandler(_mockOrderRepository.Object);
|
||||
|
||||
var result = await handler.Handle(request, CancellationToken.None);
|
||||
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BeNull_If_Order_Not_found()
|
||||
{
|
||||
var request = new GetOrderDetails("SomeUserName", 100);
|
||||
|
||||
var handler = new GetOrderDetailsHandler(_mockOrderRepository.Object);
|
||||
|
||||
var result = await handler.Handle(request, CancellationToken.None);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ApplicationCore\ApplicationCore.csproj" />
|
||||
<ProjectReference Include="..\..\src\Web\Web.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user