Added ordering unit tests
This commit is contained in:
parent
77de525916
commit
e7ec7260bb
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.26206.0
|
VisualStudioVersion = 15.0.26228.0
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{932D8224-11F6-4D07-B109-DA28AD288A63}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{932D8224-11F6-4D07-B109-DA28AD288A63}"
|
||||||
EndProject
|
EndProject
|
||||||
@ -454,10 +454,10 @@ Global
|
|||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|x64.ActiveCfg = Release|x64
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|x64.ActiveCfg = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|x64.Build.0 = Release|x64
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|x64.Build.0 = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|x86.ActiveCfg = Release|x86
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|x86.Build.0 = Release|x86
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Ad-Hoc|x86.Build.0 = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|Any CPU.Build.0 = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|ARM.ActiveCfg = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|ARM.ActiveCfg = Debug|Any CPU
|
||||||
@ -466,10 +466,10 @@ Global
|
|||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|iPhone.Build.0 = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|iPhone.Build.0 = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|x64.ActiveCfg = Release|x64
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|x64.ActiveCfg = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|x64.Build.0 = Release|x64
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|x64.Build.0 = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|x86.ActiveCfg = Release|x86
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|x86.ActiveCfg = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|x86.Build.0 = Release|x86
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.AppStore|x86.Build.0 = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||||
@ -478,10 +478,10 @@ Global
|
|||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|iPhone.Build.0 = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|iPhone.Build.0 = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|x64.ActiveCfg = Debug|x64
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|x64.Build.0 = Debug|x64
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|x86.ActiveCfg = Debug|x86
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|x86.Build.0 = Debug|x86
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|Any CPU.Build.0 = Release|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|ARM.ActiveCfg = Release|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||||
@ -490,10 +490,10 @@ Global
|
|||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|iPhone.Build.0 = Release|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|iPhone.Build.0 = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|x64.ActiveCfg = Release|x64
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|x64.Build.0 = Release|x64
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|x86.ActiveCfg = Release|x86
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|x86.Build.0 = Release|x86
|
{F16E3C6A-1C94-4EAB-BE91-099618060B68}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -77,6 +77,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
|
|||||||
CardHolderName = cardHolderName;
|
CardHolderName = cardHolderName;
|
||||||
CardSecurityNumber = cardSecurityNumber;
|
CardSecurityNumber = cardSecurityNumber;
|
||||||
CardTypeId = cardTypeId;
|
CardTypeId = cardTypeId;
|
||||||
|
CardExpiration = cardExpiration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,10 +6,13 @@ using Moq;
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace UnitTest.Ordering.Application
|
namespace UnitTest.Ordering.Application
|
||||||
{
|
{
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Xunit;
|
||||||
public class NewOrderRequestHandlerTest
|
public class NewOrderRequestHandlerTest
|
||||||
{
|
{
|
||||||
private readonly Mock<IBuyerRepository<Buyer>> _buyerRepositoryMock;
|
private readonly Mock<IBuyerRepository<Buyer>> _buyerRepositoryMock;
|
||||||
@ -29,6 +32,10 @@ namespace UnitTest.Ordering.Application
|
|||||||
{
|
{
|
||||||
|
|
||||||
var buyerId = "1234";
|
var buyerId = "1234";
|
||||||
|
|
||||||
|
var fakeOrderCmd = FakeOrderRequestWithBuyer(new Dictionary<string, object>
|
||||||
|
{ ["cardExpiration"] = DateTime.Now.AddYears(1) });
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(buyerId))
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(buyerId))
|
||||||
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
||||||
@ -45,7 +52,7 @@ namespace UnitTest.Ordering.Application
|
|||||||
_identityServiceMock.Setup(svc => svc.GetUserIdentity()).Returns(buyerId);
|
_identityServiceMock.Setup(svc => svc.GetUserIdentity()).Returns(buyerId);
|
||||||
//Act
|
//Act
|
||||||
var handler = new CreateOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object, _identityServiceMock.Object);
|
var handler = new CreateOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object, _identityServiceMock.Object);
|
||||||
var result = await handler.Handle(FakeOrderRequestWithBuyer());
|
var result = await handler.Handle(fakeOrderCmd);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
Assert.True(result);
|
Assert.True(result);
|
||||||
@ -55,6 +62,10 @@ namespace UnitTest.Ordering.Application
|
|||||||
public async Task Handle_return_false_if_order_is_not_persisted()
|
public async Task Handle_return_false_if_order_is_not_persisted()
|
||||||
{
|
{
|
||||||
var buyerId = "1234";
|
var buyerId = "1234";
|
||||||
|
|
||||||
|
var fakeOrderCmd = FakeOrderRequestWithBuyer(new Dictionary<string, object>
|
||||||
|
{ ["cardExpiration"] = DateTime.Now.AddYears(1) });
|
||||||
|
|
||||||
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(buyerId))
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(buyerId))
|
||||||
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
||||||
|
|
||||||
@ -68,12 +79,148 @@ namespace UnitTest.Ordering.Application
|
|||||||
|
|
||||||
//Act
|
//Act
|
||||||
var handler = new CreateOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object, _identityServiceMock.Object);
|
var handler = new CreateOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object, _identityServiceMock.Object);
|
||||||
var result = await handler.Handle(FakeOrderRequestWithBuyer());
|
var result = await handler.Handle(fakeOrderCmd);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
Assert.False(result);
|
Assert.False(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Handle_throws_exception_when_order_expired()
|
||||||
|
{
|
||||||
|
|
||||||
|
var buyerId = "1234";
|
||||||
|
|
||||||
|
var fakeOrderCmd = FakeOrderRequestWithBuyer(new Dictionary<string, object>
|
||||||
|
{ ["cardExpiration"] = DateTime.Now.AddYears(-1) });
|
||||||
|
|
||||||
|
// Arrange
|
||||||
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(buyerId))
|
||||||
|
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
||||||
|
|
||||||
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
||||||
|
.Returns(Task.FromResult(1));
|
||||||
|
|
||||||
|
_orderRepositoryMock.Setup(or => or.Add(FakeOrder()))
|
||||||
|
.Returns(FakeOrder());
|
||||||
|
|
||||||
|
_orderRepositoryMock.Setup(or => or.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
||||||
|
.Returns(Task.FromResult(1));
|
||||||
|
|
||||||
|
_identityServiceMock.Setup(svc => svc.GetUserIdentity()).Returns(buyerId);
|
||||||
|
//Act
|
||||||
|
var handler = new CreateOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object, _identityServiceMock.Object);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
await Assert.ThrowsAsync<ArgumentException>(async () => await handler.Handle(fakeOrderCmd));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Handle_throws_exception_when_no_holdername()
|
||||||
|
{
|
||||||
|
|
||||||
|
var buyerId = "1234";
|
||||||
|
|
||||||
|
var fakeOrderCmd = FakeOrderRequestWithBuyer(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["cardExpiration"] = DateTime.Now.AddYears(1),
|
||||||
|
["cardHolderName"] = string.Empty,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Arrange
|
||||||
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(buyerId))
|
||||||
|
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
||||||
|
|
||||||
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
||||||
|
.Returns(Task.FromResult(1));
|
||||||
|
|
||||||
|
_orderRepositoryMock.Setup(or => or.Add(FakeOrder()))
|
||||||
|
.Returns(FakeOrder());
|
||||||
|
|
||||||
|
_orderRepositoryMock.Setup(or => or.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
||||||
|
.Returns(Task.FromResult(1));
|
||||||
|
|
||||||
|
_identityServiceMock.Setup(svc => svc.GetUserIdentity()).Returns(buyerId);
|
||||||
|
//Act
|
||||||
|
var handler = new CreateOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object, _identityServiceMock.Object);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
await Assert.ThrowsAsync<ArgumentException>(async () => await handler.Handle(fakeOrderCmd));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Handle_throws_exception_when_no_securityNumber()
|
||||||
|
{
|
||||||
|
|
||||||
|
var buyerId = "1234";
|
||||||
|
|
||||||
|
var fakeOrderCmd = FakeOrderRequestWithBuyer(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["cardExpiration"] = DateTime.Now.AddYears(1),
|
||||||
|
["cardSecurityNumber"] = string.Empty,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Arrange
|
||||||
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(buyerId))
|
||||||
|
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
||||||
|
|
||||||
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
||||||
|
.Returns(Task.FromResult(1));
|
||||||
|
|
||||||
|
_orderRepositoryMock.Setup(or => or.Add(FakeOrder()))
|
||||||
|
.Returns(FakeOrder());
|
||||||
|
|
||||||
|
_orderRepositoryMock.Setup(or => or.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
||||||
|
.Returns(Task.FromResult(1));
|
||||||
|
|
||||||
|
_identityServiceMock.Setup(svc => svc.GetUserIdentity()).Returns(buyerId);
|
||||||
|
//Act
|
||||||
|
var handler = new CreateOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object, _identityServiceMock.Object);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
await Assert.ThrowsAsync<ArgumentException>(async () => await handler.Handle(fakeOrderCmd));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Handle_throws_exception_when_no_cardNumber()
|
||||||
|
{
|
||||||
|
|
||||||
|
var buyerId = "1234";
|
||||||
|
|
||||||
|
var fakeOrderCmd = FakeOrderRequestWithBuyer(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["cardExpiration"] = DateTime.Now.AddYears(1),
|
||||||
|
["cardNumber"] = string.Empty,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Arrange
|
||||||
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(buyerId))
|
||||||
|
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
||||||
|
|
||||||
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
||||||
|
.Returns(Task.FromResult(1));
|
||||||
|
|
||||||
|
_orderRepositoryMock.Setup(or => or.Add(FakeOrder()))
|
||||||
|
.Returns(FakeOrder());
|
||||||
|
|
||||||
|
_orderRepositoryMock.Setup(or => or.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
||||||
|
.Returns(Task.FromResult(1));
|
||||||
|
|
||||||
|
_identityServiceMock.Setup(svc => svc.GetUserIdentity()).Returns(buyerId);
|
||||||
|
//Act
|
||||||
|
var handler = new CreateOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object, _identityServiceMock.Object);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
await Assert.ThrowsAsync<ArgumentException>(async () => await handler.Handle(fakeOrderCmd));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Handle_throws_exception_when_no_buyerId()
|
||||||
|
{
|
||||||
|
//Assert
|
||||||
|
Assert.Throws<ArgumentNullException>(() => new Buyer(string.Empty));
|
||||||
|
}
|
||||||
|
|
||||||
private Buyer FakeBuyer()
|
private Buyer FakeBuyer()
|
||||||
{
|
{
|
||||||
return new Buyer(Guid.NewGuid().ToString());
|
return new Buyer(Guid.NewGuid().ToString());
|
||||||
@ -84,19 +231,19 @@ namespace UnitTest.Ordering.Application
|
|||||||
return new Order(1, 1, new Address("street", "city", "state", "country", "zipcode"));
|
return new Order(1, 1, new Address("street", "city", "state", "country", "zipcode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private CreateOrderCommand FakeOrderRequestWithBuyer()
|
private CreateOrderCommand FakeOrderRequestWithBuyer(Dictionary<string, object> args = null)
|
||||||
{
|
{
|
||||||
return new CreateOrderCommand(
|
return new CreateOrderCommand(
|
||||||
city: null,
|
city: args != null && args.ContainsKey("city") ? (string)args["city"] : null,
|
||||||
street: null,
|
street: args != null && args.ContainsKey("street") ? (string)args["street"] : null,
|
||||||
state: null,
|
state: args != null && args.ContainsKey("state") ? (string)args["state"] : null,
|
||||||
country: null,
|
country: args != null && args.ContainsKey("country") ? (string)args["country"] : null,
|
||||||
zipcode: null,
|
zipcode: args != null && args.ContainsKey("zipcode") ? (string)args["zipcode"] : null,
|
||||||
cardNumber: "1234",
|
cardNumber: args != null && args.ContainsKey("cardNumber") ? (string)args["cardNumber"] : "1234",
|
||||||
cardExpiration: DateTime.Now.AddYears(1),
|
cardExpiration: args != null && args.ContainsKey("cardExpiration") ? (DateTime)args["cardExpiration"] : DateTime.MinValue,
|
||||||
cardSecurityNumber: "123",
|
cardSecurityNumber: args != null && args.ContainsKey("cardSecurityNumber") ? (string)args["cardSecurityNumber"] : "123",
|
||||||
cardHolderName: "XXX",
|
cardHolderName: args != null && args.ContainsKey("cardHolderName") ? (string)args["cardHolderName"] : "XXX",
|
||||||
cardTypeId: 0);
|
cardTypeId: args != null && args.ContainsKey("cardTypeId") ? (int)args["cardTypeId"] : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
106
test/Services/UnitTest/Ordering/Domain/BuyerAggregateTest.cs
Normal file
106
test/Services/UnitTest/Ordering/Domain/BuyerAggregateTest.cs
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
public class BuyerAggregateTest
|
||||||
|
{
|
||||||
|
public BuyerAggregateTest()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Create_buyer_item_success()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var identity = new Guid().ToString();
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var fakeBuyerItem = new Buyer(identity);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.NotNull(fakeBuyerItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Create_buyer_item_fail()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var identity = string.Empty;
|
||||||
|
|
||||||
|
//Act - Assert
|
||||||
|
Assert.Throws<ArgumentNullException>(() => new Buyer(identity));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void add_payment_success()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var cardTypeId = 1;
|
||||||
|
var alias = "fakeAlias";
|
||||||
|
var cardNumber = "124";
|
||||||
|
var securityNumber = "1234";
|
||||||
|
var cardHolderName = "FakeHolderNAme";
|
||||||
|
var expiration = DateTime.Now.AddYears(1);
|
||||||
|
var identity = new Guid().ToString();
|
||||||
|
var fakeBuyerItem = new Buyer(identity);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var result = fakeBuyerItem.AddPaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void create_payment_method_success()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var cardTypeId = 1;
|
||||||
|
var alias = "fakeAlias";
|
||||||
|
var cardNumber = "124";
|
||||||
|
var securityNumber = "1234";
|
||||||
|
var cardHolderName = "FakeHolderNAme";
|
||||||
|
var expiration = DateTime.Now.AddYears(1);
|
||||||
|
var fakePaymentMethod = new PaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var result = new PaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void create_payment_method_expiration_fail()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var cardTypeId = 1;
|
||||||
|
var alias = "fakeAlias";
|
||||||
|
var cardNumber = "124";
|
||||||
|
var securityNumber = "1234";
|
||||||
|
var cardHolderName = "FakeHolderNAme";
|
||||||
|
var expiration = DateTime.Now.AddYears(-1);
|
||||||
|
|
||||||
|
//Act - Assert
|
||||||
|
Assert.Throws<ArgumentException>(() => new PaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void payment_method_isEqualTo()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var cardTypeId = 1;
|
||||||
|
var alias = "fakeAlias";
|
||||||
|
var cardNumber = "124";
|
||||||
|
var securityNumber = "1234";
|
||||||
|
var cardHolderName = "FakeHolderNAme";
|
||||||
|
var expiration = DateTime.Now.AddYears(1);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var fakePaymentMethod = new PaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration);
|
||||||
|
var result = fakePaymentMethod.IsEqualTo(cardTypeId, cardNumber, expiration);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
}
|
93
test/Services/UnitTest/Ordering/Domain/OrderAggregateTest.cs
Normal file
93
test/Services/UnitTest/Ordering/Domain/OrderAggregateTest.cs
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
public class OrderAggregateTest
|
||||||
|
{
|
||||||
|
public OrderAggregateTest()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Create_order_item_success()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var productId = 1;
|
||||||
|
var productName = "FakeProductName";
|
||||||
|
var unitPrice = 12;
|
||||||
|
var discount = 15;
|
||||||
|
var pictureUrl = "FakeUrl";
|
||||||
|
var units = 5;
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.NotNull(fakeOrderItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Invalid_number_of_units()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var productId = 1;
|
||||||
|
var productName = "FakeProductName";
|
||||||
|
var unitPrice = 12;
|
||||||
|
var discount = 15;
|
||||||
|
var pictureUrl = "FakeUrl";
|
||||||
|
var units = -1;
|
||||||
|
|
||||||
|
//Act - Assert
|
||||||
|
Assert.Throws<ArgumentNullException>(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Invalid_total_of_order_item_lower_than_discount_applied()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var productId = 1;
|
||||||
|
var productName = "FakeProductName";
|
||||||
|
var unitPrice = 12;
|
||||||
|
var discount = 15;
|
||||||
|
var pictureUrl = "FakeUrl";
|
||||||
|
var units = 1;
|
||||||
|
|
||||||
|
//Act - Assert
|
||||||
|
Assert.Throws<ArgumentException>(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Invalid_discount_setting()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var productId = 1;
|
||||||
|
var productName = "FakeProductName";
|
||||||
|
var unitPrice = 12;
|
||||||
|
var discount = 15;
|
||||||
|
var pictureUrl = "FakeUrl";
|
||||||
|
var units = 5;
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.Throws<ArgumentException>(() => fakeOrderItem.SetNewDiscount(-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Invalid_units_setting()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var productId = 1;
|
||||||
|
var productName = "FakeProductName";
|
||||||
|
var unitPrice = 12;
|
||||||
|
var discount = 15;
|
||||||
|
var pictureUrl = "FakeUrl";
|
||||||
|
var units = 5;
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.Throws<ArgumentException>(() => fakeOrderItem.AddUnits(-1));
|
||||||
|
}
|
||||||
|
}
|
@ -13,12 +13,14 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\..\src\Services\Catalog\Catalog.API\Catalog.API.csproj" />
|
||||||
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.API\Ordering.API.csproj" />
|
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.API\Ordering.API.csproj" />
|
||||||
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.Infrastructure\Ordering.Infrastructure.csproj" />
|
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.Infrastructure\Ordering.Infrastructure.csproj" />
|
||||||
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.Domain\Ordering.Domain.csproj" />
|
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.Domain\Ordering.Domain.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
|
||||||
<PackageReference Include="MediatR" Version="2.1.0" />
|
<PackageReference Include="MediatR" Version="2.1.0" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user