Skip to content

Commit

Permalink
ShouldThrowValidationExceptionIfFlexiMessageIsNull -> FAIL
Browse files Browse the repository at this point in the history
  • Loading branch information
mabroukmahdhi committed Aug 11, 2024
1 parent fba09f6 commit e1a5ad0
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
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);
}
}
}
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)
{
}
}
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)
{
}
}

0 comments on commit e1a5ad0

Please sign in to comment.