This repository has been archived by the owner on Apr 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac9e1b4
commit 00f7b3f
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
|
||
namespace DynamoLeagueBlazor.Tests; | ||
|
||
public class RedirectTests | ||
{ | ||
[Fact] | ||
public async Task GivenAnyRequest_WhenIsHttp_ThenIsRedirectedToHttps() | ||
{ | ||
var webApplicationFactory = new WebApplicationFactory<Program>(); | ||
|
||
var client = webApplicationFactory.CreateClient(new WebApplicationFactoryClientOptions | ||
{ | ||
AllowAutoRedirect = false, | ||
BaseAddress = new Uri("http://www.test.com") | ||
}); | ||
|
||
var response = await client.GetAsync(string.Empty); | ||
|
||
response.Headers.Location!.Scheme.Should().Be("https"); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenAnyRequest_WhenIsNotWww_ThenIsRedirectedToWww() | ||
{ | ||
var webApplicationFactory = new WebApplicationFactory<Program>(); | ||
|
||
var client = webApplicationFactory.CreateClient(new WebApplicationFactoryClientOptions | ||
{ | ||
AllowAutoRedirect = false, | ||
BaseAddress = new Uri("https://test.com") | ||
}); | ||
|
||
var response = await client.GetAsync(string.Empty); | ||
|
||
response.Headers.Location!.AbsoluteUri.Should().Contain("www"); | ||
} | ||
} |