-
-
Notifications
You must be signed in to change notification settings - Fork 540
/
ExtensibilitySpecs.cs
65 lines (57 loc) · 2.23 KB
/
ExtensibilitySpecs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using Xunit;
using Xunit.Sdk;
namespace FluentAssertions.Specs
{
public class ExtensibilitySpecs
{
[Fact]
public void When_a_method_is_marked_as_custom_assertion_it_should_be_ignored_during_caller_identification()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
var myClient = new MyCustomer
{
Active = false
};
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action act = () => myClient.Should().BeActive("because we don't work with old clients");
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<XunitException>().WithMessage(
#if NETCOREAPP1_1
"Expected boolean to be true because we don't work with old clients, but found False.");
#else
"Expected myClient to be true because we don't work with old clients, but found False.");
#endif
}
}
public class MyCustomer
{
public bool Active { get; set; }
}
public static class MyCustomerExtensions
{
public static MyCustomerAssertions Should(this MyCustomer customer)
{
return new MyCustomerAssertions(customer);
}
}
public class MyCustomerAssertions
{
private readonly MyCustomer customer;
public MyCustomerAssertions(MyCustomer customer)
{
this.customer = customer;
}
[CustomAssertion]
public void BeActive(string because = "", params object[] becauseArgs)
{
customer.Active.Should().BeTrue(because, becauseArgs);
}
}
}