-
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.
- Loading branch information
John Miller
committed
Aug 21, 2024
1 parent
9cd30e5
commit 7fb757d
Showing
19 changed files
with
58 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
using MediatR; | ||
using Microservice.Customer.Api.Data.Repository.Interfaces; | ||
using Microservice.Customer.Api.Helpers; | ||
using Microservice.Customer.Api.Helpers.Exceptions; | ||
using Microservice.Customer.Api.Helpers.Interfaces; | ||
using Microservice.Customer.Api.MediatR.AddCustomer; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
@@ -14,9 +13,9 @@ namespace Microservice.Customer.Api.Test.Unit; | |
[TestFixture] | ||
public class UpdateCustomerMediatrTests | ||
{ | ||
private Mock<ICustomerRepository> customerRepositoryMock = new Mock<ICustomerRepository>(); | ||
private Mock<ICustomerHttpAccessor> customerHttpAccessorMock = new Mock<ICustomerHttpAccessor>(); | ||
private ServiceCollection services = new ServiceCollection(); | ||
private Mock<ICustomerRepository> customerRepositoryMock = new(); | ||
private Mock<ICustomerHttpAccessor> customerHttpAccessorMock = new(); | ||
private ServiceCollection services = new(); | ||
private ServiceProvider serviceProvider; | ||
private IMediator mediator; | ||
private Guid customerId; | ||
|
@@ -32,7 +31,7 @@ public void OneTimeSetup() | |
services.AddAutoMapper(Assembly.GetAssembly(typeof(UpdateCustomerMapper))); | ||
|
||
serviceProvider = services.BuildServiceProvider(); | ||
mediator = serviceProvider.GetRequiredService<IMediator>(); | ||
mediator = serviceProvider.GetRequiredService<IMediator>(); | ||
} | ||
|
||
[OneTimeTearDown] | ||
|
@@ -75,7 +74,7 @@ public async Task Customer_updated_return_success_message() | |
customer.Email = "Changed Email"; | ||
|
||
customerRepositoryMock | ||
.Setup(x => x.UpdateAsync(customer)); | ||
.Setup(x => x.UpdateAsync(customer)); | ||
|
||
var updateCustomerRequest = new UpdateCustomerRequest(customerId, "[email protected]", "TestSurname", "TestFirstName"); | ||
|
||
|
@@ -93,14 +92,14 @@ public void Customer_not_updated_id_does_not_exists_return_exception_fail_messag | |
.Returns(Task.FromResult(false)); | ||
|
||
var updateCustomerRequest = new UpdateCustomerRequest(customerId, "[email protected]", "TestSurname", "TestFirstName"); | ||
|
||
var validationException = Assert.ThrowsAsync<ValidationException>(async () => | ||
{ | ||
await mediator.Send(updateCustomerRequest); | ||
}); | ||
|
||
Assert.That(validationException.Errors.Count, Is.EqualTo(1)); | ||
Assert.That(validationException.Errors.ElementAt(0).ErrorMessage, Is.EqualTo("The customer does not exists.")); | ||
Assert.That(validationException.Errors.ElementAt(0).ErrorMessage, Is.EqualTo("The customer does not exists.")); | ||
} | ||
|
||
[Test] | ||
|
@@ -116,9 +115,9 @@ public void Customer_not_updated_email_exists_return_exception_fail_message() | |
{ | ||
await mediator.Send(updateCustomerRequest); | ||
}); | ||
Assert.That(validationException .Errors.Count, Is.EqualTo(1)); | ||
Assert.That(validationException.Errors.ElementAt(0).ErrorMessage, Is.EqualTo("Customer with this email already exists")); | ||
|
||
Assert.That(validationException.Errors.Count, Is.EqualTo(1)); | ||
Assert.That(validationException.Errors.ElementAt(0).ErrorMessage, Is.EqualTo("Customer with this email already exists")); | ||
} | ||
|
||
[Test] | ||
|
@@ -160,7 +159,7 @@ public void Customer_not_updated_invalid_surname_firstname_return_exception_fail | |
|
||
[Test] | ||
public void Customer_not_updated_no_email_surname_firstname_return_exception_fail_message() | ||
{ | ||
{ | ||
customerRepositoryMock | ||
.Setup(x => x.ExistsAsync("[email protected]")) | ||
.Returns(Task.FromResult(false)); | ||
|
@@ -175,10 +174,10 @@ public void Customer_not_updated_no_email_surname_firstname_return_exception_fai | |
Assert.That(validationException.Errors.Count, Is.EqualTo(7)); | ||
Assert.That(validationException.Errors.ElementAt(0).ErrorMessage, Is.EqualTo("Email is required.")); | ||
Assert.That(validationException.Errors.ElementAt(1).ErrorMessage, Is.EqualTo("Email length between 8 and 150.")); | ||
Assert.That(validationException.Errors.ElementAt(2).ErrorMessage, Is.EqualTo("Invalid Email.")); | ||
Assert.That(validationException.Errors.ElementAt(2).ErrorMessage, Is.EqualTo("Invalid Email.")); | ||
Assert.That(validationException.Errors.ElementAt(3).ErrorMessage, Is.EqualTo("Surname is required.")); | ||
Assert.That(validationException.Errors.ElementAt(4).ErrorMessage, Is.EqualTo("Surname length between 1 and 30.")); | ||
Assert.That(validationException.Errors.ElementAt(5).ErrorMessage, Is.EqualTo("First name is required.")); | ||
Assert.That(validationException.Errors.ElementAt(6).ErrorMessage, Is.EqualTo("First name length between 1 and 30.")); | ||
} | ||
} | ||
} |
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
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
2 changes: 1 addition & 1 deletion
2
Microservice.Customer.Api/Mediatr/GetCustomer/GetCustomerResponse.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,3 +1,3 @@ | ||
namespace Microservice.Customer.Api.MediatR.GetCustomer; | ||
|
||
public record GetCustomerResponse(string Email, string Surname, string FirstName); |
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
2 changes: 1 addition & 1 deletion
2
Microservice.Customer.Api/Middleware/ExceptionHandlingMiddleware.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
3 changes: 1 addition & 2 deletions
3
Microservice.Customer.Api/Migrations/20240727104340_create-table-default-data.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
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