Skip to content
This repository has been archived by the owner on Feb 6, 2025. It is now read-only.

Commit

Permalink
Added (very) basic functional tests (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellenfieldn authored May 12, 2019
1 parent e4b73cb commit 45d8204
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
31 changes: 31 additions & 0 deletions IdentityServer4.WsFederation.Tests/Functional/MetadataTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using IdentityServer4.WsFederation.Server;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace IdentityServer4.WsFederation.Tests.Functional
{
[TestClass]
public class MetadataTests
{
private readonly HttpClient _client;

public MetadataTests()
{
var factory = new WebApplicationFactory<Program>();
_client = factory.CreateClient();
}

[TestMethod]
public async Task MetadataSuccess()
{
var response = await _client.GetAsync("/wsfederation/metadata");
var content = await response.Content.ReadAsStringAsync();

Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
StringAssert.Contains(content, "<md:EntityDescriptor entityID=\"urn:idsrv4:wsfed:server:sample\" xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\">");
}
}
}
32 changes: 32 additions & 0 deletions IdentityServer4.WsFederation.Tests/Functional/SigninTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using IdentityServer4.WsFederation.Server;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace IdentityServer4.WsFederation.Tests.Functional
{
[TestClass]
public class SigninTests
{
private readonly HttpClient _client;

public SigninTests()
{
var factory = new WebApplicationFactory<Program>();
_client = factory.CreateClient();
}

[TestMethod]
public async Task SigninWithNoContextRedirectsToLogin()
{
var response = await _client.GetAsync("/wsfederation/signin?wa=wsignin1.0&wtrealm=urn:idsrv4:wsfed:sample");
var content = await response.Content.ReadAsStringAsync();

Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
Assert.AreEqual("/Account/Login", response.RequestMessage.RequestUri.LocalPath);
StringAssert.Contains(content, "<h1>Login</h1>");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.1.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
Expand All @@ -27,6 +28,7 @@

<ItemGroup>
<ProjectReference Include="..\src\IdentityServer4.WsFederation\IdentityServer4.WsFederation.csproj" />
<ProjectReference Include="..\src\SampleServer\IdentityServer4.WsFederation.Server\IdentityServer4.WsFederation.Server.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHost BuildWebHost(string[] args) =>
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
.UseStartup<Startup>();
}
}

0 comments on commit 45d8204

Please sign in to comment.