Skip to content

Commit 0b6d640

Browse files
committed
Readability tweaks.
Removed superflous using directives. Moved test method into appropriate region. Indented if statement (as per code review.) Removed unintended whitespace between region. Corrected test name. Corrected errant test body formatting.
1 parent e17744c commit 0b6d640

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq;
44
using System.Linq.Expressions;
55
using System.Net;
6-
using System.Text.RegularExpressions;
76
using System.Web.Mvc;
87
using NUnit.Framework;
98
using TestStack.FluentMVCTesting.Tests.TestControllers;
@@ -317,8 +316,6 @@ public void Check_for_invalid_partial_name()
317316
}
318317
#endregion
319318

320-
321-
322319
#region File tests
323320

324321
[Test]
@@ -427,7 +424,7 @@ public void Check_for_file_content_result_and_check_textual_content_and_check_co
427424
}
428425

429426
[Test]
430-
public void Check_for_file_content_result_and_check_textual_content_and_check_invalid_content_result()
427+
public void Check_for_file_content_result_and_check_textual_content_and_check_invalid_content_typet()
431428
{
432429
const string contentType = "application/dummy";
433430

@@ -438,7 +435,7 @@ public void Check_for_file_content_result_and_check_textual_content_and_check_in
438435
}
439436

440437
[Test]
441-
public void Check_for_file_content_result_and_check_invalid_textual_content_and_check_invalid_content_result()
438+
public void Check_for_file_content_result_and_check_invalid_textual_content_and_check_invalid_content_type()
442439
{
443440
const string contents = "dummy content";
444441
const string contentType = "application/dummy";
@@ -471,9 +468,7 @@ public void Check_for_file_content_result_and_check_textual_content_using_given_
471468
public void Check_for_file_content_result_and_check_textual_content_using_invalid_given_char_encoding()
472469
{
473470
Assert.Throws<ActionResultAssertionException>(() =>
474-
_controller.WithCallTo(c => c.TextualFile())
475-
.ShouldRenderFileContents(ControllerResultTestController.TextualFileContents,
476-
ControllerResultTestController.FileContentType, Encoding.BigEndianUnicode));
471+
_controller.WithCallTo(c => c.TextualFile()).ShouldRenderFileContents(ControllerResultTestController.TextualFileContents, ControllerResultTestController.FileContentType, Encoding.BigEndianUnicode));
477472
}
478473

479474
[Test]

TestStack.FluentMvcTesting/ControllerResultTest.cs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
using System.Linq.Expressions;
44
using System.Net;
55
using System.Reflection;
6-
using System.Runtime.InteropServices;
76
using System.Text;
87
using System.Text.RegularExpressions;
98
using System.Web.Mvc;
109
using System.Web.Routing;
11-
using System.Web.UI.WebControls;
1210

1311
namespace TestStack.FluentMVCTesting
1412
{
@@ -216,27 +214,6 @@ public ViewResultTest ShouldRenderDefaultPartialView()
216214

217215
#endregion
218216

219-
public FileContentResult ShouldRenderFileContents(string contents, string contentType = null, Encoding encoding = null)
220-
{
221-
ValidateActionReturnType<FileContentResult>();
222-
223-
var fileResult = (FileContentResult) _actionResult;
224-
225-
if (contentType != null && fileResult.ContentType != contentType)
226-
{
227-
throw new ActionResultAssertionException(string.Format("Expected file to be of content type '{0}', but instead was given '{1}'.", contentType, fileResult.ContentType));
228-
}
229-
230-
if (encoding == null) encoding = Encoding.UTF8;
231-
var reconstitutedText = encoding.GetString(fileResult.FileContents);
232-
if (contents != reconstitutedText)
233-
{
234-
throw new ActionResultAssertionException(string.Format("Expected file contents to be \"{0}\", but instead was \"{1}\".", contents, reconstitutedText));
235-
}
236-
237-
return fileResult;
238-
}
239-
240217
#region File Results
241218

242219
public FileResult ShouldRenderAnyFile(string contentType = null)
@@ -275,6 +252,31 @@ public FileContentResult ShouldRenderFileContents(byte[] contents = null, string
275252
return fileResult;
276253
}
277254

255+
public FileContentResult ShouldRenderFileContents(string contents, string contentType = null, Encoding encoding = null)
256+
{
257+
ValidateActionReturnType<FileContentResult>();
258+
259+
var fileResult = (FileContentResult)_actionResult;
260+
261+
if (contentType != null && fileResult.ContentType != contentType)
262+
{
263+
throw new ActionResultAssertionException(
264+
string.Format("Expected file to be of content type '{0}', but instead was given '{1}'.", contentType,
265+
fileResult.ContentType));
266+
}
267+
268+
if (encoding == null)
269+
encoding = Encoding.UTF8;
270+
271+
var reconstitutedText = encoding.GetString(fileResult.FileContents);
272+
if (contents != reconstitutedText)
273+
{
274+
throw new ActionResultAssertionException(string.Format("Expected file contents to be \"{0}\", but instead was \"{1}\".", contents, reconstitutedText));
275+
}
276+
277+
return fileResult;
278+
}
279+
278280
[Obsolete("Obsolete: Use ShouldRenderFileContents instead.")]
279281
public FileContentResult ShouldRenderFile(string contentType = null)
280282
{

0 commit comments

Comments
 (0)