-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathPhysicalFileResultAssertions_Tests.cs
161 lines (128 loc) · 7.52 KB
/
PhysicalFileResultAssertions_Tests.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using FluentAssertions.Mvc.Tests.Helpers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;
using System;
using System.Globalization;
using Xunit;
namespace FluentAssertions.AspNetCore.Mvc.Tests
{
public class PhysicalFileResultAssertions_Tests
{
public const string Reason = FailureMessageHelper.Reason;
public readonly static object[] ReasonArgs = FailureMessageHelper.ReasonArgs;
private const string TestPhysicalPath = "TestPhysicalPath";
private const string TestContentType = "text/html";
private const string TestFileDownloadName = "TestFileDownloadName";
private readonly DateTimeOffset? TestLastModified = DateTimeOffset.Parse("2020-04-28 15:48:33.6672395 +2", CultureInfo.InvariantCulture);
private readonly EntityTagHeaderValue TestEntityTag = new EntityTagHeaderValue("\"0815\"");
[Fact]
public void WithPhysicalPath_GivenExpected_ShouldPass()
{
ActionResult result = new PhysicalFileResult(TestPhysicalPath, TestContentType);
result.Should().BePhysicalFileResult().WithPhysicalPath(TestPhysicalPath);
}
[Fact]
public void WithPhysicalPath_GivenUnexpected_ShouldFail()
{
var actualPhysicalPath = TestPhysicalPath;
var expectedPhysicalPath = "xyz";
ActionResult result = new PhysicalFileResult(actualPhysicalPath, TestContentType);
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("PhysicalFileResult.PhysicalPath", expectedPhysicalPath, actualPhysicalPath);
Action a = () => result.Should().BePhysicalFileResult().WithPhysicalPath(expectedPhysicalPath, Reason, ReasonArgs);
a.Should().Throw<Exception>().WithMessage(failureMessage);
}
[Fact]
public void WithContentType_GivenExpected_ShouldPass()
{
ActionResult result = new PhysicalFileResult(string.Empty, TestContentType);
result.Should().BePhysicalFileResult().WithContentType(TestContentType);
}
[Fact]
public void WithContentType_GivenUnexpected_ShouldFail()
{
var actualContentType = TestContentType;
var expectedContentType = "xyz";
ActionResult result = new PhysicalFileResult(string.Empty, actualContentType);
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("PhysicalFileResult.ContentType", expectedContentType, actualContentType);
Action a = () => result.Should().BePhysicalFileResult().WithContentType(expectedContentType, Reason, ReasonArgs);
a.Should().Throw<Exception>().WithMessage(failureMessage);
}
[Fact]
public void WithFileDownloadName_GivenExpected_ShouldPass()
{
ActionResult result = new PhysicalFileResult(string.Empty, TestContentType) { FileDownloadName = TestFileDownloadName };
result.Should().BePhysicalFileResult().WithFileDownloadName(TestFileDownloadName);
}
[Fact]
public void WithFileDownloadName_GivenUnexpected_ShouldFail()
{
var actualFileDownloadName = TestFileDownloadName;
var expectedFileDownloadName = "xyz";
ActionResult result = new PhysicalFileResult(string.Empty, TestContentType) { FileDownloadName = actualFileDownloadName };
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("PhysicalFileResult.FileDownloadName", expectedFileDownloadName, actualFileDownloadName);
Action a = () => result.Should().BePhysicalFileResult().WithFileDownloadName(expectedFileDownloadName, Reason, ReasonArgs);
a.Should().Throw<Exception>().WithMessage(failureMessage);
}
[Fact]
public void WithLastModified_GivenExpected_ShouldPass()
{
ActionResult result = new PhysicalFileResult(string.Empty, TestContentType) { LastModified = TestLastModified };
result.Should().BePhysicalFileResult().WithLastModified(TestLastModified);
}
[Fact]
public void WithLastModified_GivenNull_ShouldPass()
{
var actualLastModified = null as DateTimeOffset?;
var expectedLastModified = null as DateTimeOffset?;
ActionResult result = new PhysicalFileResult(string.Empty, TestContentType) { LastModified = actualLastModified };
result.Should().BePhysicalFileResult().WithLastModified(expectedLastModified);
}
[Fact]
public void WithLastModified_GivenActualNull_ShouldFail()
{
var actualLastModified = null as DateTimeOffset?;
var expectedLastModified = TestLastModified;
ActionResult result = new PhysicalFileResult(string.Empty, TestContentType) { LastModified = actualLastModified };
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("PhysicalFileResult.LastModified", expectedLastModified, actualLastModified);
Action a = () => result.Should().BePhysicalFileResult().WithLastModified(expectedLastModified, Reason, ReasonArgs);
a.Should().Throw<Exception>().WithMessage(failureMessage);
}
[Fact]
public void WithLastModified_GivenExpectedNull_ShouldFail()
{
var actualLastModified = TestLastModified;
var expectedLastModified = null as DateTimeOffset?;
ActionResult result = new PhysicalFileResult(string.Empty, TestContentType) { LastModified = actualLastModified };
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("PhysicalFileResult.LastModified", expectedLastModified, actualLastModified);
Action a = () => result.Should().BePhysicalFileResult().WithLastModified(expectedLastModified, Reason, ReasonArgs);
a.Should().Throw<Exception>().WithMessage(failureMessage);
}
[Fact]
public void WithLastModified_GivenUnexpected_ShouldFail()
{
var actualLastModified = TestLastModified;
var expectedLastModified = TestLastModified.Value.AddMilliseconds(1);
ActionResult result = new PhysicalFileResult(string.Empty, TestContentType) { LastModified = actualLastModified };
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("PhysicalFileResult.LastModified", expectedLastModified, actualLastModified);
Action a = () => result.Should().BePhysicalFileResult().WithLastModified(expectedLastModified, Reason, ReasonArgs);
a.Should().Throw<Exception>().WithMessage(failureMessage);
}
[Fact]
public void WithEntityTag_GivenExpected_ShouldPass()
{
ActionResult result = new PhysicalFileResult(string.Empty, TestContentType) { EntityTag = TestEntityTag };
result.Should().BePhysicalFileResult().WithEntityTag(TestEntityTag);
}
[Fact]
public void WithEntityTag_GivenUnexpected_ShouldFail()
{
var actualEntityTag = TestEntityTag;
var expectedEntityTag = new EntityTagHeaderValue("\"1234\"");
ActionResult result = new PhysicalFileResult(string.Empty, TestContentType) { EntityTag = actualEntityTag };
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("PhysicalFileResult.EntityTag", expectedEntityTag, actualEntityTag);
Action a = () => result.Should().BePhysicalFileResult().WithEntityTag(expectedEntityTag, Reason, ReasonArgs);
a.Should().Throw<Exception>()
.WithMessage(failureMessage);
}
}
}