Skip to content

Commit

Permalink
Merge pull request #59 from The-Standard-Organization/users/cjdutoit/…
Browse files Browse the repository at this point in the history
…foudations-xeptionaggregate-rework

FOUNDATIONS:  Xeption - Aggregate support for SameExceptionAs
  • Loading branch information
hassanhabib authored Jul 25, 2024
2 parents 15d0c8f + 95ecf35 commit cd002ef
Show file tree
Hide file tree
Showing 8 changed files with 2,150 additions and 452 deletions.
834 changes: 729 additions & 105 deletions Xeption.Tests/XeptionAssertionTests.Logic.BeEquivalentTo.cs

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions Xeption.Tests/XeptionAssertionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,5 @@ private static KeyValuePair<string, List<string>> GenerateKeyValuePair(int count

return keyValuePair;
}

internal class OtherTarget
{
public static void ThrowingExceptionMethod() =>
throw new Exception();
}
}
}
1,173 changes: 1,173 additions & 0 deletions Xeption.Tests/XeptionExtensionTests.Logic.SameExceptionAs.cs

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions Xeption.Tests/XeptionExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using Tynamix.ObjectFiller;

namespace Xeptions.Tests
Expand All @@ -12,6 +14,24 @@ public partial class XeptionExtensionTests
private static string GetRandomString() =>
new MnemonicString().GetValue();

private static KeyValuePair<string, List<string>> GenerateKeyValuePair(int count, string keyName = "")
{
if (String.IsNullOrWhiteSpace(keyName))
{
keyName = GetRandomString();
}

List<string> values = Enumerable.Range(start: 0, count)
.Select(_ => GetRandomString())
.ToList();

var keyValuePair = new KeyValuePair<string, List<string>>(
key: keyName,
value: values);

return keyValuePair;
}

internal class OtherTarget
{
public static void ThrowingExceptionMethod() =>
Expand Down
32 changes: 16 additions & 16 deletions Xeption.Tests/XeptionTests.Logic.DataEqualsWithMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void ShouldReturnTrueAndNullStringIfDataMatchInCount()
}

[Fact]
public void ShouldReturnFalsAndMessageStringIfActualDataContainsKeysNotInExpectedData()
public void ShouldReturnFalseAndMessageStringIfActualDataContainsKeysNotInExpectedData()
{
// given
Xeption randomXeption = new Xeption();
Expand All @@ -49,21 +49,21 @@ public void ShouldReturnFalsAndMessageStringIfActualDataContainsKeysNotInExpecte
actualXeption.UpsertDataList(randomKey, randomValue);

var expectedMessage = new StringBuilder();
expectedMessage.AppendLine($"Expected data to: ");
expectedMessage.AppendLine($"Expected exception to:");

expectedMessage.AppendLine(
$"- have a count of {expectedXeption.Data.Count}, " +
$"but found {actualXeption.Data.Count}.");
$"- have a data count of {expectedXeption.Data.Count}, " +
$"but found {actualXeption.Data.Count}");

expectedMessage.AppendLine($"- NOT contain key '{randomKey}'.");
expectedMessage.AppendLine($"- NOT contain key \"{randomKey}\"");

// when
(bool isEqual, string message) = actualXeption.DataEqualsWithDetail(expectedXeption.Data);

// then
isEqual.Should().BeFalse();
message.Should().NotBeNullOrEmpty();
message.Should().BeEquivalentTo(expectedMessage.ToString());
message.Should().BeEquivalentTo(expectedMessage.ToString().Trim());
}

[Fact]
Expand All @@ -83,14 +83,14 @@ public void ShouldReturnFalseAndMessageStringIfExpectedDataContainsKeysNotInActu
expectedXeption.UpsertDataList(randomKey, randomValue);

var expectedMessage = new StringBuilder();
expectedMessage.AppendLine($"Expected data to: ");
expectedMessage.AppendLine($"Expected exception to:");

expectedMessage.AppendLine(
$"- have a count of {expectedXeption.Data.Count}, " +
$"but found {actualXeption.Data.Count}.");
$"- have a data count of {expectedXeption.Data.Count}, " +
$"but found {actualXeption.Data.Count}");

expectedMessage.AppendLine(
$"- contain key '{randomKey}' with value(s) [{randomValue}].");
$"- contain key \"{randomKey}\" with value(s) ['{randomValue}']");

// when
(bool isEqual, string message) = actualXeption
Expand All @@ -99,11 +99,11 @@ public void ShouldReturnFalseAndMessageStringIfExpectedDataContainsKeysNotInActu
// then
isEqual.Should().BeFalse();
message.Should().NotBeNullOrEmpty();
message.Should().BeEquivalentTo(expectedMessage.ToString());
message.Should().BeEquivalentTo(expectedMessage.ToString().Trim('\r', '\n'));
}

[Fact]
public void ShouldReturnFalseAndMessageStringIfExpectedDataContainsKeysMatchingKeysWithUnmatchedValues()
public void ShouldReturnFalseAndMessageStringIfExpectedDataContainsKeysWithUnmatchedValues()
{
// given
Xeption randomXeption = new Xeption();
Expand All @@ -127,11 +127,11 @@ public void ShouldReturnFalseAndMessageStringIfExpectedDataContainsKeysMatchingK
.Select(value => value).Aggregate((t1, t2) => t1 + "','" + t2);

var expectedMessage = new StringBuilder();
expectedMessage.AppendLine($"Expected data to: ");
expectedMessage.AppendLine($"Expected exception to:");

expectedMessage.AppendLine(
$"- have key '{randomKey}' with value(s) ['{expectedValues}'], " +
$"but found value(s) ['{actualValues}'].");
$"- have key \"{randomKey}\" with value(s) ['{expectedValues}'], " +
$"but found value(s) ['{actualValues}']");

// when
(bool isEqual, string message) = actualXeption
Expand All @@ -140,7 +140,7 @@ public void ShouldReturnFalseAndMessageStringIfExpectedDataContainsKeysMatchingK
// then
isEqual.Should().BeFalse();
message.Should().NotBeNullOrEmpty();
message.Should().BeEquivalentTo(expectedMessage.ToString());
message.Should().BeEquivalentTo(expectedMessage.ToString().Trim('\r', '\n'));
}
}
}
Loading

0 comments on commit cd002ef

Please sign in to comment.