Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/nuget/FluentAssertions-6.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleMcMaster authored Jan 9, 2025
2 parents 4e46c61 + a7dc0ee commit 0189027
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Authors>$(Company)</Authors>
<Copyright>Copyright © $(Company) $([System.DateTime]::Now.Year)</Copyright>
<Trademark>$(Company)™</Trademark>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionPrefix>3.0.0</VersionPrefix>
<Product>CSharpFunctionalExtensions.FluentAssertions</Product>
<Title>$(Product)</Title>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down Expand Up @@ -35,4 +35,4 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
<Product>CSharpFunctionalExtensions.FluentAssertions</Product>
<Title>$(Product)</Title>
<PackageTags>$(PackageTags)</PackageTags>
<RootNamespace>FluentAssertions</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpFunctionalExtensions" Version="2.37.0" />
<PackageReference Include="CSharpFunctionalExtensions" Version="3.0.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public MaybeAssertions(Maybe<T> instance) : base(instance) { }
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<MaybeAssertions<T>> HaveSomeValue(string because = "", params object[] becauseArgs)
public AndWhichConstraint<MaybeAssertions<T>, T> HaveSomeValue(string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(v => v.HasValue)
.FailWith("Expected a value {reason}");

return new AndConstraint<MaybeAssertions<T>>(this);
return new AndWhichConstraint<MaybeAssertions<T>, T>(this, Subject.Value);
}

/// <summary>
Expand All @@ -39,7 +39,7 @@ public AndConstraint<MaybeAssertions<T>> HaveSomeValue(string because = "", para
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<MaybeAssertions<T>> HaveValue(T value, string because = "", params object[] becauseArgs)
public AndWhichConstraint<MaybeAssertions<T>, T> HaveValue(T value, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
Expand All @@ -56,7 +56,7 @@ public AndConstraint<MaybeAssertions<T>> HaveValue(T value, string because = "",
_ => value,
v => v);

return new AndConstraint<MaybeAssertions<T>>(this);
return new AndWhichConstraint<MaybeAssertions<T>, T>(this, Subject.Value);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public AndConstraint<ResultAssertions> Succeed(string because = "", params objec
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<ResultAssertions> Fail(string because = "", params object[] becauseArgs)
public AndWhichConstraint<ResultAssertions, string> Fail(string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.ForCondition(Subject.IsFailure)
.FailWith(() => new FailReason($"Expected {{context:result}} to fail{{reason}}, but it succeeded"));

return new AndConstraint<ResultAssertions>(this);
return new AndWhichConstraint<ResultAssertions, string>(this, Subject.Error);
}

/// <summary>
Expand All @@ -54,14 +54,14 @@ public AndConstraint<ResultAssertions> Fail(string because = "", params object[]
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<ResultAssertions> FailWith(string error, string because = "", params object[] becauseArgs)
public AndWhichConstraint<ResultAssertions, string> FailWith(string error, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject.IsFailure)
.ForCondition(b => Subject.Error!.Equals(error))
.FailWith($"Expected {{context:result}} error to be {{0}}, but found {{1}}", error, Subject.Error);

return new AndConstraint<ResultAssertions>(this);
return new AndWhichConstraint<ResultAssertions, string>(this, Subject.Error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public ResultTEAssertions(Result<T, E> instance) : base(instance) { }
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<ResultTEAssertions<T, E>> Succeed(string because = "", params object[] becauseArgs)
public AndWhichConstraint<ResultTEAssertions<T, E>, T> Succeed(string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.ForCondition(Subject.IsSuccess)
.FailWith(() => new FailReason(@$"Expected {{context:result}} to succeed{{reason}}, but it failed with error ""{Subject.Error}"""));
return new AndConstraint<ResultTEAssertions<T, E>>(this);
return new AndWhichConstraint<ResultTEAssertions<T, E>, T>(this, Subject.Value);
}
/// <summary>
Expand All @@ -37,7 +37,7 @@ public AndConstraint<ResultTEAssertions<T, E>> Succeed(string because = "", para
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<ResultTEAssertions<T, E>> SucceedWith(T value, string because = "", params object[] becauseArgs)
public AndWhichConstraint<ResultTEAssertions<T, E>, T> SucceedWith(T value, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
Expand All @@ -48,7 +48,7 @@ public AndConstraint<ResultTEAssertions<T, E>> SucceedWith(T value, string becau
.ForCondition(v => v!.Equals(value))
.FailWith("Expected {context:result} value to be {0}, but found {1}", value, Subject.Value);

return new AndConstraint<ResultTEAssertions<T, E>>(this);
return new AndWhichConstraint<ResultTEAssertions<T, E>, T>(this, Subject.Value);
}

/// <summary>
Expand All @@ -57,14 +57,14 @@ public AndConstraint<ResultTEAssertions<T, E>> SucceedWith(T value, string becau
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<ResultTEAssertions<T, E>> Fail(string because = "", params object[] becauseArgs)
public AndWhichConstraint<ResultTEAssertions<T, E>, E> Fail(string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.ForCondition(Subject.IsFailure)
.FailWith(() => new FailReason(@$"Expected {{context:result}} to fail, but it succeeded with value ""{Subject.Value}"""));
return new AndConstraint<ResultTEAssertions<T, E>>(this);
return new AndWhichConstraint<ResultTEAssertions<T, E>, E>(this, Subject.Error);
}
/// <summary>
Expand All @@ -74,7 +74,7 @@ public AndConstraint<ResultTEAssertions<T, E>> Fail(string because = "", params
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<ResultTEAssertions<T, E>> FailWith(E error, string because = "", params object[] becauseArgs)
public AndWhichConstraint<ResultTEAssertions<T, E>, E> FailWith(E error, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
Expand All @@ -85,6 +85,6 @@ public AndConstraint<ResultTEAssertions<T, E>> FailWith(E error, string because
.ForCondition(e => e!.Equals(error))
.FailWith($"Expected {{context:result}} error to be {{0}}, but found {{1}}", error, Subject.Error);

return new AndConstraint<ResultTEAssertions<T, E>>(this);
return new AndWhichConstraint<ResultTEAssertions<T, E>, E>(this, Subject.Error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public ResultTAssertions(Result<T> instance) : base(instance) { }
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<ResultTAssertions<T>> Succeed(string because = "", params object[] becauseArgs)
public AndWhichConstraint<ResultTAssertions<T>, T> Succeed(string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.ForCondition(Subject.IsSuccess)
.FailWith(() => new FailReason(@$"Expected {{context:result}} to succeed{{reason}}, but it failed with error ""{Subject.Error}"""));
return new AndConstraint<ResultTAssertions<T>>(this);
return new AndWhichConstraint<ResultTAssertions<T>, T>(this, Subject.Value);
}
/// <summary>
Expand All @@ -38,7 +38,7 @@ public AndConstraint<ResultTAssertions<T>> Succeed(string because = "", params o
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<ResultTAssertions<T>> SucceedWith(T value, string because = "", params object[] becauseArgs)
public AndWhichConstraint<ResultTAssertions<T>, T> SucceedWith(T value, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
Expand All @@ -49,7 +49,7 @@ public AndConstraint<ResultTAssertions<T>> SucceedWith(T value, string because =
.ForCondition(v => v!.Equals(value))
.FailWith($"Expected {{context:result}} value to be {{0}}, but found {{1}}", value, Subject.Value);

return new AndConstraint<ResultTAssertions<T>>(this);
return new AndWhichConstraint<ResultTAssertions<T>, T>(this, Subject.Value);
}

/// <summary>
Expand All @@ -58,14 +58,14 @@ public AndConstraint<ResultTAssertions<T>> SucceedWith(T value, string because =
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<ResultTAssertions<T>> Fail(string because = "", params object[] becauseArgs)
public AndWhichConstraint<ResultTAssertions<T>, string> Fail(string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.ForCondition(Subject.IsFailure)
.FailWith(() => new FailReason(@$"Expected {{context:result}} to fail, but it succeeded with value ""{Subject.Value}"""));
return new AndConstraint<ResultTAssertions<T>>(this);
return new AndWhichConstraint<ResultTAssertions<T>, string>(this, Subject.Error);
}
/// <summary>
Expand All @@ -75,14 +75,14 @@ public AndConstraint<ResultTAssertions<T>> Fail(string because = "", params obje
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<ResultTAssertions<T>> FailWith(string error, string because = "", params object[] becauseArgs)
public AndWhichConstraint<ResultTAssertions<T>, string> FailWith(string error, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject.IsFailure)
.ForCondition(b => Subject.Error!.Equals(error))
.FailWith($"Expected {{context:result}} error to be {{0}}, but found {{1}}", error, Subject.Error);

return new AndConstraint<ResultTAssertions<T>>(this);
return new AndWhichConstraint<ResultTAssertions<T>, string>(this, Subject.Error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public AndConstraint<UnitResultAssertions<E>> Succeed(string because = "", param
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<UnitResultAssertions<E>> Fail(string because = "", params object[] becauseArgs)
public AndWhichConstraint<UnitResultAssertions<E>, E> Fail(string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.ForCondition(Subject.IsFailure)
.FailWith(() => new FailReason($"Expected {{context:result}} to fail, but it succeeded"));

return new AndConstraint<UnitResultAssertions<E>>(this);
return new AndWhichConstraint<UnitResultAssertions<E>, E>(this, Subject.Error);
}

/// <summary>
Expand All @@ -53,7 +53,7 @@ public AndConstraint<UnitResultAssertions<E>> Fail(string because = "", params o
/// <param name="because"></param>
/// <param name="becauseArgs"></param>
/// <returns></returns>
public AndConstraint<UnitResultAssertions<E>> FailWith(E error, string because = "", params object[] becauseArgs)
public AndWhichConstraint<UnitResultAssertions<E>, E> FailWith(E error, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
Expand All @@ -64,6 +64,6 @@ public AndConstraint<UnitResultAssertions<E>> FailWith(E error, string because =
.ForCondition(e => e!.Equals(error))
.FailWith($"Expected {{context:result}} error to be {{0}}, but found {{1}}", error, Subject.Error);

return new AndConstraint<UnitResultAssertions<E>>(this);
return new AndWhichConstraint<UnitResultAssertions<E>, E>(this, Subject.Error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public void WhenMaybeIsExpectedToHaveSomeValueAndItDoesShouldNotThrow()
var maybe = Maybe.From("test");

maybe.Should().HaveSomeValue();
maybe.Should().HaveSomeValue().Which.Should().Be("test");
}

[Fact]
Expand All @@ -20,6 +21,7 @@ public void WhenMaybeIsExpectedToHaveValueAndItDoesShouldNotThrow()
var maybe = Maybe.From("test");

maybe.Should().HaveValue("test");
maybe.Should().HaveValue("test").Which.Should().HaveLength(4);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public void WhenResultIsExpectedToHaveErrorFailShouldNotThrow()

result.Should().Fail();
result.Should().FailWith(error);

result.Should().Fail().Which.Should().Be(error);
result.Should().FailWith(error).Which.Should().Be(error);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public void WhenResultIsExpectedToHaveValueItShouldBeSuccessful()
var result = Result.Success("test");

result.Should().Succeed();
result.Should().Succeed().Which.Should().Be("test");
}

[Fact]
Expand All @@ -31,6 +32,7 @@ public void WhenResultIsExpectedToHaveValueItShouldBeSuccessfulWithValue()
var result = Result.Success(expected);

result.Should().SucceedWith(expected);
result.Should().SucceedWith(expected).Which.Should().HaveLength(4);
}

[Fact]
Expand All @@ -51,6 +53,8 @@ public void WhenResultIsExpectedToHaveErrorFailShouldNotThrow()

result.Should().Fail();
result.Should().FailWith(error);
result.Should().Fail().Which.Should().Be(error);
result.Should().FailWith(error).Which.Should().HaveLength(5);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public void WhenResultIsExpectedToBeSuccessItShouldBeSuccess()
var action = () => result.Should().Succeed();

action.Should().NotThrow();
result.Should().Succeed().Which.Should().Be(value);
}

[Fact]
Expand All @@ -24,6 +25,7 @@ public void WhenResultIsExpectedToBeSuccessWithValueItShouldBeSuccessWithValue()
var result = Result.Success<string, Exception>(value);

result.Should().SucceedWith(value);
result.Should().SucceedWith(value).Which.Should().Be(value);
}

[Fact]
Expand Down Expand Up @@ -59,6 +61,8 @@ public void WhenResultIsExpectedToBeFailureItShouldBeFailure()

action.Should().NotThrow();
actionWith.Should().NotThrow();
result.Should().Fail().Which.Should().Be(error);
result.Should().FailWith(error).Which.Should().Be(error);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public void WhenResultIsExpectedToBeFailureItShouldBeFailure()

action.Should().NotThrow();
actionWithError.Should().NotThrow();
result.Should().Fail().Which.Should().Be(error);
result.Should().FailWith(error).Which.Should().HaveLength(5);
}

[Fact]
Expand Down

0 comments on commit 0189027

Please sign in to comment.