Skip to content

Commit

Permalink
ShouldSendAndSaveCopyBasedOnAddressTypeAsync -> PASS
Browse files Browse the repository at this point in the history
  • Loading branch information
mabroukmahdhi committed Aug 11, 2024
1 parent bd9eb09 commit 6336e6f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
25 changes: 21 additions & 4 deletions FlexiMail.Tests.Unit/Services/FlexiExchangeServiceTests.Logics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,31 @@ public async void ShouldSendAndSaveCopyAsync()
Times.Once);
}

[Fact]
public async void ShouldSendAndSaveCopyIfOnlyToAddressAddedAsync()
[Theory]
[InlineData(true, false, false)] // Only To address is added
[InlineData(false, true, false)] // Only Cc address is added
[InlineData(false, false, true)] // Only Bcc address is added
public async void ShouldSendAndSaveCopyBasedOnAddressTypeAsync(bool hasTo, bool hasCc, bool hasBcc)
{
// given
var randomAccessToken = GetRandomString();
var randomMessage = CreateRandomFlexiMessage();
randomMessage.Bcc = null;
randomMessage.Cc = null;

if (!hasTo)
{
randomMessage.To = null;
}

if (!hasCc)
{
randomMessage.Cc = null;
}

if (!hasBcc)
{
randomMessage.Bcc = null;
}

var randomExchangeService = CreateExchangeService();

this.exchangeBrokerMock.Setup(broker =>
Expand Down
3 changes: 3 additions & 0 deletions FlexiMail.Tests.Unit/Services/FlexiExchangeServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Made with love for the .NET Community
// ---------------------------------------

using System.Collections.Generic;
using FlexiMail.Brokers.Exchanges;
using FlexiMail.Models.Configurations;
using FlexiMail.Models.Foundations.Messages;
Expand Down Expand Up @@ -68,5 +69,7 @@ private static ExchangeService CreateExchangeService()
{
return new ExchangeService();
}

private static List<string> GetEmptyList() => [];
}
}
13 changes: 10 additions & 3 deletions FlexiMail/Services/FlexiExchangeService.Validations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Made with love for the .NET Community
// ---------------------------------------

using System.Formats.Tar;
using System.Linq;
using FlexiMail.Models.Foundations.Messages;
using FlexiMail.Models.Foundations.Messages.Exceptions;

Expand All @@ -14,9 +16,14 @@ private static void ValidFlexiMessage(FlexiMessage flexiMessage)
{
ValidFlexiMessageIsNotNull(flexiMessage);

Validate((Rule: IsInvalid(flexiMessage.To), Parameter: nameof(FlexiMessage.To)));
Validate((Rule: IsInvalid(flexiMessage.Cc), Parameter: nameof(FlexiMessage.Cc)));
Validate((Rule: IsInvalid(flexiMessage.Bcc), Parameter: nameof(FlexiMessage.Bcc)));
if ((flexiMessage.To?.Count ?? 0) > 0
|| (flexiMessage.Cc?.Count ?? 0) > 0
|| (flexiMessage.Bcc?.Count ?? 0) > 0)
return;

Validate((Rule: IsInvalid(flexiMessage.To), Parameter: nameof(FlexiMessage.To)),
(Rule: IsInvalid(flexiMessage.Cc), Parameter: nameof(FlexiMessage.Cc)),
(Rule: IsInvalid(flexiMessage.Bcc), Parameter: nameof(FlexiMessage.Bcc)));
}

private static void ValidFlexiMessageIsNotNull(FlexiMessage flexiMessage)
Expand Down

0 comments on commit 6336e6f

Please sign in to comment.