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 @@ -25,9 +25,8 @@ public AndConstraint<ResultAssertions> Succeed(string because = "", params objec
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(s => s.IsSuccess)
.FailWith("Expected Result to be successful but it failed");
.ForCondition(Subject.IsSuccess)
.FailWith(() => new FailReason(@$"Expected {{context:result}} to succeed{{reason}}, but it failed with error ""{Subject.Error}"""));

return new AndConstraint<ResultAssertions>(this);
}
Expand All @@ -42,9 +41,8 @@ public AndConstraint<ResultAssertions> Fail(string because = "", params object[]
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(s => s.IsFailure)
.FailWith("Expected Result to be failure but it succeeded");
.ForCondition(Subject.IsFailure)
.FailWith(() => new FailReason($"Expected {{context:result}} to fail{{reason}}, but it succeeded"));

return new AndConstraint<ResultAssertions>(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ public AndConstraint<ResultTEAssertions<T, E>> Succeed(string because = "", para
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(s => s.IsSuccess)
.FailWith("Expected Result to be successful but it failed");
.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);
}
Expand All @@ -42,13 +41,12 @@ public AndConstraint<ResultTEAssertions<T, E>> SucceedWith(T value, string becau
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(s => s.IsSuccess)
.FailWith("Expected Result to be successful but it failed")
.ForCondition(Subject.IsSuccess)
.FailWith(() => new FailReason(@$"Expected {{context:result}} to succeed{{reason}}, but it failed with error ""{Subject.Error}"""))
.Then
.Given(s => s.Value)
.Given(() => Subject.Value)
.ForCondition(v => v!.Equals(value))
.FailWith("Excepted Result value to be {0} but found {1}", value, Subject.Value);
.FailWith("Expected {context:result} value to be {0}, but found {1}", value, Subject.Value);

return new AndConstraint<ResultTEAssertions<T, E>>(this);
}
Expand All @@ -63,9 +61,8 @@ public AndConstraint<ResultTEAssertions<T, E>> Fail(string because = "", params
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(s => s.IsFailure)
.FailWith("Expected Result to be failure but it succeeded");
.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);
}
Expand All @@ -81,13 +78,12 @@ public AndConstraint<ResultTEAssertions<T, E>> FailWith(E error, string because
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(s => s.IsFailure)
.FailWith("Expected Result to be failure but it succeeded")
.ForCondition(Subject.IsFailure)
.FailWith(() => new FailReason($"Expected {{context:result}} to fail, but it succeeded"))
.Then
.Given(s => s.Error)
.Given(() => Subject.Error)
.ForCondition(e => e!.Equals(error))
.FailWith("Excepted Result value to be {0} but found {1}", error, Subject.Error);
.FailWith($"Expected {{context:result}} error to be {{0}}, but found {{1}}", error, Subject.Error);

return new AndConstraint<ResultTEAssertions<T, E>>(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public AndConstraint<ResultTAssertions<T>> Succeed(string because = "", params o
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(s => s.IsSuccess)
.FailWith("Expected Result to be successful but it failed");
.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);
}
Expand All @@ -43,13 +42,12 @@ public AndConstraint<ResultTAssertions<T>> SucceedWith(T value, string because =
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(s => s.IsSuccess)
.FailWith("Expected Result to be successful but it failed")
.ForCondition(Subject.IsSuccess)
.FailWith(() => new FailReason(@$"Expected {{context:result}} to succeed{{reason}}, but it failed with error ""{Subject.Error}"""))
.Then
.Given(s => s.Value)
.Given(() => Subject.Value)
.ForCondition(v => v!.Equals(value))
.FailWith("Excepted Result value to be {0} but found {1}", value, Subject.Value);
.FailWith($"Expected {{context:result}} value to be {{0}}, but found {{1}}", value, Subject.Value);

return new AndConstraint<ResultTAssertions<T>>(this);
}
Expand All @@ -64,9 +62,8 @@ public AndConstraint<ResultTAssertions<T>> Fail(string because = "", params obje
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(s => s.IsFailure)
.FailWith("Expected Result to be failure but it succeeded");
.ForCondition(Subject.IsFailure)
.FailWith(() => new FailReason(@$"Expected {{context:result}} to fail, but it succeeded with value ""{Subject.Value}"""));

return new AndConstraint<ResultTAssertions<T>>(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ public AndConstraint<UnitResultAssertions<E>> Succeed(string because = "", param
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(s => s.IsSuccess)
.FailWith("Expected UnitResult to be successful but it failed");
.ForCondition(Subject.IsSuccess)
.FailWith(() => new FailReason(@$"Expected {{context:result}} to succeed{{reason}}, but it failed with error ""{Subject.Error}"""));

return new AndConstraint<UnitResultAssertions<E>>(this);
}
Expand All @@ -41,15 +40,14 @@ public AndConstraint<UnitResultAssertions<E>> Fail(string because = "", params o
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(s => s.IsFailure)
.FailWith("Expected UnitResult to be failure but it succeeded");
.ForCondition(Subject.IsFailure)
.FailWith(() => new FailReason($"Expected {{context:result}} to fail, but it succeeded"));

return new AndConstraint<UnitResultAssertions<E>>(this);
}

/// <summary>
/// Asserts a unit result is a failure with a specfied error.
/// Asserts a unit result is a failure with a specified error.
/// </summary>
/// <param name="error"></param>
/// <param name="because"></param>
Expand All @@ -59,13 +57,12 @@ public AndConstraint<UnitResultAssertions<E>> FailWith(E error, string because =
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => Subject)
.ForCondition(s => s.IsFailure)
.FailWith("Expected UnitResult to be failure but it succeeded")
.ForCondition(Subject.IsFailure)
.FailWith(() => new FailReason($"Expected {{context:result}} to fail, but it succeeded"))
.Then
.Given(s => s.Error)
.Given(() => Subject.Error)
.ForCondition(e => e!.Equals(error))
.FailWith("Excepted UnitResult value to be {0} but found {1}", error, Subject.Error);
.FailWith($"Expected {{context:result}} error to be {{0}}, but found {{1}}", error, Subject.Error);

return new AndConstraint<UnitResultAssertions<E>>(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void WhenResultIsExpectedToHaveValueItShouldNotBeFailure()

var action = () => result.Should().Fail();

action.Should().Throw<XunitException>().WithMessage("Expected Result to be failure but it succeeded");
action.Should().Throw<XunitException>().WithMessage($"Expected {nameof(result)} to fail, but it succeeded");
}

[Fact]
Expand All @@ -39,6 +39,6 @@ public void WhenResultIsExpectedToHaveErrorItShouldBeFailure()

var action = () => result.Should().Succeed();

action.Should().Throw<XunitException>().WithMessage("Expected Result to be successful but it failed");
action.Should().Throw<XunitException>().WithMessage(@$"Expected {nameof(result)} to succeed, but it failed with error ""error""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void WhenResultIsExpectedToHaveValueItShouldNotBeFailure()

var action = () => result.Should().Fail();

action.Should().Throw<XunitException>().WithMessage("Expected Result to be failure but it succeeded");
action.Should().Throw<XunitException>().WithMessage(@$"Expected {nameof(result)} to fail, but it succeeded with value ""test""");
}

[Fact]
Expand All @@ -40,7 +40,7 @@ public void WhenResultIsExpectedToHaveValueItShouldNotBeSuccessfulWithDifferentV

var action = () => result.Should().SucceedWith("bar");

action.Should().Throw<XunitException>().WithMessage(@"Excepted Result value to be ""bar"" but found ""foo""");
action.Should().Throw<XunitException>().WithMessage(@$"Expected {nameof(result)} value to be ""bar"", but found ""foo""");
}

[Fact]
Expand All @@ -58,6 +58,6 @@ public void WhenResultIsExpectedToHaveErrorItShouldBeFailure()

var action = () => result.Should().Succeed();

action.Should().Throw<XunitException>().WithMessage("Expected Result to be successful but it failed");
action.Should().Throw<XunitException>().WithMessage(@$"Expected {nameof(result)} to succeed, but it failed with error ""error""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void WhenResultIsExpectedToBeSuccessItShouldThrowWhenFailure()

var action = () => result.Should().Succeed();

action.Should().Throw<XunitException>().WithMessage("Expected Result to be successful but it failed");
action.Should().Throw<XunitException>().WithMessage(@$"Expected {nameof(result)} to succeed, but it failed with error ""System.Exception: error""");
}

[Fact]
Expand All @@ -45,7 +45,7 @@ public void WhenResultIsExpectedToBeSuccessWithValueItShouldThrowWhenSuccessWith

var action = () => result.Should().SucceedWith("some other value");

action.Should().Throw<XunitException>().WithMessage("Excepted Result value to be \"some other value\" but found \"value\"");
action.Should().Throw<XunitException>().WithMessage(@$"Expected {nameof(result)} value to be ""some other value"", but found ""value""");
}

[Fact]
Expand Down Expand Up @@ -78,7 +78,7 @@ public void WhenResultIsExpectedToBeFailureWithValueItShouldThrowWhenFailureWith

var action = () => result.Should().FailWith(new Exception("Some other error"));

action.Should().Throw<XunitException>().WithMessage("Excepted Result value to be System.Exception with message \"Some other error\" but found System.Exception with message \"error\"");
action.Should().Throw<XunitException>().WithMessage(@$"Expected {nameof(result)} error to be System.Exception with message ""Some other error"", but found System.Exception with message ""error""");
}

[Fact]
Expand All @@ -91,7 +91,7 @@ public void WhenResultIsExpectedToBeFailureItShouldThrowWhenSuccess()
var action = () => result.Should().Fail();
var actionWith = () => result.Should().FailWith(someError);

action.Should().Throw<XunitException>().WithMessage("Expected Result to be failure but it succeeded");
actionWith.Should().Throw<XunitException>().WithMessage("Expected Result to be failure but it succeeded");
action.Should().Throw<XunitException>().WithMessage(@$"Expected {nameof(result)} to fail, but it succeeded with value ""{value}""");
actionWith.Should().Throw<XunitException>().WithMessage(@$"Expected {nameof(result)} to fail, but it succeeded");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void WhenResultIsExpectedToBeSuccessItShouldThrowWhenFailure()

var action = () => result.Should().Succeed();

action.Should().Throw<XunitException>().WithMessage("Expected UnitResult to be successful but it failed");
action.Should().Throw<XunitException>().WithMessage(@$"Expected {nameof(result)} to succeed, but it failed with error ""{error}""");
}

[Fact]
Expand Down Expand Up @@ -56,7 +56,7 @@ public void WhenResultIsExpectedToBeFailureWithValueItShouldThrowWhenFailureWith

var action = () => result.Should().FailWith("some other error");

action.Should().Throw<XunitException>().WithMessage("Excepted UnitResult value to be \"some other error\" but found \"error\"");
action.Should().Throw<XunitException>().WithMessage(@$"Expected {nameof(result)} error to be ""some other error"", but found ""{error}""");
}

[Fact]
Expand All @@ -66,6 +66,6 @@ public void WhenResultIsExpectedToBeFailureItShouldThrowWhenSuccess()

var action = () => result.Should().Fail();

action.Should().Throw<XunitException>().WithMessage("Expected UnitResult to be failure but it succeeded");
action.Should().Throw<XunitException>().WithMessage($"Expected {nameof(result)} to fail, but it succeeded");
}
}