-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,11 @@ public static CustomerResponse PrivateCustomer(string customerCode) | |
return new CustomerResponse(customerCode, "FirstName", "LastName", "2020-12-12", "123456", null, "PTrusted", "EUR", "NL", "[email protected]", "ACTIVE", "TestBankAccount", false, "Low", new Dictionary<string, string>()); | ||
} | ||
|
||
public static CustomerResponse DeletedPrivateCustomer(string customerCode) | ||
{ | ||
return new CustomerResponse(customerCode, "FirstName", "LastName", "2020-12-12", "123456", null, "PTrusted", "EUR", "NL", "[email protected]", "DELETED", "TestBankAccount", false, "Low", new Dictionary<string, string>()); | ||
} | ||
|
||
public static IDictionary<string, string> AccountQuery(string customerCode) | ||
{ | ||
return new Dictionary<string, string>() | ||
|
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using Nexus.Sdk.Shared.Requests; | ||
using Nexus.Sdk.Shared.Responses; | ||
using Nexus.Sdk.Token; | ||
|
||
namespace Core.InfrastructureTests.Nexus.Repositories | ||
|
@@ -144,6 +145,80 @@ public async Task CreateCustomer_Creating_Throws_ExistsPropertyError_TestAsync() | |
server.Verify(s => s.Customers.Create(It.IsAny<CreateCustomerRequest>(), It.IsAny<string>()), Times.Never); | ||
} | ||
|
||
[TestMethod()] | ||
public async Task CreateCustomer_Creating_Throws_EmailExistsError_TestAsync() | ||
{ | ||
var server = new Mock<ITokenServer>(); | ||
server.Setup(s => s.Customers.Get(It.IsAny<Dictionary<string, string>>())) | ||
.Returns(Task.FromResult(new PagedResponse<CustomerResponse>( | ||
page: 1, | ||
total: 1, | ||
totalPages: 1, | ||
filteringParameters: new Dictionary<string, string>(), | ||
records: [NexusSDKHelper.PrivateCustomer("TestCustomer123")]))); | ||
|
||
var repo = new NexusCustomerRepository(server.Object, DefaultOptions.TokenOptions); | ||
|
||
var customer = new Customer() | ||
{ | ||
CustomerCode = "TestCustomer", | ||
CurrencyCode = string.Empty, | ||
Email = "[email protected]", | ||
IsMerchant = false, | ||
Status = "ACTIVE", | ||
TrustLevel = string.Empty, | ||
BankAccount = string.Empty, | ||
Data = new Dictionary<string, string> | ||
{ | ||
{ "Key1", "Value1"}, | ||
{ "Key2", "Value2"} | ||
} | ||
}; | ||
|
||
var ex = await Assert.ThrowsExceptionAsync<CustomErrorsException>(async () => await repo.CreateAsync(customer)); | ||
|
||
Assert.AreEqual("ExistingProperty", ex.CustomErrors.Errors[0].Code); | ||
Assert.AreEqual("A customer with this email already exists", ex.CustomErrors.Errors[0].Message); | ||
|
||
server.Verify(s => s.Customers.Exists("TestCustomer"), Times.Once()); | ||
server.Verify(s => s.Customers.Create(It.IsAny<CreateCustomerRequest>(), It.IsAny<string>()), Times.Never); | ||
} | ||
|
||
[TestMethod()] | ||
public async Task CreateCustomer_Creating_EmailExists_StatusDeleted_Success_TestAsync() | ||
{ | ||
var server = new Mock<ITokenServer>(); | ||
server.Setup(s => s.Customers.Get(It.IsAny<Dictionary<string, string>>())) | ||
.Returns(Task.FromResult(new PagedResponse<CustomerResponse>( | ||
page: 1, | ||
total: 1, | ||
totalPages: 1, | ||
filteringParameters: new Dictionary<string, string>(), | ||
records: [NexusSDKHelper.DeletedPrivateCustomer("TestCustomer")]))); | ||
|
||
var repo = new NexusCustomerRepository(server.Object, DefaultOptions.TokenOptions); | ||
|
||
var customer = new Customer() | ||
{ | ||
CustomerCode = "TestCustomer123", | ||
CurrencyCode = "EUR", | ||
Email = "[email protected]", | ||
IsMerchant = false, | ||
Status = "ACTIVE", | ||
TrustLevel = "PTrusted", | ||
BankAccount = string.Empty, | ||
Data = new Dictionary<string, string> | ||
{ | ||
{ "FirstName", "Hans"}, | ||
{ "LastName", "Peter"} | ||
} | ||
}; | ||
|
||
await repo.CreateAsync(customer); | ||
|
||
server.Verify(s => s.Customers.Get(It.IsAny<Dictionary<string, string>>()), Times.Once); | ||
} | ||
|
||
public async static Task Get_Returns_Valid_Customer_TestAsync() | ||
{ | ||
var server = new Mock<ITokenServer>(); | ||
|