Skip to content
This repository was archived by the owner on May 30, 2021. It is now read-only.

Commit dba7b2d

Browse files
committed
Added docs
1 parent b85ff97 commit dba7b2d

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed

docs/Asserter.md

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Asserter
2+
3+
As explained in the [Overview](Overview.md), the Asserter is a collection of additional and improved code assertion methods where the MSTest Assert equivalent doesn't provide useful messages when the assertion fails.
4+
5+
The Asserter provides the following code assertion extensions:
6+
7+
## IsTrue
8+
9+
This method tests whether the specified condition is true and throws an exception if the condition is false.
10+
11+
The method comes as an improvement over the MSTest `Assert.IsTrue` for two reasons. Firstly, the failure message provides useful information showing what is false. More importantly, the condition parameter takes an Expression which allows you to build up an assertion through multiple parameters.
12+
13+
**Example**
14+
15+
```csharp
16+
[TestMethod]
17+
public void TestObject_WhenBooleanMethodCalledWithTrueParameter_ShouldReturnTrueAndSetBooleanPropertyTestToFalse()
18+
{
19+
// Arrange
20+
21+
var o = new TestObject { BooleanPropertyTest = true };
22+
23+
// Act & Assert
24+
25+
Asserter.IsTrue(() => !o.BooleanPropertyTest && o.BooleanMethodTest(true));
26+
}
27+
```
28+
29+
## IsFalse
30+
31+
This method tests whether the specified condition is false and throws an exception if the condition is true.
32+
33+
The method comes as an improvement over the MSTest `Assert.IsFalse` for two reasons. Firstly, the failure message provides useful information showing what is true. More importantly, the condition parameter takes an Expression which allows you to build up an assertion through multiple parameters.
34+
35+
**Example**
36+
37+
```csharp
38+
[TestMethod]
39+
public void TestObject_WhenBooleanMethodCalledWithFalseParameter_ShouldSetBooleanPropertyTestToFalse()
40+
{
41+
// Arrange
42+
43+
var o = new TestObject { BooleanPropertyTest = true };
44+
45+
// Act
46+
47+
o.BooleanMethodTest(false);
48+
49+
// Assert
50+
51+
Asserter.IsFalse(() => o.BooleanPropertyTest);
52+
}
53+
```
54+
55+
## IsNull
56+
57+
This method tests whether the specified condition is null and throws an exception if the condition is not null.
58+
59+
The method comes as an improvement over the MSTest `Assert.IsNull` for two reasons. Firstly, the failure message provides useful information showing what is not null. More importantly, the condition parameter takes an Expression which allows you to build up an assertion through multiple parameters.
60+
61+
**Example**
62+
63+
```csharp
64+
[TestMethod]
65+
public void TestObject_WhenNullableBooleanMethodCalledWithNullParameter_ShouldSetNullableBooleanPropertyTestToNull()
66+
{
67+
// Arrange
68+
69+
var o = new TestObject { NullableBooleanPropertyTest = true };
70+
71+
// Act
72+
73+
o.NullableBooleanMethodTest(null);
74+
75+
// Assert
76+
77+
Asserter.IsNull(() => o.NullableBooleanPropertyTest);
78+
}
79+
```
80+
81+
## IsNotNull
82+
83+
This method tests whether the specified condition is not null and throws an exception if the condition is null.
84+
85+
The method comes as an improvement over the MSTest `Assert.IsNotNull` for two reasons. Firstly, the failure message provides useful information showing what is null. More importantly, the condition parameter takes an Expression which allows you to build up an assertion through multiple parameters.
86+
87+
**Example**
88+
89+
```csharp
90+
[TestMethod]
91+
public void TestObject_WhenNullableBooleanMethodCalledWithTrueParameter_ShouldSetNullableBooleanPropertyTestToTrue()
92+
{
93+
// Arrange
94+
95+
var o = new TestObject { NullableBooleanPropertyTest = null };
96+
97+
// Act
98+
99+
o.NullableBooleanMethodTest(true);
100+
101+
// Assert
102+
103+
Asserter.IsNotNull(() => o.NullableBooleanPropertyTest);
104+
}
105+
```

docs/CollectionAsserter.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# CollectionAsserter
2+
3+
As explained in the [Overview](Overview.md), the CollectionAsserter is a collection of additional and improved code assertion methods for enumerable collections where the MSTest CollectionAssert equivalent doesn't provide alternatives, such as `AreEnumerablesEqual`.
4+
5+
The CollectionAsserter provides the following code assertion extensions:
6+
7+
## AreEnumerablesEqual
8+
9+
This method tests whether the specified enumerables are equal and throws an exception if the two enumerables are not equal. Equality is defined as having the same elements, compared using Equals, in the same order and same quantity.
10+
11+
**Example**
12+
13+
```csharp
14+
[TestMethod]
15+
public void Setup_WhenCalledWithPopulateItems_ShouldAddEachItemToItemsProperty()
16+
{
17+
// Arrange
18+
19+
var expected = new List<EqualityTestObject> { new EqualityTestObject(), new EqualityTestObject { BooleanPropertyTest = true } };
20+
21+
var model = new EqualityModel();
22+
23+
// Act
24+
25+
model.Setup(expected);
26+
27+
IEnumerable<EqualityTestObject> actual = model.Items;
28+
29+
// Assert
30+
31+
CollectionAsserter.AreEnumerablesEqual<EqualityTestObject>(expected, actual);
32+
}
33+
```
34+
35+
There is also an overload which contains an additional parameter to provide your own comparer for the items in the collections.
36+
37+
## AreEnumerablesEquivalent
38+
39+
This method tests whether two collections contain the same elements and throws an exception if either collection contains an element not in the other collection.
40+
41+
The benefit of this method over `AreEnumerablesEqual` is that the order of the items does not matter, as long as both enumerables contain all the items.
42+
43+
**Example**
44+
45+
```csharp
46+
[TestMethod]
47+
public void Setup_WhenCalledWithPopulateItems_ShouldAddEachItemToItemsProperty()
48+
{
49+
// Arrange
50+
51+
var expected = new List<EqualityTestObject> { new EqualityTestObject(), new EqualityTestObject { BooleanPropertyTest = true } };
52+
53+
var model = new EqualityModel();
54+
55+
// Act
56+
57+
model.Setup(expected);
58+
59+
IEnumerable<EqualityTestObject> actual = model.Items;
60+
61+
// Assert
62+
63+
CollectionAsserter.AreEnumerablesEquivalent<EqualityTestObject>(expected, actual);
64+
}
65+
```

docs/ExceptionAsserter.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ExceptionAsserter
2+
3+
As explained in the [Overview](Overview.md), the ExceptionAsserter is a collection of additional and improved code assertion methods for exception checks where the MSTest Assert equivalent doesn't provide alternatives, such as `DoesNotThrowException`.
4+
5+
The ExceptionAsserter provides the following code assertion extensions:
6+
7+
## DoesNotThrowException
8+
9+
This method tests whether the code specified by delegate condition called does not throw an exception.
10+
11+
**Example**
12+
13+
```csharp
14+
[TestMethod]
15+
public void Setup_WhenCalledWithNullItems_ShouldNotThrowNullReferenceException()
16+
{
17+
// Arrange
18+
19+
IEnumerable<EqualityTestObject> items = default(IEnumerable<EqualityTestObject>);
20+
21+
var model = new EqualityModel();
22+
23+
// Act & Assert
24+
25+
ExceptionAsserter.DoesNotThrowException(() => model.Setup(items));
26+
}
27+
```
28+
29+
There is also an asynchronous alternative `DoesNotThrowExceptionAsync` for testing asynchronous operations.

docs/Overview.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Overview
2+
3+
MADE Microsoft Test Framework Extension Library is separated into multiple extension and helper classes for code assertion:
4+
5+
- [Asserter](../src/MADE.Testing.MSTest/Asserter.cs)
6+
- Defines a code assertion helper for common scenarios, similar to the [MSTest Assert](https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.testtools.unittesting.assert).
7+
- [CollectionAsserter](../src/MADE.Testing.MSTest/CollectionAsserter.cs)
8+
- Defines a code assertion helper for collection based scenarios, similar to the [MSTest CollectionAssert](https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.testtools.unittesting.collectionassert).
9+
- [ExceptionAsserter](../src/MADE.Testing.MSTest/ExcpetionAsserter.cs)
10+
- Defines a code assertion helper for exception based scenarios.
11+
12+
## Asserter
13+
14+
The Asserter is a collection of additional and improved code assertion methods where the MSTest Assert equivalent doesn't provide useful messages when the assertion fails.
15+
16+
[Read more about Asserter](Asserter.md).
17+
18+
## CollectionAsserter
19+
20+
The CollectionAsserter is a collection of additional and improved code assertion methods for enumerable collections where the MSTest CollectionAssert equivalent doesn't provide alternatives, such as `AreEnumerablesEqual`.
21+
22+
[Read more about CollectionAsserter](CollectionAsserter.md).
23+
24+
## ExceptionAsserter
25+
26+
The ExceptionAsserter is a collection of additional and improved code assertion methods for exception checks where the MSTest Assert equivalent doesn't provide alternatives, such as `DoesNotThrowException`.
27+
28+
[Read more about ExceptionAsserter](ExceptionAsserter.md).

0 commit comments

Comments
 (0)