Skip to content

Commit 974b58e

Browse files
committed
Add a register test
1 parent 109f882 commit 974b58e

File tree

6 files changed

+62
-10
lines changed

6 files changed

+62
-10
lines changed

src/Identity/UI/src/Areas/Identity/Pages/V3/Account/Register.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<div class="row">
1010
<div class="col-md-4">
11-
<form id="register" asp-route-returnUrl="@Model.ReturnUrl" method="post">
11+
<form id="registerForm" asp-route-returnUrl="@Model.ReturnUrl" method="post">
1212
<h4>Create a new account.</h4>
1313
<hr />
1414
<div asp-validation-summary="All" class="text-danger"></div>
@@ -27,7 +27,7 @@
2727
<input asp-for="Input.ConfirmPassword" class="form-control" />
2828
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
2929
</div>
30-
<button type="submit" class="btn btn-default">Register</button>
30+
<button id="registerSubmit" type="submit" class="btn btn-default">Register</button>
3131
</form>
3232
</div>
3333
<div class="col-md-6 col-md-offset-2">

src/Identity/UI/src/Areas/Identity/Pages/V4/Account/Register.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<div class="row">
1010
<div class="col-md-4">
11-
<form id="register" asp-route-returnUrl="@Model.ReturnUrl" method="post">
11+
<form id="registerForm" asp-route-returnUrl="@Model.ReturnUrl" method="post">
1212
<h4>Create a new account.</h4>
1313
<hr />
1414
<div asp-validation-summary="All" class="text-danger"></div>
@@ -27,7 +27,7 @@
2727
<input asp-for="Input.ConfirmPassword" class="form-control" />
2828
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
2929
</div>
30-
<button type="submit" class="btn btn-primary">Register</button>
30+
<button id="registerSubmit" type="submit" class="btn btn-primary">Register</button>
3131
</form>
3232
</div>
3333
<div class="col-md-6 col-md-offset-2">

src/Identity/test/Identity.FunctionalTests/ManagementTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;

src/Identity/test/Identity.FunctionalTests/Pages/Account/Register.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Collections.Generic;
@@ -12,11 +12,29 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account
1212
public class Register : DefaultUIPage
1313
{
1414
private IHtmlFormElement _registerForm;
15+
private IHtmlFormElement _externalLoginForm;
16+
private readonly IHtmlElement _contosoButton;
1517

1618
public Register(HttpClient client, IHtmlDocument register, DefaultUIContext context)
1719
: base(client, register, context)
1820
{
19-
_registerForm = HtmlAssert.HasForm("#register", register);
21+
_registerForm = HtmlAssert.HasForm("#registerForm", register);
22+
if (context.ContosoLoginEnabled)
23+
{
24+
_externalLoginForm = HtmlAssert.HasForm("#external-account", register);
25+
_contosoButton = HtmlAssert.HasElement("button[value=Contoso]", register);
26+
}
27+
}
28+
29+
public async Task<Contoso.Login> ClickLoginWithContosoLinkAsync()
30+
{
31+
var externalFormResponse = await Client.SendAsync(_externalLoginForm, _contosoButton);
32+
var goToContosoLogin = ResponseAssert.IsRedirect(externalFormResponse);
33+
var contosoLoginResponse = await Client.GetAsync(goToContosoLogin);
34+
35+
var contosoLogin = await ResponseAssert.IsHtmlDocumentAsync(contosoLoginResponse);
36+
37+
return new Contoso.Login(Client, contosoLogin, Context);
2038
}
2139

2240
public async Task<Index> SubmitRegisterFormForValidUserAsync(string userName, string password)

src/Identity/test/Identity.FunctionalTests/RegistrationTests.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -56,7 +56,7 @@ void ConfigureTestServices(IServiceCollection services) =>
5656
}
5757

5858
[Fact]
59-
public async Task CanRegisterWithASocialLoginProvider()
59+
public async Task CanRegisterWithASocialLoginProviderFromLogin()
6060
{
6161
// Arrange
6262
void ConfigureTestServices(IServiceCollection services) =>
@@ -75,6 +75,26 @@ void ConfigureTestServices(IServiceCollection services) =>
7575
await UserStories.RegisterNewUserWithSocialLoginAsync(client, userName, email);
7676
}
7777

78+
[Fact]
79+
public async Task CanRegisterWithASocialLoginProviderFromRegister()
80+
{
81+
// Arrange
82+
void ConfigureTestServices(IServiceCollection services) =>
83+
services
84+
.SetupTestThirdPartyLogin();
85+
86+
var client = ServerFactory
87+
.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
88+
.CreateClient();
89+
90+
var guid = Guid.NewGuid();
91+
var userName = $"{guid}";
92+
var email = $"{guid}@example.com";
93+
94+
// Act & Assert
95+
await UserStories.RegisterNewUserWithSocialLoginAsyncViaRegisterPage(client, userName, email);
96+
}
97+
7898
[Fact]
7999
public async Task CanRegisterWithASocialLoginProvider_WithGlobalAuthorizeFilter()
80100
{

src/Identity/test/Identity.FunctionalTests/UserStories.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -55,6 +55,7 @@ internal static async Task<DefaultUIPage> LockoutExistingUserAsync(HttpClient cl
5555
return await login.LockoutUserAsync(userName, password);
5656
}
5757

58+
// This is via login page
5859
internal static async Task<Index> RegisterNewUserWithSocialLoginAsync(HttpClient client, string userName, string email)
5960
{
6061
var index = await Index.CreateAsync(client, new DefaultUIContext().WithSocialLoginEnabled());
@@ -68,6 +69,19 @@ internal static async Task<Index> RegisterNewUserWithSocialLoginAsync(HttpClient
6869
return await externalLogin.SendEmailAsync(email);
6970
}
7071

72+
internal static async Task<Index> RegisterNewUserWithSocialLoginAsyncViaRegisterPage(HttpClient client, string userName, string email)
73+
{
74+
var index = await Index.CreateAsync(client, new DefaultUIContext().WithSocialLoginEnabled());
75+
76+
var register = await index.ClickRegisterLinkAsync();
77+
78+
var contosoLogin = await register.ClickLoginWithContosoLinkAsync();
79+
80+
var externalLogin = await contosoLogin.SendNewUserNameAsync(userName);
81+
82+
return await externalLogin.SendEmailAsync(email);
83+
}
84+
7185
internal static async Task<Account.Manage.Index> SendEmailConfirmationLinkAsync(Index index)
7286
{
7387
var manage = await index.ClickManageLinkAsync();

0 commit comments

Comments
 (0)