Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat (MessageRelay/UI): Add indicator to UI when message has been relayed successfully. (#774) + Relay recipients added to table MessageRelay * task: test for relay controller action. * swap Smtp4devServer usage with interface. Smtp4devServer -> Stop, DeleteSession, DeleteSessions access modified to public to expose on interface.
- Loading branch information
Showing
25 changed files
with
1,102 additions
and
612 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc; | ||
using MimeKit; | ||
using NSubstitute; | ||
using Rnwood.Smtp4dev.ApiModel; | ||
using Rnwood.Smtp4dev.Controllers; | ||
using Rnwood.Smtp4dev.Data; | ||
using Rnwood.Smtp4dev.Server; | ||
using Rnwood.Smtp4dev.Tests.DBMigrations.Helpers; | ||
using Xunit; | ||
using Message = Rnwood.Smtp4dev.DbModel.Message; | ||
|
||
namespace Rnwood.Smtp4dev.Tests.Controllers | ||
{ | ||
public class MessagesControllerTests : IDisposable | ||
{ | ||
private readonly MessagesController controller; | ||
private readonly IMessagesRepository messagesRepository; | ||
private readonly ISmtp4devServer server; | ||
private readonly Smtp4devDbContext context; | ||
|
||
public MessagesControllerTests() | ||
{ | ||
messagesRepository = Substitute.For<IMessagesRepository>(); | ||
server = Substitute.For<ISmtp4devServer>(); | ||
controller = new MessagesController(messagesRepository, server); | ||
var sqlLiteForTesting = new SqliteInMemory(); | ||
context = new Smtp4devDbContext(sqlLiteForTesting.ContextOptions); | ||
InitRepo(); | ||
messagesRepository.GetMessages(Arg.Any<bool>()) | ||
.Returns(context.Messages); | ||
messagesRepository.DbContext.Returns(context); | ||
} | ||
|
||
[Fact] | ||
public void CanRelayMessageAndPersistResult() | ||
{ | ||
// setup | ||
var messageId = GetData().First().Id; | ||
|
||
server.TryRelayMessage(Arg.Any<DbModel.Message>(), Arg.Any<MailboxAddress[]>()).Returns(new RelayResult(GetData().First()) | ||
{ | ||
RelayRecipients = new List<RelayRecipientResult>() | ||
{ new RelayRecipientResult { Email = "relay@blah.com", RelayDate = DateTime.UtcNow } } | ||
}); | ||
|
||
// act | ||
var result = controller.RelayMessage(messageId, | ||
new MessageRelayOptions() { OverrideRecipientAddresses = new[] { "test@foo.bar" } }); | ||
|
||
// expect ok result | ||
result.Should().BeOfType<OkResult>(); | ||
|
||
var relay = context.MessageRelays.FirstOrDefault(mr => mr.MessageId == messageId); | ||
//expect MessageRelay persisted. | ||
relay.Should().NotBeNull(); | ||
} | ||
|
||
private IEnumerable<Message> GetData() | ||
{ | ||
return new List<Message>() { new Message() { Id = new Guid("7476cf62-03e4-4d58-93ac-1cd143ba8653") } }; | ||
} | ||
|
||
private void InitRepo() | ||
{ | ||
context.Messages.AddRange(GetData()); | ||
context.SaveChanges(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
context?.Dispose(); | ||
} | ||
} | ||
} |
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
50 changes: 28 additions & 22 deletions
50
Rnwood.Smtp4dev/ClientApp/src/ApiClient/MessageSummary.ts
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,24 +1,30 @@ | ||
| ||
export default class MessageSummary { | ||
constructor( | ||
id: string, | ||
from: string, | ||
to: string, | ||
receivedDate: Date, | ||
subject: string, | ||
attachmentCount: number, | ||
isUnread: boolean, | ||
isRelayed: boolean, | ||
) { | ||
this.id = id; | ||
this.from = from; | ||
this.to = to; | ||
this.receivedDate = receivedDate; | ||
this.subject = subject; | ||
this.attachmentCount = attachmentCount; | ||
this.isUnread = isUnread; | ||
this.isRelayed = isRelayed; | ||
} | ||
|
||
export default class MessageSummary { | ||
|
||
constructor(id: string, from: string, to: string, receivedDate: Date, subject: string, attachmentCount: number, isUnread: boolean, ) { | ||
|
||
this.id = id; | ||
this.from = from; | ||
this.to = to; | ||
this.receivedDate = receivedDate; | ||
this.subject = subject; | ||
this.attachmentCount = attachmentCount; | ||
this.isUnread = isUnread; | ||
} | ||
|
||
|
||
id: string; | ||
from: string; | ||
to: string; | ||
receivedDate: Date; | ||
subject: string; | ||
attachmentCount: number; | ||
isUnread: boolean; | ||
id: string; | ||
from: string; | ||
to: string; | ||
receivedDate: Date; | ||
subject: string; | ||
attachmentCount: number; | ||
isUnread: boolean; | ||
isRelayed: boolean; | ||
} |
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
Oops, something went wrong.