Skip to content

Commit

Permalink
add successfull assertion extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jheinath committed Jul 30, 2023
1 parent 426f9bd commit 073ebc6
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 22 deletions.
9 changes: 3 additions & 6 deletions Domain.Test/EscapeGames/Aggregate/EscapeGameTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public void Create_ValidInput_CreatesEscapeGameCorrectly()
var result = EscapeGame.Create(culture, new[] { riddle }, new []{ gameSolutionForGroup }, _defaultCreatorPassword);

//Assert
result.IsSuccess.Should().BeTrue();
result.Errors.Should().BeEmpty();
result.Should().BeSuccessfulWithoutErrors();
result.Value.CultureInfo.Should().BeEquivalentTo(new CultureInfo(culture));
result.Value.Riddles.Should().BeEquivalentTo(new[] { riddle });
result.Value.GameSolutionForGroups.Should()
Expand Down Expand Up @@ -113,8 +112,7 @@ public void SelectGroupNumber_ValidSelection_ReturnsUpdatedAggregate()
var result = EscapeGame.SelectGroupNumber(escapeGame, groupNumber);

//Assert
result.Errors.Should().BeEmpty();
result.IsSuccess.Should().BeTrue();
result.Should().BeSuccessfulWithoutErrors();
result.Value.Should().BeEquivalentTo(escapeGame, options => options.Excluding(x => x.SelectedGroupNumber));
result.Value.SelectedGroupNumber?.Value.Should().Be(2);
}
Expand Down Expand Up @@ -157,8 +155,7 @@ public void SolveRiddle_CorrectValue_ReturnsUpdatedEscapeGame()
var result = EscapeGame.SolveRiddle(escapeGame, "123", 0);

//Assert
result.Errors.Should().BeEmpty();
result.IsSuccess.Should().BeTrue();
result.Should().BeSuccessfulWithoutErrors();
result.Value.Should().BeEquivalentTo(escapeGame, options => options.Excluding(x => x.Riddles));
result.Value.Riddles.ElementAt(0).IsSolved.Value.Should().BeTrue();
}
Expand Down
4 changes: 2 additions & 2 deletions Domain.Test/EscapeGames/Entities/GameSolutionForGroupTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Domain.EscapeGames.Entities;
using Domain.EscapeGames.ValueObjects;
using Domain.Test.Lib;
using FluentAssertions;
using Xunit;

Expand All @@ -18,8 +19,7 @@ public void Create_ValidInput_CreatesCorrectly()
var result = GameSolutionForGroup.Create(groupNumber, gameSolution);

//Assert
result.IsSuccess.Should().BeTrue();
result.Errors.Should().BeEmpty();
result.Should().BeSuccessfulWithoutErrors();
result.Value.GameSolution.Should().BeEquivalentTo(gameSolution);
result.Value.GroupNumber.Should().BeEquivalentTo(groupNumber);
}
Expand Down
6 changes: 2 additions & 4 deletions Domain.Test/EscapeGames/Entities/RiddleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public void Create_ValidInput_CreatesRiddleCorrectly()
var result = Riddle.Create(riddleSolution, isSolved);

//Assert
result.IsSuccess.Should().BeTrue();
result.Errors.Should().BeEmpty();
result.Should().BeSuccessfulWithoutErrors();
result.Value.IsSolved.Should().BeEquivalentTo(isSolved);
result.Value.RiddleSolution.Should().BeEquivalentTo(riddleSolution);
}
Expand Down Expand Up @@ -71,8 +70,7 @@ public void Solve_CorrectValue_ReturnsSolvedRiddle()
var result = Riddle.Solve(riddle, "123");

//Assert
result.Errors.Should().BeEmpty();
result.IsSuccess.Should().BeTrue();
result.Should().BeSuccessfulWithoutErrors();
result.Value.IsSolved.Value.Should().BeTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Create_ValidInput_CreatesCorrectly()
var result = CreatorPassword.Create(input);

//Assert
result.IsSuccess.Should().BeTrue();
result.Should().BeSuccessfulWithoutErrors();
result.Value.Value.Should().Be(input);
}
}
2 changes: 1 addition & 1 deletion Domain.Test/EscapeGames/ValueObjects/GameSolutionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Create_ValidInput_CreatesCorrectly()
var result = GameSolution.Create(input);

//Assert
result.IsSuccess.Should().BeTrue();
result.Should().BeSuccessfulWithoutErrors();
result.Value.Value.Should().Be(input);
}
}
2 changes: 1 addition & 1 deletion Domain.Test/EscapeGames/ValueObjects/GroupNumberTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Create_ValidInput_CreatesCorrectly()
var result = GroupNumber.Create(input);

//Assert
result.IsSuccess.Should().BeTrue();
result.Should().BeSuccessfulWithoutErrors();
result.Value!.Value.Should().Be(input);
}
}
4 changes: 2 additions & 2 deletions Domain.Test/EscapeGames/ValueObjects/IsSolvedTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Domain.EscapeGames.ValueObjects;
using Domain.Test.Lib;
using FluentAssertions;
using Xunit;

Expand All @@ -13,8 +14,7 @@ public void Create_NoInput_CreateIsSolvedCorrectly()
var result = IsSolved.Create();

//Assert
result.IsSuccess.Should().BeTrue();
result.Errors.Should().BeEmpty();
result.Should().BeSuccessfulWithoutErrors();
result.Value.Value.Should().BeFalse();
}
}
5 changes: 2 additions & 3 deletions Domain.Test/EscapeGames/ValueObjects/RiddleSolutionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Create_InputIsNotOnlyDigits_ReturnsRiddleSolutionsMustNotBeEmptyErro
public void Create_InvalidLength_ReturnsRiddleSolutionInvalidLengthError(string inputValue)
{
//Arrange
var expectedError = new RiddleSolutionInvalidLengthError(3);
var expectedError = new RiddleSolutionInvalidLengthError(RiddleSolution.AllowedSolutionLengths.ToArray());

//Act
var result = RiddleSolution.Create(inputValue);
Expand All @@ -65,8 +65,7 @@ public void Create_ValidInput_CreateRiddleSolutionCorrectly(string inputValue)
var result = RiddleSolution.Create(inputValue);

//Assert
result.IsSuccess.Should().BeTrue();
result.Errors.Should().BeEmpty();
result.Should().BeSuccessfulWithoutErrors();
result.Value.Value.Should().Be(inputValue);
}
}
3 changes: 2 additions & 1 deletion Domain.Test/Lib/GenericCollectionAssertionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentAssertions.Collections;
using FluentAssertions;
using FluentAssertions.Collections;
using FluentResults;

namespace Domain.Test.Lib;
Expand Down
17 changes: 17 additions & 0 deletions Domain.Test/Lib/ObjectAssertionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using FluentAssertions;
using FluentAssertions.Primitives;
using FluentResults;

namespace Domain.Test.Lib;

public static class ObjectAssertionsExtensions
{
public static void BeSuccessfulWithoutErrors(this ObjectAssertions assertions)
{
if (assertions.Subject is not IResultBase result)
throw new ArgumentException($"Subject is not of type {typeof(Result)}");

result.Errors.Should().BeEmpty();
result.IsSuccess.Should().BeTrue();
}
}
2 changes: 1 addition & 1 deletion Domain/EscapeGames/ValueObjects/RiddleSolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private RiddleSolution(string value)
Value = value;
}

private static IEnumerable<int> AllowedSolutionLengths => new[] { 3, 4 };
public static IEnumerable<int> AllowedSolutionLengths => new[] { 3, 4 };

public static Result<RiddleSolution> Create(string? riddleSolution)
{
Expand Down

0 comments on commit 073ebc6

Please sign in to comment.