-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#130 Added Mail Message REST API Controller
- Loading branch information
1 parent
ba0531d
commit 1845ade
Showing
10 changed files
with
187 additions
and
2 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
11 changes: 11 additions & 0 deletions
11
...istant.Blazor/Server/WebAPI/v1/MailModule/MailMessageController.MailMessageResponseDto.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using AdminAssistant.DomainModel.Modules.MailModule; | ||
using AdminAssistant.Framework.TypeMapping; | ||
|
||
namespace AdminAssistant.WebAPI.v1.MailModule | ||
{ | ||
public class MailMessageResponseDto : IMapFrom<MailMessage> | ||
{ | ||
public int MailMessageID { get; set; } | ||
public string Subject { get; set; } = string.Empty; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/AdminAssistant.Blazor/Server/WebAPI/v1/MailModule/MailMessageController.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using AdminAssistant.DomainModel.Modules.MailModule.CQRS; | ||
using AdminAssistant.Infra.Providers; | ||
using AutoMapper; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Swashbuckle.AspNetCore.Annotations; | ||
|
||
namespace AdminAssistant.WebAPI.v1.MailModule | ||
{ | ||
[ApiController] | ||
[Route("api/v1/core/[controller]")] | ||
[ApiExplorerSettings(GroupName = "MailMessage Register - MailMessage")] | ||
public class MailMessageController : WebAPIControllerBase | ||
{ | ||
public MailMessageController(IMapper mapper, IMediator mediator, ILoggingProvider loggingProvider) | ||
: base(mapper, mediator, loggingProvider) | ||
{ | ||
} | ||
|
||
[HttpGet] | ||
[SwaggerOperation("Lists all mail messages", OperationId = "GetMailMessage")] | ||
[SwaggerResponse(StatusCodes.Status200OK, "Ok - returns a list of MailMessageResponseDto", type: typeof(IEnumerable<MailMessageResponseDto>))] | ||
public async Task<ActionResult<IEnumerable<MailMessageResponseDto>>> GetMailMessages() | ||
{ | ||
Log.Start(); | ||
|
||
var result = await Mediator.Send(new MailMessageQuery()).ConfigureAwait(false); | ||
var response = Mapper.Map<IEnumerable<MailMessageResponseDto>>(result.Value); | ||
|
||
return Log.Finish(Ok(response)); | ||
} | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
src/AdminAssistant.Test/WebAPI/v1/MailModule/MailMessageController_UnitTest.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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#pragma warning disable CA1707 // Identifiers should not contain underscores | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AdminAssistant.DomainModel; | ||
using AdminAssistant.DomainModel.Modules.MailModule; | ||
using AdminAssistant.DomainModel.Modules.MailModule.CQRS; | ||
using Ardalis.Result; | ||
using AutoMapper; | ||
using FluentAssertions; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace AdminAssistant.WebAPI.v1.MailModule | ||
{ | ||
public class MailMessageController_GetMailMessages | ||
{ | ||
[Fact] | ||
[Trait("Category", "Unit")] | ||
public async Task Returns_Status200OK_With_AListOfMailMessages_Given_NoArguments() | ||
{ | ||
// Arrange | ||
var documents = new List<MailMessage>() | ||
{ | ||
Factory.MailMessage.WithTestData(10).Build(), | ||
Factory.MailMessage.WithTestData(20).Build() | ||
}; | ||
|
||
var services = new ServiceCollection(); | ||
services.AddMockServerSideLogging(); | ||
services.AddAutoMapper(typeof(MappingProfile)); | ||
|
||
var mockMediator = new Mock<IMediator>(); | ||
mockMediator.Setup(x => x.Send(It.IsAny<MailMessageQuery>(), It.IsAny<CancellationToken>())) | ||
.Returns(Task.FromResult(Result<IEnumerable<MailMessage>>.Success(documents))); | ||
|
||
services.AddTransient((sp) => mockMediator.Object); | ||
services.AddTransient<MailMessageController>(); | ||
|
||
// Act | ||
var response = await services.BuildServiceProvider().GetRequiredService<MailMessageController>().GetMailMessages().ConfigureAwait(false); | ||
|
||
// Assert | ||
response.Result.Should().BeOfType<OkObjectResult>(); | ||
response.Value.Should().BeNull(); | ||
|
||
var result = (OkObjectResult)response.Result; | ||
result.Value.Should().BeAssignableTo<IEnumerable<MailMessageResponseDto>>(); | ||
|
||
//var value = ((IEnumerable<CurrencyResponseDto>)result.Value).ToArray(); | ||
//value.Should().HaveCount(currencies.Count); | ||
|
||
//var expected = currencies.ToArray(); | ||
//for (int i = 0; i < expected.Length; i++) | ||
//{ | ||
// value[i].CurrencyID.Should().Be(expected[i].CurrencyID); | ||
// value[i].Symbol.Should().Be(expected[i].Symbol); | ||
// value[i].DecimalFormat.Should().Be(expected[i].DecimalFormat); | ||
//} | ||
} | ||
} | ||
} | ||
#pragma warning restore CA1707 // Identifiers should not contain underscores |
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
28 changes: 28 additions & 0 deletions
28
src/AdminAssistant/DomainModel/Modules/MailModule/Builders/MailMessageBuilder.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace AdminAssistant.DomainModel.Modules.MailModule.Builders | ||
{ | ||
public interface IMailMessageBuilder | ||
{ | ||
MailMessage Build(); | ||
IMailMessageBuilder WithTestData(int assetID = Constants.UnknownRecordID); | ||
IMailMessageBuilder WithSubject(string subject); | ||
} | ||
internal class MailMessageBuilder : MailMessage, IMailMessageBuilder | ||
{ | ||
public static MailMessage Default(IMailMessageBuilder builder) => builder.Build(); | ||
public static MailMessage Default(MailMessageBuilder builder) => builder.Build(); | ||
|
||
public MailMessage Build() => this; | ||
|
||
public IMailMessageBuilder WithTestData(int assetID = Constants.UnknownRecordID) | ||
{ | ||
MailMessageID = assetID; | ||
Subject = "A mail from the boss"; | ||
return this; | ||
} | ||
public IMailMessageBuilder WithSubject(string subject) | ||
{ | ||
Subject = subject; | ||
return this; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/AdminAssistant/DomainModel/Modules/MailModule/CQRS/MailMessageQuery.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
using Ardalis.Result; | ||
using MediatR; | ||
|
||
namespace AdminAssistant.DomainModel.Modules.MailModule.CQRS | ||
{ | ||
public class MailMessageQuery : IRequest<Result<IEnumerable<MailMessage>>> | ||
{ | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/AdminAssistant/DomainModel/Modules/MailModule/MailMessage.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using AdminAssistant.Infra.DAL; | ||
|
||
namespace AdminAssistant.DomainModel.Modules.MailModule | ||
{ | ||
public class MailMessage : IDatabasePersistable | ||
{ | ||
public const int SubjectNameMaxLength = Constants.DescriptionMaxLength; | ||
|
||
public int MailMessageID { get; set; } | ||
public string Subject { get; set; } = string.Empty; | ||
|
||
public int PrimaryKey => MailMessageID; | ||
} | ||
} |