-
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.
ShouldThrowValidationExceptionIfFlexiMessageIsNull -> FAIL
- Loading branch information
1 parent
fba09f6
commit e1a5ad0
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
FlexiMail.Tests.Unit/Services/FlexiExchangeServiceTests.Validations.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,56 @@ | ||
// --------------------------------------- | ||
// Copyright (c) 2024 Mabrouk Mahdhi. | ||
// Made with love for the .NET Community | ||
// --------------------------------------- | ||
|
||
using System; | ||
using FlexiMail.Models.Foundations.Messages; | ||
using FlexiMail.Models.Foundations.Messages.Exceptions; | ||
using FluentAssertions; | ||
using Microsoft.Exchange.WebServices.Data; | ||
using Moq; | ||
|
||
namespace FlexiMail.Tests.Unit.Services | ||
{ | ||
public partial class FlexiExchangeServiceTests | ||
{ | ||
[Fact] | ||
public void ShouldThrowValidationExceptionIfFlexiMessageIsNull() | ||
{ | ||
// given | ||
FlexiMessage nullMessage = null; | ||
|
||
var nullFlexiMessageException = | ||
new NullFlexiMessageException( | ||
message: "FlexiMessage is null."); | ||
|
||
var expectedFlexiMessageValidationException = | ||
new FlexiMessageValidationException( | ||
message: "Flexi Message validation error occurred, fix errors and try again.", | ||
innerException: nullFlexiMessageException); | ||
|
||
// when | ||
void SendMessageAction() => this.flexiExchangeService.SendAndSaveCopyAsync(nullMessage); | ||
|
||
var actualException = Assert.Throws<FlexiMessageValidationException>((Action)SendMessageAction); | ||
// then | ||
|
||
actualException.Should().BeEquivalentTo(expectedFlexiMessageValidationException); | ||
|
||
this.exchangeBrokerMock.Verify(broker => | ||
broker.GetAccessTokenAsync(), | ||
Times.Never); | ||
|
||
this.exchangeBrokerMock.Verify(broker => | ||
broker.CreateExchangeService( | ||
ExchangeVersion.Exchange2013, | ||
It.IsAny<string>(), | ||
It.IsAny<ImpersonatedUserId>()), | ||
Times.Never); | ||
|
||
this.exchangeBrokerMock.Verify(broker => | ||
broker.SendAndSaveCopy(It.IsAny<EmailMessage>()), | ||
Times.Never); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
FlexiMail/Models/Foundations/Messages/Exceptions/FlexiMessageValidationException.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 @@ | ||
// --------------------------------------- | ||
// Copyright (c) 2024 Mabrouk Mahdhi. | ||
// Made with love for the .NET Community | ||
// --------------------------------------- | ||
|
||
using System; | ||
|
||
namespace FlexiMail.Models.Foundations.Messages.Exceptions | ||
{ | ||
public class FlexiMessageValidationException(string message, Exception innerException) | ||
: Exception(message, innerException) | ||
{ | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
FlexiMail/Models/Foundations/Messages/Exceptions/NullFlexiMessageException.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,13 @@ | ||
// --------------------------------------- | ||
// Copyright (c) 2024 Mabrouk Mahdhi. | ||
// Made with love for the .NET Community | ||
// --------------------------------------- | ||
|
||
using System; | ||
|
||
namespace FlexiMail.Models.Foundations.Messages.Exceptions | ||
{ | ||
public class NullFlexiMessageException(string message) : Exception(message) | ||
{ | ||
} | ||
} |