Skip to content

Commit 9a0e06d

Browse files
committed
Add tests
1 parent a76060e commit 9a0e06d

File tree

6 files changed

+121
-16
lines changed

6 files changed

+121
-16
lines changed

src/CSharpFunctionalExtensions.FluentAssertions/UnitResultExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public AndConstraint<UnitResultAssertions<E>> Fail(string because = "", params o
5555
/// <param name="because"></param>
5656
/// <param name="becauseArgs"></param>
5757
/// <returns></returns>
58-
public AndConstraint<UnitResultAssertions<E>> Fail(E error, string because = "", params object[] becauseArgs)
58+
public AndConstraint<UnitResultAssertions<E>> FailWith(E error, string because = "", params object[] becauseArgs)
5959
{
6060
Execute.Assertion
6161
.BecauseOf(because, becauseArgs)

tests/CSharpFunctionalExtensions.FluentAssertions.Tests/MaybeAssertionsTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ namespace CSharpFunctionalExtensions.FluentAssertions.Tests;
77
public class MaybeAssertionsTests
88
{
99
[Fact]
10-
public void When_Maybe_Is_Expected_To_Have_Value_And_It_Does_Should_Not_Throw()
10+
public void WhenMaybeIsExpectedToHaveValueAndItDoesShouldNotThrow()
1111
{
1212
var x = Maybe.From("test");
1313

1414
x.Should().HaveValue("test");
1515
}
1616

1717
[Fact]
18-
public void When_Maybe_Is_Expected_To_Have_Value_And_It_Has_Wrong_Value_Should_Throw()
18+
public void WhenMaybeIsExpectedToHaveValueAndItHasWrongValueShouldThrow()
1919
{
2020
var x = Maybe.From("oops");
2121

@@ -25,7 +25,7 @@ public void When_Maybe_Is_Expected_To_Have_Value_And_It_Has_Wrong_Value_Should_T
2525
}
2626

2727
[Fact]
28-
public void When_Maybe_Is_Expected_To_Have_Value_And_It_Does_Not_Should_Throw()
28+
public void WhenMaybeIsExpectedToHaveValueAndItDoesNotShouldThrow()
2929
{
3030
Maybe<string> x = null;
3131

@@ -35,15 +35,15 @@ public void When_Maybe_Is_Expected_To_Have_Value_And_It_Does_Not_Should_Throw()
3535
}
3636

3737
[Fact]
38-
public void When_Maybe_Is_Expected_To_Have_No_Value_And_It_Has_None_Should_Not_Throw()
38+
public void WhenMaybeIsExpectedToHaveNoValueAndItHasNoneShouldNotThrow()
3939
{
4040
Maybe<string> x = null;
4141

4242
x.Should().HaveNoValue();
4343
}
4444

4545
[Fact]
46-
public void When_Maybe_Is_Expected_To_Have_No_Value_And_It_Has_One_Should_Throw()
46+
public void WhenMaybeIsExpectedToHaveNoValueAndItHasOneShouldThrow()
4747
{
4848
var x = Maybe.From("test");
4949

tests/CSharpFunctionalExtensions.FluentAssertions.Tests/ResultAssertionTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ namespace CSharpFunctionalExtensions.FluentAssertions.Tests;
77
public class ResultAssertionTests
88
{
99
[Fact]
10-
public void When_Result_Is_Expected_To_Have_Value_It_Should_Be_Successful()
10+
public void WhenResultIsExpectedToHaveValueItShouldBeSuccessful()
1111
{
1212
var x = Result.Success();
1313

1414
x.Should().Succeed();
1515
}
1616

1717
[Fact]
18-
public void When_Result_Is_Expected_To_Have_Value_It_Should_Not_Be_Failure()
18+
public void WhenResultIsExpectedToHaveValueItShouldNotBeFailure()
1919
{
2020
var x = Result.Success();
2121

@@ -25,15 +25,15 @@ public void When_Result_Is_Expected_To_Have_Value_It_Should_Not_Be_Failure()
2525
}
2626

2727
[Fact]
28-
public void When_Result_Is_Expected_To_Have_Error_It_Should_Not_Be_Failure()
28+
public void WhenResultIsExpectedToHaveErrorItShouldNotBeFailure()
2929
{
3030
var x = Result.Failure("error");
3131

3232
x.Should().Fail();
3333
}
3434

3535
[Fact]
36-
public void When_Result_Is_Expected_To_Have_Error_It_Should_Be_Failure()
36+
public void WhenResultIsExpectedToHaveErrorItShouldBeFailure()
3737
{
3838
var x = Result.Failure("error");
3939

tests/CSharpFunctionalExtensions.FluentAssertions.Tests/ResultTAssertionsTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ namespace CSharpFunctionalExtensions.FluentAssertions.Tests;
77
public class ResultAssertionsTests
88
{
99
[Fact]
10-
public void When_Result_Is_Expected_To_Have_Value_It_Should_Be_Successful()
10+
public void WhenResultIsExpectedToHaveValueItShouldBeSuccessful()
1111
{
1212
var x = Result.Success("test");
1313

1414
x.Should().Succeed();
1515
}
1616

1717
[Fact]
18-
public void When_Result_Is_Expected_To_Have_Value_It_Should_Not_Be_Failure()
18+
public void WhenResultIsExpectedToHaveValueItShouldNotBeFailure()
1919
{
2020
var x = Result.Success("test");
2121

@@ -25,7 +25,7 @@ public void When_Result_Is_Expected_To_Have_Value_It_Should_Not_Be_Failure()
2525
}
2626

2727
[Fact]
28-
public void When_Result_Is_Expected_To_Have_Value_It_Should_Be_Successful_With_Value()
28+
public void WhenResultIsExpectedToHaveValueItShouldBeSuccessfulWithValue()
2929
{
3030
string expected = "test";
3131
var x = Result.Success(expected);
@@ -34,7 +34,7 @@ public void When_Result_Is_Expected_To_Have_Value_It_Should_Be_Successful_With_V
3434
}
3535

3636
[Fact]
37-
public void When_Result_Is_Expected_To_Have_Value_It_Should_Not_Be_Successful_With_Different_Value()
37+
public void WhenResultIsExpectedToHaveValueItShouldNotBeSuccessfulWithDifferentValue()
3838
{
3939
var x = Result.Success("foo");
4040

@@ -44,15 +44,15 @@ public void When_Result_Is_Expected_To_Have_Value_It_Should_Not_Be_Successful_Wi
4444
}
4545

4646
[Fact]
47-
public void When_Result_Is_Expected_To_Have_Error_It_Should_Not_Be_Failure()
47+
public void WhenResultIsExpectedToHaveErrorItShouldNotBeFailure()
4848
{
4949
var x = Result.Failure<string>("error");
5050

5151
x.Should().Fail();
5252
}
5353

5454
[Fact]
55-
public void When_Result_Is_Expected_To_Have_Error_It_Should_Be_Failure()
55+
public void WhenResultIsExpectedToHaveErrorItShouldBeFailure()
5656
{
5757
var x = Result.Failure<string>("error");
5858

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using FluentAssertions;
3+
using Xunit;
4+
using Xunit.Sdk;
5+
6+
namespace CSharpFunctionalExtensions.FluentAssertions.Tests;
7+
public class ResultTEAssertionTests
8+
{
9+
[Fact]
10+
public void WhenResultIsExpectedToBeSuccessItShouldBeSuccess()
11+
{
12+
string value = "value";
13+
var result = Result.Success<string, Exception>(value);
14+
15+
var action = () => result.Should().Succeed();
16+
17+
action.Should().NotThrow();
18+
}
19+
20+
[Fact]
21+
public void WhenResultIsExpectedToBeSuccessItShouldThrowWhenFailure()
22+
{
23+
var error = new Exception("error");
24+
var result = Result.Failure<string, Exception>(error);
25+
26+
var action = () => result.Should().Succeed();
27+
28+
action.Should().Throw<XunitException>().WithMessage("Expected Result to be successful but it failed");
29+
}
30+
31+
[Fact]
32+
public void WhenResultIsExpectedToBeFailureItShouldBeFailure()
33+
{
34+
var error = new Exception("error");
35+
var result = Result.Failure<string, Exception>(error);
36+
37+
var action = () => result.Should().Fail();
38+
var actionWith = () => result.Should().FailWith(error);
39+
40+
action.Should().NotThrow();
41+
actionWith.Should().NotThrow();
42+
}
43+
44+
[Fact]
45+
public void WhenResultIsExpectedToBeFailureItShouldThrowWhenSuccess()
46+
{
47+
string value = "value";
48+
var someError = new Exception("error");
49+
var result = Result.Success<string, Exception>(value);
50+
51+
var action = () => result.Should().Fail();
52+
var actionWith = () => result.Should().FailWith(someError);
53+
54+
action.Should().Throw<XunitException>().WithMessage("Expected Result to be failure but it succeeded");
55+
actionWith.Should().Throw<XunitException>().WithMessage("Expected Result to be failure but it succeeded");
56+
}
57+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using FluentAssertions;
2+
using Xunit;
3+
using Xunit.Sdk;
4+
5+
namespace CSharpFunctionalExtensions.FluentAssertions.Tests;
6+
public class UnitResultAssertionTests
7+
{
8+
[Fact]
9+
public void WhenResultIsExpectedToBeSuccessItShouldBeSuccess()
10+
{
11+
var r = UnitResult.Success<string>();
12+
var action = () => r.Should().Succeed();
13+
14+
action.Should().NotThrow();
15+
}
16+
17+
[Fact]
18+
public void WhenResultIsExpectedToBeSuccessItShouldThrowWhenFailure()
19+
{
20+
string error = "error";
21+
var r = UnitResult.Failure(error);
22+
var action = () => r.Should().Succeed();
23+
24+
action.Should().Throw<XunitException>().WithMessage("Expected UnitResult to be successful but it failed");
25+
}
26+
27+
[Fact]
28+
public void WhenResultIsExpectedToBeFailureItShouldBeFailure()
29+
{
30+
string error = "error";
31+
var r = UnitResult.Failure(error);
32+
33+
var action = () => r.Should().Fail();
34+
var actionWithError = () => r.Should().FailWith(error);
35+
36+
action.Should().NotThrow();
37+
actionWithError.Should().NotThrow();
38+
}
39+
40+
[Fact]
41+
public void WhenResultIsExpectedToBeFailureItShouldThrowWhenSuccess()
42+
{
43+
var r = UnitResult.Success<string>();
44+
var action = () => r.Should().Fail();
45+
46+
action.Should().Throw<XunitException>().WithMessage("Expected UnitResult to be failure but it succeeded");
47+
}
48+
}

0 commit comments

Comments
 (0)