-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathShouldReturnContentTests.cs
More file actions
96 lines (77 loc) · 4.67 KB
/
ShouldReturnContentTests.cs
File metadata and controls
96 lines (77 loc) · 4.67 KB
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
using NUnit.Framework;
using System.Web.Mvc;
using System.Text;
using TestStack.FluentMVCTesting.Tests.TestControllers;
namespace TestStack.FluentMVCTesting.Tests
{
partial class ControllerResultTestShould
{
[Test]
public void Check_for_content_result()
{
_controller.WithCallTo(c => c.Content()).ShouldReturnContent();
}
[Test]
public void Check_for_content_result_and_check_content()
{
_controller.WithCallTo(c => c.Content()).ShouldReturnContent(ControllerResultTestController.TextualContent);
}
[Test]
public void Check_for_content_result_and_check_invalid_content()
{
const string content = "dummy contents";
var exception = Assert.Throws<ActionResultAssertionException>(() => _controller.WithCallTo(c => c.Content()).ShouldReturnContent(content));
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected content to be '{0}', but instead was '{1}'.", content, ControllerResultTestController.TextualContent)));
}
[Test]
public void Check_for_content_result_and_check_content_and_check_content_type()
{
_controller.WithCallTo(c => c.Content()).ShouldReturnContent(ControllerResultTestController.TextualContent, ControllerResultTestController.ContentType);
}
[Test]
public void Check_for_content_result_and_check_content_and_check_invalid_content_type()
{
const string contentType = "application/dummy";
var exception = Assert.Throws<ActionResultAssertionException>(() => _controller.WithCallTo(c => c.Content()).ShouldReturnContent(ControllerResultTestController.TextualContent, contentType));
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected content type to be '{0}', but instead was '{1}'.", contentType, ControllerResultTestController.ContentType)));
}
[Test]
public void Check_for_content_result_and_check_content_and_check_content_type_and_check_content_encoding()
{
_controller.WithCallTo(c => c.Content()).ShouldReturnContent(ControllerResultTestController.TextualContent, ControllerResultTestController.ContentType, ControllerResultTestController.TextualContentEncoding);
}
[Test]
public void Check_for_content_result_and_check_content_and_check_content_type_and_check_invalid_content_encoding()
{
var encoding = Encoding.Unicode;
var exception = Assert.Throws<ActionResultAssertionException>(() => _controller.WithCallTo(c => c.Content()).ShouldReturnContent(ControllerResultTestController.TextualContent, ControllerResultTestController.ContentType, encoding));
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected encoding to be equal to {0}, but instead was {1}.", encoding.EncodingName, ControllerResultTestController.TextualContentEncoding.EncodingName)));
}
[Test]
public void Check_for_content_result_and_check_invalid_content_and_check_invalid_content_type_and_check_invalid_encoding()
{
const string contentType = "application/dummy";
const string content = "dumb";
Encoding encoding = Encoding.Unicode;
var exception = Assert.Throws<ActionResultAssertionException>(() => _controller.WithCallTo(c => c.Content()).ShouldReturnContent(content, contentType, encoding));
// Assert that the content type validation occurs before that of the actual content.
Assert.That(exception.Message.Contains("content type"));
}
[Test]
public void Emit_readable_error_message_when_the_actual_content_encoding_has_not_been_specified()
{
var exception = Assert.Throws<ActionResultAssertionException>(() => _controller.WithCallTo(c => c.ContentWithoutEncodingSpecified()).ShouldReturnContent(encoding: ControllerResultTestController.TextualContentEncoding));
Assert.That(exception.Message, Is.EqualTo($"Expected encoding to be equal to {ControllerResultTestController.TextualContentEncoding.EncodingName}, but instead was null."));
}
[Test]
public void Return_the_content_result()
{
var expected = (ContentResult)_controller.Content();
var actual = _controller.WithCallTo(c => c.Content())
.ShouldReturnContent(ControllerResultTestController.TextualContent);
Assert.That(actual.Content,Is.EqualTo(expected.Content));
Assert.That(actual.ContentType, Is.EqualTo(expected.ContentType));
Assert.That(actual.ContentEncoding, Is.EqualTo(expected.ContentEncoding));
}
}
}