/
BufferedStreamAssertionSpecs.cs
115 lines (97 loc) · 3.7 KB
/
BufferedStreamAssertionSpecs.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1
using System;
using System.IO;
using FluentAssertions.Execution;
using Xunit;
using Xunit.Sdk;
#endif
namespace FluentAssertions.Specs.Streams
{
public class BufferedStreamAssertionSpecs
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1
public class HaveBufferSize
{
[Fact]
public void When_a_stream_has_the_expected_buffer_size_it_should_succeed()
{
// Arrange
using var stream = new BufferedStream(new MemoryStream(), 10);
// Act
Action act = () =>
stream.Should().HaveBufferSize(10);
// Assert
act.Should().NotThrow();
}
[Fact]
public void When_a_stream_has_an_unexpected_buffer_size_should_fail()
{
// Arrange
using var stream = new BufferedStream(new MemoryStream(), 1);
// Act
Action act = () =>
stream.Should().HaveBufferSize(10, "we want to test the failure {0}", "message");
// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected the buffer size of stream to be 10 *failure message*, but it was 1.");
}
[Fact]
public void When_null_have_buffer_size_should_fail()
{
// Arrange
BufferedStream stream = null;
// Act
Action act = () =>
{
using var _ = new AssertionScope();
stream.Should().HaveBufferSize(10, "we want to test the failure {0}", "message");
};
// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected the buffer size of stream to be 10 *failure message*, but found a <null> reference.");
}
}
public class NotHaveBufferSize
{
[Fact]
public void When_a_stream_does_not_have_an_unexpected_buffer_size_it_should_succeed()
{
// Arrange
using var stream = new BufferedStream(new MemoryStream(), 1);
// Act
Action act = () =>
stream.Should().NotHaveBufferSize(10);
// Assert
act.Should().NotThrow();
}
[Fact]
public void When_a_stream_does_have_the_unexpected_buffer_size_it_should_fail()
{
// Arrange
using var stream = new BufferedStream(new MemoryStream(), 10);
// Act
Action act = () =>
stream.Should().NotHaveBufferSize(10, "we want to test the failure {0}", "message");
// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected the buffer size of stream not to be 10 *failure message*, but it was.");
}
[Fact]
public void When_null_not_have_buffer_size_should_fail()
{
// Arrange
BufferedStream stream = null;
// Act
Action act = () =>
{
using var _ = new AssertionScope();
stream.Should().NotHaveBufferSize(10, "we want to test the failure {0}", "message");
};
// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected the buffer size of stream not to be 10 *failure message*, but found a <null> reference.");
}
}
#endif
}
}