Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Product>CSharpFunctionalExtensions.FluentAssertions</Product>
<Title>$(Product)</Title>
<PackageTags>$(PackageTags)</PackageTags>
<RootNamespace>FluentAssertions</RootNamespace>
</PropertyGroup>

<ItemGroup>
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 @@ -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