Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Handle line ending differences in a few tests
Browse files Browse the repository at this point in the history
- #6205
- combine `TagHelpers_SupportsPathNavigation()` and `TagHelpers_SupportsRelativeNavigation()` into one

nit: remove a few unnecessary `.Trim()` calls
  • Loading branch information
dougbu committed Nov 29, 2017
1 parent 41104bf commit 6ae153a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
37 changes: 12 additions & 25 deletions test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorPagesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@ public async Task Page_SimpleForms_RenderAntiforgery()
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(expectedMediaType, response.Content.Headers.ContentType);

responseContent = responseContent.Trim();

var forgeryToken = AntiforgeryTestHelper.RetrieveAntiforgeryToken(responseContent, "SimpleForms");
#if GENERATE_BASELINES
// Reverse usual substitution and insert a format item into the new file content.
responseContent = responseContent.Replace(forgeryToken, "{0}");
ResourceFile.UpdateFile(_resourcesAssembly, outputFile, expectedContent, responseContent);
#else
expectedContent = string.Format(expectedContent, forgeryToken);
Assert.Equal(expectedContent.Trim(), responseContent, ignoreLineEndingDifferences: true);
Assert.Equal(expectedContent, responseContent.Trim(), ignoreLineEndingDifferences: true);
#endif
}

Expand Down Expand Up @@ -577,13 +575,14 @@ public async Task ViewStart_IsDiscoveredWhenRootDirectoryIsNotSpecified()
{
// Test for https://github.com/aspnet/Mvc/issues/5915
//Arrange
var expected = $"Hello from _ViewStart{Environment.NewLine}Hello from /Pages/WithViewStart/Index.cshtml!";
var expected = @"Hello from _ViewStart
Hello from /Pages/WithViewStart/Index.cshtml!";

// Act
var response = await Client.GetStringAsync("/Pages/WithViewStart");

// Assert
Assert.Equal(expected, response.Trim());
Assert.Equal(expected, response, ignoreLineEndingDifferences: true);
}

[Fact]
Expand Down Expand Up @@ -791,7 +790,7 @@ public async Task PagePropertiesAreInjected()
var response = await Client.GetStringAsync("InjectedPageProperties");

// Assert
Assert.Equal(expected, response.Trim());
Assert.Equal(expected, response.Trim(), ignoreLineEndingDifferences: true);
}

[Fact]
Expand Down Expand Up @@ -968,60 +967,48 @@ public async Task TagHelpers_SupportSiblingRoutes()
{
// Arrange
var expected =
@"<form method=""post"" action=""/Pages/TagHelper/CrossPost""></form>
@"<form method=""post"" action=""/Pages/TagHelper/CrossPost""></form>
<a href=""/Pages/TagHelper/SelfPost/12"" />
<input type=""image"" formaction=""/Pages/TagHelper/CrossPost#my-fragment"" />";

// Act
var response = await Client.GetStringAsync("/Pages/TagHelper/SiblingLinks");

// Assert
Assert.Equal(expected, response.Trim());
Assert.Equal(expected, response.Trim(), ignoreLineEndingDifferences: true);
}

[Fact]
public async Task TagHelpers_SupportSubDirectoryRoutes()
{
// Arrange
var expected =
@"<form method=""post"" action=""/Pages/TagHelper/SubDir/SubDirPage""></form>
@"<form method=""post"" action=""/Pages/TagHelper/SubDir/SubDirPage""></form>
<a href=""/Pages/TagHelper/SubDir/SubDirPage/12"" />
<input type=""image"" formaction=""/Pages/TagHelper/SubDir/SubDirPage#my-fragment"" />";

// Act
var response = await Client.GetStringAsync("/Pages/TagHelper/SubDirectoryLinks");

// Assert
Assert.Equal(expected, response.Trim());
Assert.Equal(expected, response.Trim(), ignoreLineEndingDifferences: true);
}

[Fact]
public async Task TagHelpers_SupportsPathNavigation()
{
// Arrange
var expected =
@"<form method=""post"" action=""/HelloWorld""></form>
@"<form method=""post"" action=""/Pages/TagHelper/SubDirectoryLinks""></form>
<form method=""post"" action=""/HelloWorld""></form>
<a href=""/Pages/Redirects/RedirectToIndex"" />
<input type=""image"" formaction=""/Pages/Admin#my-fragment"" />";

// Act
var response = await Client.GetStringAsync("/Pages/TagHelper/PathTraversalLinks");

// Assert
Assert.EndsWith(expected, response.Trim());
}

[Fact]
public async Task TagHelpers_SupportsRelativeNavigation()
{
// Arrange
var expected = @"<form method=""post"" action=""/Pages/TagHelper/SubDirectoryLinks""></form>";

// Act
var response = await Client.GetStringAsync("/Pages/TagHelper/PathTraversalLinks");

// Assert
Assert.StartsWith(expected, response.Trim());
Assert.Equal(expected, response.Trim(), ignoreLineEndingDifferences: true);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
Expand Down Expand Up @@ -130,27 +129,29 @@ public async Task ViewStart_IsDiscoveredWhenRootDirectoryIsSpecified()
{
// Test for https://github.com/aspnet/Mvc/issues/5915
//Arrange
var expected = $"Hello from _ViewStart{Environment.NewLine}Hello from /Pages/WithViewStart/Index.cshtml!";
var expected = @"Hello from _ViewStart
Hello from /Pages/WithViewStart/Index.cshtml!";

// Act
var response = await Client.GetStringAsync("/WithViewStart");

// Assert
Assert.Equal(expected, response.Trim());
Assert.Equal(expected, response, ignoreLineEndingDifferences: true);
}

[Fact]
public async Task ViewStart_IsDiscoveredForFilesOutsidePageRoot()
{
//Arrange
var newLine = Environment.NewLine;
var expected = $"Hello from _ViewStart at root{newLine}Hello from _ViewStart{newLine}Hello from page";
var expected = @"Hello from _ViewStart at root
Hello from _ViewStart
Hello from page";

// Act
var response = await Client.GetStringAsync("/WithViewStart/ViewStartAtRoot");

// Assert
Assert.Equal(expected, response.Trim());
Assert.Equal(expected, response.Trim(), ignoreLineEndingDifferences: true);
}

[Fact]
Expand Down Expand Up @@ -212,14 +213,14 @@ public async Task FormTagHelper_WithPage_AllowsPostingToAnotherPage()
var response = await Client.GetStringAsync("/TagHelper/CrossPost");

// Assert
Assert.Equal(expected, response.Trim());
Assert.Equal(expected, response.Trim(), ignoreLineEndingDifferences: true);
}

[Fact]
public async Task FormActionTagHelper_WithPage_AllowsPostingToAnotherPage()
{
//Arrange
var expected =
var expected =
@"<button formaction=""/TagHelper/CrossPost/10"" />
<input type=""submit"" formaction=""/TagHelper/CrossPost/10"" />
<input type=""image"" formaction=""/TagHelper/CrossPost/10"" />
Expand All @@ -231,7 +232,7 @@ public async Task FormActionTagHelper_WithPage_AllowsPostingToAnotherPage()
var response = await Client.GetStringAsync("/TagHelper/FormAction");

// Assert
Assert.Equal(expected, response.Trim());
Assert.Equal(expected, response, ignoreLineEndingDifferences: true);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public async Task RazorView_SetsViewPathAndExecutingPagePath()
public async Task ViewEngine_NormalizesPathsReturnedByViewLocationExpanders()
{
// Arrange
var expected =
var expected =
@"Layout
Page
Partial";
Expand All @@ -498,7 +498,7 @@ public async Task ViewEngine_NormalizesPathsReturnedByViewLocationExpanders()
var responseContent = await Client.GetStringAsync("/BackSlash");

// Assert
Assert.Equal(expected, responseContent.Trim());
Assert.Equal(expected, responseContent, ignoreLineEndingDifferences: true);
}

[Fact]
Expand Down

0 comments on commit 6ae153a

Please sign in to comment.