Cleanup Identity functional tests

This commit is contained in:
Javier Calvarro Nelson 2018-02-18 09:23:02 -08:00
parent 3e30d52055
commit 5572955414
26 changed files with 126 additions and 79 deletions

View File

@ -234,6 +234,7 @@ Global
{D5FB2E24-4C71-430C-A289-59C8D59164B0}.Debug|x64.ActiveCfg = Debug|Any CPU
{D5FB2E24-4C71-430C-A289-59C8D59164B0}.Debug|x64.Build.0 = Debug|Any CPU
{D5FB2E24-4C71-430C-A289-59C8D59164B0}.Debug|x86.ActiveCfg = Debug|Any CPU
{D5FB2E24-4C71-430C-A289-59C8D59164B0}.Debug|x86.Build.0 = Debug|Any CPU
{D5FB2E24-4C71-430C-A289-59C8D59164B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5FB2E24-4C71-430C-A289-59C8D59164B0}.Release|Any CPU.Build.0 = Release|Any CPU
{D5FB2E24-4C71-430C-A289-59C8D59164B0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
@ -281,6 +282,7 @@ Global
{EA424B4D-0BE1-49AC-A106-CC6CC808A104}.Debug|x64.ActiveCfg = Debug|Any CPU
{EA424B4D-0BE1-49AC-A106-CC6CC808A104}.Debug|x64.Build.0 = Debug|Any CPU
{EA424B4D-0BE1-49AC-A106-CC6CC808A104}.Debug|x86.ActiveCfg = Debug|Any CPU
{EA424B4D-0BE1-49AC-A106-CC6CC808A104}.Debug|x86.Build.0 = Debug|Any CPU
{EA424B4D-0BE1-49AC-A106-CC6CC808A104}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA424B4D-0BE1-49AC-A106-CC6CC808A104}.Release|Any CPU.Build.0 = Release|Any CPU
{EA424B4D-0BE1-49AC-A106-CC6CC808A104}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU

View File

@ -6,8 +6,15 @@ using Xunit;
namespace Microsoft.AspNetCore.Identity.FunctionalTests
{
public class AuthorizationTests
public class AuthorizationTests : IClassFixture<ServerFactory>
{
public AuthorizationTests(ServerFactory serverFactory)
{
ServerFactory = serverFactory;
}
public ServerFactory ServerFactory { get; }
public static TheoryData<string> AuthorizedPages =>
new TheoryData<string>
{
@ -86,10 +93,10 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
// /Identity/Account/LoginWith2fa
// /Identity/Account/ExternalLogin
// /Identity/Account/ConfirmEmail
// /Identity/Account/ResetPassword,
public static TheoryData<string> UnauthorizedPages =>
new TheoryData<string>
{
"/Identity/Account/ResetPassword",
"/Identity/Account/Login",
"/Identity/Account/Lockout",
"/Identity/Account/ForgotPasswordConfirmation",

View File

@ -1,20 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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.
namespace Microsoft.AspNetCore.Identity.FunctionalTests
{
public class DefaultUIContext : HtmlPageContext
{
public DefaultUIContext()
{
}
public DefaultUIContext() { }
public DefaultUIContext(DefaultUIContext currentContext)
: base(currentContext)
{
}
public DefaultUIContext(DefaultUIContext currentContext) : base(currentContext) { }
public DefaultUIContext WithAuthenticatedUser() =>
new DefaultUIContext(this) { UserAuthenticated = true };

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
// 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.Net.Http;
using System.Text;
using AngleSharp.Dom.Html;
namespace Microsoft.AspNetCore.Identity.FunctionalTests

View File

@ -9,13 +9,12 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
{
private readonly IDictionary<string, object> _properties;
protected HtmlPageContext()
: this(new Dictionary<string, object>())
protected HtmlPageContext() : this(new Dictionary<string, object>())
{
}
protected HtmlPageContext(HtmlPageContext currentContext)
: this(new Dictionary<string,object>(currentContext._properties))
: this(new Dictionary<string, object>(currentContext._properties))
{
}
@ -26,6 +25,7 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
protected TValue GetValue<TValue>(string key) =>
_properties.TryGetValue(key, out var rawValue) ? (TValue)rawValue : default;
protected void SetValue(string key, object value) =>
_properties[key] = value;
}

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Runtime.CompilerServices;
@ -12,9 +13,12 @@ using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Identity.FunctionalTests
{
public class ServerFactory
public class ServerFactory : IDisposable
{
public static TestServer CreateServer(
private bool disposedValue = false;
private IList<IDisposable> _disposableServers = new List<IDisposable>();
public TestServer CreateServer(
Action<IWebHostBuilder> configureBuilder,
[CallerMemberName] string isolationKey = "")
{
@ -30,13 +34,14 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
configureBuilder(builder);
var server = new TestServer(builder);
_disposableServers.Add(server);
return server;
}
public static TestServer CreateDefaultServer([CallerMemberName] string isolationKey = "") =>
public TestServer CreateDefaultServer([CallerMemberName] string isolationKey = "") =>
CreateServer(b => { }, isolationKey);
public static HttpClient CreateDefaultClient(TestServer server)
public HttpClient CreateDefaultClient(TestServer server)
{
var client = new HttpClient(new CookieContainerHandler(server.CreateHandler()))
{
@ -46,7 +51,29 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
return client;
}
public static HttpClient CreateDefaultClient() =>
public HttpClient CreateDefaultClient() =>
CreateDefaultClient(CreateDefaultServer());
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
foreach (var disposable in _disposableServers)
{
disposable?.Dispose();
}
}
_disposableServers = null;
disposedValue = true;
}
}
public void Dispose()
{
Dispose(true);
}
}
}

View File

@ -4,17 +4,21 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using AngleSharp.Dom.Html;
using Identity.DefaultUI.WebSite.Services;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.Extensions.DependencyInjection;
using Identity.DefaultUI.WebSite;
using Xunit;
using Xunit.Sdk;
namespace Microsoft.AspNetCore.Identity.FunctionalTests
{
public class LoginTests
public class LoginTests : IClassFixture<ServerFactory>
{
public LoginTests(ServerFactory serverFactory)
{
ServerFactory = serverFactory;
}
public ServerFactory ServerFactory { get; }
[Fact]
public async Task CanLogInWithAPreviouslyRegisteredUser()
{

View File

@ -3,13 +3,20 @@
using System;
using System.Threading.Tasks;
using Identity.DefaultUI.WebSite.Services;
using Identity.DefaultUI.WebSite;
using Xunit;
namespace Microsoft.AspNetCore.Identity.FunctionalTests
{
public class ManagementTests
public class ManagementTests : IClassFixture<ServerFactory>
{
public ManagementTests(ServerFactory serverFactory)
{
ServerFactory = serverFactory;
}
public ServerFactory ServerFactory { get; }
[Fact]
public async Task CanEnableTwoFactorAuthentication()
{

View File

@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
// 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.Net.Http;
using System.Text;
using System.Threading.Tasks;
using AngleSharp.Dom.Html;
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Pages.Account
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account
{
public class ConfirmEmail : DefaultUIPage
{

View File

@ -1,11 +1,12 @@
using System;
// 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.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using AngleSharp.Dom.Html;
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Pages.Account
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account
{
public class ExternalLogin : DefaultUIPage
{

View File

@ -1,7 +1,8 @@
using System;
// 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.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using AngleSharp.Dom.Html;

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
// 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.Net.Http;
using System.Text;
using AngleSharp.Dom.Html;
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account

View File

@ -5,7 +5,6 @@ using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using AngleSharp.Dom.Html;
using Microsoft.AspNetCore.Identity.FunctionalTests.Pages.Account;
using Xunit;
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account

View File

@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account
var indexPage = await Client.GetAsync(goToIndex);
var index = await ResponseAssert.IsHtmlDocumentAsync(indexPage);
return new Index(Client, index, new DefaultUIContext(Context) { UserAuthenticated = true });
return new Index(Client, index, Context.WithAuthenticatedUser());
}
}
}

View File

@ -1,11 +1,12 @@
using System;
// 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.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using AngleSharp.Dom.Html;
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Pages.Account
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account
{
public class ResetPassword : DefaultUIPage
{

View File

@ -1,7 +1,10 @@
using System.Net.Http;
// 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.Net.Http;
using AngleSharp.Dom.Html;
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Pages.Account
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account
{
public class ResetPasswordConfirmation : DefaultUIPage
{

View File

@ -1,10 +1,11 @@
using System;
// 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.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using AngleSharp.Dom.Html;
using Microsoft.AspNetCore.Identity.FunctionalTests.Pages.Account;
using Microsoft.AspNetCore.Identity.FunctionalTests.Account;
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Contoso
{

View File

@ -7,8 +7,15 @@ using Xunit;
namespace Microsoft.AspNetCore.Identity.FunctionalTests
{
public class RegistrationTests
public class RegistrationTests : IClassFixture<ServerFactory>
{
public RegistrationTests(ServerFactory serverFactory)
{
ServerFactory = serverFactory;
}
public ServerFactory ServerFactory { get; }
[Fact]
public async Task CanRegisterAUser()
{

View File

@ -5,10 +5,9 @@ using System;
using System.Net.Http;
using System.Threading.Tasks;
using AngleSharp.Dom.Html;
using Identity.DefaultUI.WebSite.Services;
using Identity.DefaultUI.WebSite;
using Microsoft.AspNetCore.Identity.FunctionalTests.Account;
using Microsoft.AspNetCore.Identity.FunctionalTests.Account.Manage;
using Microsoft.AspNetCore.Identity.FunctionalTests.Pages.Account;
using Xunit;
namespace Microsoft.AspNetCore.Identity.FunctionalTests

View File

@ -2,9 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
// 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 Microsoft.EntityFrameworkCore.Migrations;
namespace Identity.DefaultUI.WebSite.Data.Migrations

View File

@ -1,13 +1,12 @@
// <auto-generated />
// 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.
// <auto-generated />
using System;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
namespace Identity.DefaultUI.WebSite.Data.Migrations
{

View File

@ -11,9 +11,9 @@ namespace Identity.DefaultUI.WebSite
public static AuthenticationBuilder AddContosoAuthentication(
this AuthenticationBuilder builder,
Action<ContosoAuthenticationOptions> configure) =>
builder.AddScheme<ContosoAuthenticationOptions, ContosoAuthenticationHandler>(
ContosoAuthenticationConstants.Scheme,
ContosoAuthenticationConstants.DisplayName,
configure);
builder.AddScheme<ContosoAuthenticationOptions, ContosoAuthenticationHandler>(
ContosoAuthenticationConstants.Scheme,
ContosoAuthenticationConstants.DisplayName,
configure);
}
}

View File

@ -1,10 +1,11 @@
using System;
// 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.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity.UI.Services;
namespace Identity.DefaultUI.WebSite.Services
namespace Identity.DefaultUI.WebSite
{
public class ContosoEmailSender : IEmailSender
{

View File

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
// 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.
namespace Identity.DefaultUI.WebSite.Services
namespace Identity.DefaultUI.WebSite
{
public class IdentityEmail
{

View File

@ -1,7 +1,6 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-Identity.DefaultUI.WebSite-90455f3b-6c48-4aa0-a8d6-294d8e0b3d4d;Trusted_Connection=True;MultipleActiveResultSets=true"
//"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-Identity.DefaultUI.WebSite-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"LogLevel": {