Changing all validators to async

This commit is contained in:
Praburaj 2015-04-15 23:59:04 -07:00
parent 0083778faf
commit 9eca47b388
10 changed files with 228 additions and 222 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Core.Collections; using Microsoft.AspNet.Http.Core.Collections;
using Microsoft.AspNet.WebUtilities; using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
@ -11,14 +12,14 @@ namespace E2ETests
{ {
public partial class Validator public partial class Validator
{ {
public void LoginWithFacebook() public async Task LoginWithFacebook()
{ {
_httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = false }; _httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = false };
_httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) }; _httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) };
var response = _httpClient.GetAsync("Account/Login").Result; var response = await _httpClient.GetAsync("Account/Login");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
_logger.LogInformation("Signing in with Facebook account"); _logger.LogInformation("Signing in with Facebook account");
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
@ -28,7 +29,7 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLogin", content).Result; response = await _httpClient.PostAsync("Account/ExternalLogin", content);
Assert.Equal<string>("https://www.facebook.com/v2.2/dialog/oauth", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty)); Assert.Equal<string>("https://www.facebook.com/v2.2/dialog/oauth", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
var queryItems = new ReadableStringCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query)); var queryItems = new ReadableStringCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query));
Assert.Equal<string>("code", queryItems["response_type"]); Assert.Equal<string>("code", queryItems["response_type"]);
@ -44,8 +45,8 @@ namespace E2ETests
_httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = true }; _httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = true };
_httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) }; _httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) };
response = _httpClient.GetAsync("Account/Login").Result; response = await _httpClient.GetAsync("Account/Login");
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
formParameters = new List<KeyValuePair<string, string>> formParameters = new List<KeyValuePair<string, string>>
{ {
new KeyValuePair<string, string>("provider", "Facebook"), new KeyValuePair<string, string>("provider", "Facebook"),
@ -54,12 +55,12 @@ namespace E2ETests
}; };
content = new FormUrlEncodedContent(formParameters.ToArray()); content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLogin", content).Result; response = await _httpClient.PostAsync("Account/ExternalLogin", content);
//Post a message to the Facebook middleware //Post a message to the Facebook middleware
response = _httpClient.GetAsync("signin-facebook?code=ValidCode&state=ValidStateData").Result; response = await _httpClient.GetAsync("signin-facebook?code=ValidCode&state=ValidStateData");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
//Correlation cookie not getting cleared after successful signin? //Correlation cookie not getting cleared after successful signin?
if (!Helpers.RunningOnMono) if (!Helpers.RunningOnMono)
@ -76,9 +77,9 @@ namespace E2ETests
}; };
content = new FormUrlEncodedContent(formParameters.ToArray()); content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLoginConfirmation", content).Result; response = await _httpClient.PostAsync("Account/ExternalLoginConfirmation", content);
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains(string.Format("Hello {0}!", "AspnetvnextTest@test.com"), responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(string.Format("Hello {0}!", "AspnetvnextTest@test.com"), responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase);
@ -89,7 +90,7 @@ namespace E2ETests
_logger.LogInformation("Verifying if the middleware notifications were fired"); _logger.LogInformation("Verifying if the middleware notifications were fired");
//Check for a non existing item //Check for a non existing item
response = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123")).Result; response = await _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123"));
//This action requires admin permissions. If notifications are fired this permission is granted //This action requires admin permissions. If notifications are fired this permission is granted
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
_logger.LogInformation("Middleware notifications were fired successfully"); _logger.LogInformation("Middleware notifications were fired successfully");

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Core.Collections; using Microsoft.AspNet.Http.Core.Collections;
using Microsoft.AspNet.WebUtilities; using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
@ -11,14 +12,14 @@ namespace E2ETests
{ {
public partial class Validator public partial class Validator
{ {
public void LoginWithGoogle() public async Task LoginWithGoogle()
{ {
_httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = false }; _httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = false };
_httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) }; _httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) };
var response = _httpClient.GetAsync("Account/Login").Result; var response = await _httpClient.GetAsync("Account/Login");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
_logger.LogInformation("Signing in with Google account"); _logger.LogInformation("Signing in with Google account");
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
@ -28,7 +29,7 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLogin", content).Result; response = await _httpClient.PostAsync("Account/ExternalLogin", content);
Assert.Equal<string>("https://accounts.google.com/o/oauth2/auth", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty)); Assert.Equal<string>("https://accounts.google.com/o/oauth2/auth", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
var queryItems = new ReadableStringCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query)); var queryItems = new ReadableStringCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query));
Assert.Equal<string>("code", queryItems["response_type"]); Assert.Equal<string>("code", queryItems["response_type"]);
@ -45,8 +46,8 @@ namespace E2ETests
_httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = true }; _httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = true };
_httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) }; _httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) };
response = _httpClient.GetAsync("Account/Login").Result; response = await _httpClient.GetAsync("Account/Login");
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
formParameters = new List<KeyValuePair<string, string>> formParameters = new List<KeyValuePair<string, string>>
{ {
new KeyValuePair<string, string>("provider", "Google"), new KeyValuePair<string, string>("provider", "Google"),
@ -55,12 +56,12 @@ namespace E2ETests
}; };
content = new FormUrlEncodedContent(formParameters.ToArray()); content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLogin", content).Result; response = await _httpClient.PostAsync("Account/ExternalLogin", content);
//Post a message to the Google middleware //Post a message to the Google middleware
response = _httpClient.GetAsync("signin-google?code=ValidCode&state=ValidStateData").Result; response = await _httpClient.GetAsync("signin-google?code=ValidCode&state=ValidStateData");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
//Correlation cookie not getting cleared after successful signin? //Correlation cookie not getting cleared after successful signin?
if (!Helpers.RunningOnMono) if (!Helpers.RunningOnMono)
@ -77,9 +78,9 @@ namespace E2ETests
}; };
content = new FormUrlEncodedContent(formParameters.ToArray()); content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLoginConfirmation", content).Result; response = await _httpClient.PostAsync("Account/ExternalLoginConfirmation", content);
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains(string.Format("Hello {0}!", "AspnetvnextTest@gmail.com"), responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(string.Format("Hello {0}!", "AspnetvnextTest@gmail.com"), responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase);
@ -90,9 +91,9 @@ namespace E2ETests
_logger.LogInformation("Verifying if the middleware notifications were fired"); _logger.LogInformation("Verifying if the middleware notifications were fired");
//Check for a non existing item //Check for a non existing item
response = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123")).Result; response = await _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123"));
//This action requires admin permissions. If notifications are fired this permission is granted //This action requires admin permissions. If notifications are fired this permission is granted
_logger.LogVerbose(response.Content.ReadAsStringAsync().Result); _logger.LogVerbose(await response.Content.ReadAsStringAsync());
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
_logger.LogInformation("Middleware notifications were fired successfully"); _logger.LogInformation("Middleware notifications were fired successfully");
} }

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Core.Collections; using Microsoft.AspNet.Http.Core.Collections;
using Microsoft.AspNet.WebUtilities; using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
@ -11,14 +12,14 @@ namespace E2ETests
{ {
public partial class Validator public partial class Validator
{ {
public void LoginWithMicrosoftAccount() public async Task LoginWithMicrosoftAccount()
{ {
_httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = false }; _httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = false };
_httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) }; _httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) };
var response = _httpClient.GetAsync("Account/Login").Result; var response = await _httpClient.GetAsync("Account/Login");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
_logger.LogInformation("Signing in with Microsoft account"); _logger.LogInformation("Signing in with Microsoft account");
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
@ -28,7 +29,7 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLogin", content).Result; response = await _httpClient.PostAsync("Account/ExternalLogin", content);
Assert.Equal<string>("https://login.live.com/oauth20_authorize.srf", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty)); Assert.Equal<string>("https://login.live.com/oauth20_authorize.srf", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
var queryItems = new ReadableStringCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query)); var queryItems = new ReadableStringCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query));
Assert.Equal<string>("code", queryItems["response_type"]); Assert.Equal<string>("code", queryItems["response_type"]);
@ -45,8 +46,8 @@ namespace E2ETests
_httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = true }; _httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = true };
_httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) }; _httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) };
response = _httpClient.GetAsync("Account/Login").Result; response = await _httpClient.GetAsync("Account/Login");
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
formParameters = new List<KeyValuePair<string, string>> formParameters = new List<KeyValuePair<string, string>>
{ {
new KeyValuePair<string, string>("provider", "Microsoft"), new KeyValuePair<string, string>("provider", "Microsoft"),
@ -55,12 +56,12 @@ namespace E2ETests
}; };
content = new FormUrlEncodedContent(formParameters.ToArray()); content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLogin", content).Result; response = await _httpClient.PostAsync("Account/ExternalLogin", content);
//Post a message to the MicrosoftAccount middleware //Post a message to the MicrosoftAccount middleware
response = _httpClient.GetAsync("signin-microsoft?code=ValidCode&state=ValidStateData").Result; response = await _httpClient.GetAsync("signin-microsoft?code=ValidCode&state=ValidStateData");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
//Correlation cookie not getting cleared after successful signin? //Correlation cookie not getting cleared after successful signin?
if (!Helpers.RunningOnMono) if (!Helpers.RunningOnMono)
@ -76,9 +77,9 @@ namespace E2ETests
}; };
content = new FormUrlEncodedContent(formParameters.ToArray()); content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLoginConfirmation", content).Result; response = await _httpClient.PostAsync("Account/ExternalLoginConfirmation", content);
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains(string.Format("Hello {0}!", "microsoft@test.com"), responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(string.Format("Hello {0}!", "microsoft@test.com"), responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase);
@ -89,9 +90,9 @@ namespace E2ETests
_logger.LogInformation("Verifying if the middleware notifications were fired"); _logger.LogInformation("Verifying if the middleware notifications were fired");
//Check for a non existing item //Check for a non existing item
response = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123")).Result; response = await _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123"));
//This action requires admin permissions. If notifications are fired this permission is granted //This action requires admin permissions. If notifications are fired this permission is granted
_logger.LogInformation(response.Content.ReadAsStringAsync().Result); _logger.LogInformation(await response.Content.ReadAsStringAsync());
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
_logger.LogInformation("Middleware notifications were fired successfully"); _logger.LogInformation("Middleware notifications were fired successfully");
} }

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Core.Collections; using Microsoft.AspNet.Http.Core.Collections;
using Microsoft.AspNet.WebUtilities; using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
@ -11,14 +12,14 @@ namespace E2ETests
{ {
public partial class Validator public partial class Validator
{ {
public void LoginWithOpenIdConnect() public async Task LoginWithOpenIdConnect()
{ {
_httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = false }; _httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = false };
_httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) }; _httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) };
var response = _httpClient.GetAsync("Account/Login").Result; var response = await _httpClient.GetAsync("Account/Login");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
_logger.LogInformation("Signing in with OpenIdConnect account"); _logger.LogInformation("Signing in with OpenIdConnect account");
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
@ -28,7 +29,7 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLogin", content).Result; response = await _httpClient.PostAsync("Account/ExternalLogin", content);
Assert.Equal<string>("https://login.windows.net/4afbc689-805b-48cf-a24c-d4aa3248a248/oauth2/authorize", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty)); Assert.Equal<string>("https://login.windows.net/4afbc689-805b-48cf-a24c-d4aa3248a248/oauth2/authorize", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
var queryItems = new ReadableStringCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query)); var queryItems = new ReadableStringCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query));
Assert.Equal<string>("c99497aa-3ee2-4707-b8a8-c33f51323fef", queryItems["client_id"]); Assert.Equal<string>("c99497aa-3ee2-4707-b8a8-c33f51323fef", queryItems["client_id"]);
@ -53,9 +54,9 @@ namespace E2ETests
new KeyValuePair<string, string>("session_state", "d0b59ffa-2df9-4d8c-b43a-2c410987f4ae") new KeyValuePair<string, string>("session_state", "d0b59ffa-2df9-4d8c-b43a-2c410987f4ae")
}; };
response = _httpClient.PostAsync(string.Empty, new FormUrlEncodedContent(token.ToArray())).Result; response = await _httpClient.PostAsync(string.Empty, new FormUrlEncodedContent(token.ToArray()));
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Equal(_deploymentResult.ApplicationBaseUri + "Account/ExternalLoginCallback?ReturnUrl=%2F", response.RequestMessage.RequestUri.AbsoluteUri); Assert.Equal(_deploymentResult.ApplicationBaseUri + "Account/ExternalLoginCallback?ReturnUrl=%2F", response.RequestMessage.RequestUri.AbsoluteUri);
formParameters = new List<KeyValuePair<string, string>> formParameters = new List<KeyValuePair<string, string>>
@ -65,9 +66,9 @@ namespace E2ETests
}; };
content = new FormUrlEncodedContent(formParameters.ToArray()); content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLoginConfirmation", content).Result; response = await _httpClient.PostAsync("Account/ExternalLoginConfirmation", content);
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains(string.Format("Hello {0}!", "User3@aspnettest.onmicrosoft.com"), responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(string.Format("Hello {0}!", "User3@aspnettest.onmicrosoft.com"), responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase);
@ -78,15 +79,15 @@ namespace E2ETests
_logger.LogInformation("Verifying if the middleware notifications were fired"); _logger.LogInformation("Verifying if the middleware notifications were fired");
//Check for a non existing item //Check for a non existing item
response = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123")).Result; response = await _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123"));
//This action requires admin permissions. If notifications are fired this permission is granted //This action requires admin permissions. If notifications are fired this permission is granted
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
_logger.LogInformation("Middleware notifications were fired successfully"); _logger.LogInformation("Middleware notifications were fired successfully");
_logger.LogInformation("Verifying the OpenIdConnect logout flow.."); _logger.LogInformation("Verifying the OpenIdConnect logout flow..");
response = _httpClient.GetAsync(string.Empty).Result; response = await _httpClient.GetAsync(string.Empty);
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
ValidateLayoutPage(responseContent); ValidateLayoutPage(responseContent);
formParameters = new List<KeyValuePair<string, string>> formParameters = new List<KeyValuePair<string, string>>
{ {
@ -99,7 +100,7 @@ namespace E2ETests
handler.CookieContainer.Add(new Uri(_deploymentResult.ApplicationBaseUri), _httpClientHandler.CookieContainer.GetCookies(new Uri(_deploymentResult.ApplicationBaseUri))); handler.CookieContainer.Add(new Uri(_deploymentResult.ApplicationBaseUri), _httpClientHandler.CookieContainer.GetCookies(new Uri(_deploymentResult.ApplicationBaseUri)));
_httpClient = new HttpClient(handler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) }; _httpClient = new HttpClient(handler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) };
response = _httpClient.PostAsync("Account/LogOff", content).Result; response = await _httpClient.PostAsync("Account/LogOff", content);
Assert.Null(handler.CookieContainer.GetCookies(new Uri(_deploymentResult.ApplicationBaseUri)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.Null(handler.CookieContainer.GetCookies(new Uri(_deploymentResult.ApplicationBaseUri)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
Assert.Equal<string>( Assert.Equal<string>(
"https://login.windows.net/4afbc689-805b-48cf-a24c-d4aa3248a248/oauth2/logout", "https://login.windows.net/4afbc689-805b-48cf-a24c-d4aa3248a248/oauth2/logout",

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Core.Collections; using Microsoft.AspNet.Http.Core.Collections;
using Microsoft.AspNet.WebUtilities; using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
@ -14,14 +15,14 @@ namespace E2ETests
/// </summary> /// </summary>
public partial class Validator public partial class Validator
{ {
public void LoginWithTwitter() public async Task LoginWithTwitter()
{ {
_httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = false }; _httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = false };
_httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) }; _httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) };
var response = _httpClient.GetAsync("Account/Login").Result; var response = await _httpClient.GetAsync("Account/Login");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
_logger.LogInformation("Signing in with Twitter account"); _logger.LogInformation("Signing in with Twitter account");
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
@ -31,7 +32,7 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLogin", content).Result; response = await _httpClient.PostAsync("Account/ExternalLogin", content);
Assert.Equal<string>("https://twitter.com/oauth/authenticate", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty)); Assert.Equal<string>("https://twitter.com/oauth/authenticate", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
var queryItems = new ReadableStringCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query)); var queryItems = new ReadableStringCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query));
Assert.Equal<string>("custom", queryItems["custom_redirect_uri"]); Assert.Equal<string>("custom", queryItems["custom_redirect_uri"]);
@ -43,8 +44,8 @@ namespace E2ETests
_httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = true }; _httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = true };
_httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) }; _httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) };
response = _httpClient.GetAsync("Account/Login").Result; response = await _httpClient.GetAsync("Account/Login");
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
formParameters = new List<KeyValuePair<string, string>> formParameters = new List<KeyValuePair<string, string>>
{ {
new KeyValuePair<string, string>("provider", "Twitter"), new KeyValuePair<string, string>("provider", "Twitter"),
@ -53,12 +54,12 @@ namespace E2ETests
}; };
content = new FormUrlEncodedContent(formParameters.ToArray()); content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLogin", content).Result; response = await _httpClient.PostAsync("Account/ExternalLogin", content);
//Post a message to the Facebook middleware //Post a message to the Facebook middleware
response = _httpClient.GetAsync("signin-twitter?oauth_token=valid_oauth_token&oauth_verifier=valid_oauth_verifier").Result; response = await _httpClient.GetAsync("signin-twitter?oauth_token=valid_oauth_token&oauth_verifier=valid_oauth_verifier");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
//Check correlation cookie not getting cleared after successful signin //Check correlation cookie not getting cleared after successful signin
if (!Helpers.RunningOnMono) if (!Helpers.RunningOnMono)
@ -76,9 +77,9 @@ namespace E2ETests
}; };
content = new FormUrlEncodedContent(formParameters.ToArray()); content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/ExternalLoginConfirmation", content).Result; response = await _httpClient.PostAsync("Account/ExternalLoginConfirmation", content);
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains(string.Format("Hello {0}!", "twitter@test.com"), responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(string.Format("Hello {0}!", "twitter@test.com"), responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase);
@ -89,7 +90,7 @@ namespace E2ETests
_logger.LogInformation("Verifying if the middleware notifications were fired"); _logger.LogInformation("Verifying if the middleware notifications were fired");
//Check for a non existing item //Check for a non existing item
response = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123")).Result; response = await _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123"));
//This action requires admin permissions. If notifications are fired this permission is granted //This action requires admin permissions. If notifications are fired this permission is granted
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
_logger.LogInformation("Middleware notifications were fired successfully"); _logger.LogInformation("Middleware notifications were fired successfully");

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using DeploymentHelpers; using DeploymentHelpers;
using Microsoft.AspNet.SignalR.Client; using Microsoft.AspNet.SignalR.Client;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
@ -30,11 +31,11 @@ namespace E2ETests
_deploymentResult = deploymentResult; _deploymentResult = deploymentResult;
} }
public void VerifyHomePage( public async Task VerifyHomePage(
HttpResponseMessage response, HttpResponseMessage response,
bool useNtlmAuthentication = false) bool useNtlmAuthentication = false)
{ {
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
if (response.StatusCode != HttpStatusCode.OK) if (response.StatusCode != HttpStatusCode.OK)
{ {
@ -58,7 +59,7 @@ namespace E2ETests
_logger.LogInformation("Application initialization successful."); _logger.LogInformation("Application initialization successful.");
_logger.LogInformation("Application runtime information"); _logger.LogInformation("Application runtime information");
//var runtimeResponse = _httpClient.GetAsync("runtimeinfo").Result; //var runtimeResponse = await _httpClient.GetAsync("runtimeinfo");
// https://github.com/aspnet/Diagnostics/issues/108 // https://github.com/aspnet/Diagnostics/issues/108
if (_deploymentResult.DeploymentParameters.RuntimeFlavor != RuntimeFlavor.coreclr) if (_deploymentResult.DeploymentParameters.RuntimeFlavor != RuntimeFlavor.coreclr)
@ -66,15 +67,15 @@ namespace E2ETests
//Helpers.ThrowIfResponseStatusNotOk(runtimeResponse, _logger); //Helpers.ThrowIfResponseStatusNotOk(runtimeResponse, _logger);
} }
//var runtimeInfo = runtimeResponse.Content.ReadAsStringAsync().Result; //var runtimeInfo = await runtimeResponse.Content.ReadAsStringAsync();
//_logger.LogInformation(runtimeInfo); //_logger.LogInformation(runtimeInfo);
} }
public void VerifyNtlmHomePage(HttpResponseMessage response) public async Task VerifyNtlmHomePage(HttpResponseMessage response)
{ {
VerifyHomePage(response, useNtlmAuthentication: true); await VerifyHomePage(response, useNtlmAuthentication: true);
var homePageContent = response.Content.ReadAsStringAsync().Result; var homePageContent = await response.Content.ReadAsStringAsync();
//Check if the user name appears in the page //Check if the user name appears in the page
Assert.Contains( Assert.Contains(
@ -91,34 +92,34 @@ namespace E2ETests
Assert.Contains("<li class=\"divider\"></li>", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("<li class=\"divider\"></li>", responseContent, StringComparison.OrdinalIgnoreCase);
} }
public void VerifyStaticContentServed() public async Task VerifyStaticContentServed()
{ {
_logger.LogInformation("Validating if static contents are served.."); _logger.LogInformation("Validating if static contents are served..");
_logger.LogInformation("Fetching favicon.ico.."); _logger.LogInformation("Fetching favicon.ico..");
var response = _httpClient.GetAsync("favicon.ico").Result; var response = await _httpClient.GetAsync("favicon.ico");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
_logger.LogInformation("Etag received: {etag}", response.Headers.ETag.Tag); _logger.LogInformation("Etag received: {etag}", response.Headers.ETag.Tag);
//Check if you receive a NotModified on sending an etag //Check if you receive a NotModified on sending an etag
_logger.LogInformation("Sending an IfNoneMatch header with e-tag"); _logger.LogInformation("Sending an IfNoneMatch header with e-tag");
_httpClient.DefaultRequestHeaders.IfNoneMatch.Add(response.Headers.ETag); _httpClient.DefaultRequestHeaders.IfNoneMatch.Add(response.Headers.ETag);
response = _httpClient.GetAsync("favicon.ico").Result; response = await _httpClient.GetAsync("favicon.ico");
Assert.Equal(HttpStatusCode.NotModified, response.StatusCode); Assert.Equal(HttpStatusCode.NotModified, response.StatusCode);
_httpClient.DefaultRequestHeaders.IfNoneMatch.Clear(); _httpClient.DefaultRequestHeaders.IfNoneMatch.Clear();
_logger.LogInformation("Successfully received a NotModified status"); _logger.LogInformation("Successfully received a NotModified status");
_logger.LogInformation("Fetching /Content/bootstrap.css.."); _logger.LogInformation("Fetching /Content/bootstrap.css..");
response = _httpClient.GetAsync("Content/bootstrap.css").Result; response = await _httpClient.GetAsync("Content/bootstrap.css");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
_logger.LogInformation("Verified static contents are served successfully"); _logger.LogInformation("Verified static contents are served successfully");
} }
public void AccessStoreWithPermissions() public async Task AccessStoreWithPermissions()
{ {
_logger.LogInformation("Trying to access the store inventory.."); _logger.LogInformation("Trying to access the store inventory..");
var response = _httpClient.GetAsync("Admin/StoreManager/").Result; var response = await _httpClient.GetAsync("Admin/StoreManager/");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
Assert.Equal<string>(_deploymentResult.ApplicationBaseUri + "Admin/StoreManager/", response.RequestMessage.RequestUri.AbsoluteUri); Assert.Equal<string>(_deploymentResult.ApplicationBaseUri + "Admin/StoreManager/", response.RequestMessage.RequestUri.AbsoluteUri);
_logger.LogInformation("Successfully acccessed the store inventory"); _logger.LogInformation("Successfully acccessed the store inventory");
} }
@ -137,12 +138,12 @@ namespace E2ETests
return url.Replace("//", "/").Replace("%2F%2F", "%2F").Replace("%2F/", "%2F"); return url.Replace("//", "/").Replace("%2F%2F", "%2F").Replace("%2F/", "%2F");
} }
public void AccessStoreWithoutPermissions(string email = null) public async Task AccessStoreWithoutPermissions(string email = null)
{ {
_logger.LogInformation("Trying to access StoreManager that needs ManageStore claim with the current user : {email}", email ?? "Anonymous"); _logger.LogInformation("Trying to access StoreManager that needs ManageStore claim with the current user : {email}", email ?? "Anonymous");
var response = _httpClient.GetAsync("Admin/StoreManager/").Result; var response = await _httpClient.GetAsync("Admin/StoreManager/");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
ValidateLayoutPage(responseContent); ValidateLayoutPage(responseContent);
Assert.Contains("<title>Log in ASP.NET MVC Music Store</title>", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("<title>Log in ASP.NET MVC Music Store</title>", responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains("<h4>Use a local account to log in.</h4>", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("<h4>Use a local account to log in.</h4>", responseContent, StringComparison.OrdinalIgnoreCase);
@ -150,12 +151,12 @@ namespace E2ETests
_logger.LogInformation("Redirected to login page as expected."); _logger.LogInformation("Redirected to login page as expected.");
} }
public void RegisterUserWithNonMatchingPasswords() public async Task RegisterUserWithNonMatchingPasswords()
{ {
_logger.LogInformation("Trying to create user with not matching password and confirm password"); _logger.LogInformation("Trying to create user with not matching password and confirm password");
var response = _httpClient.GetAsync("Account/Register").Result; var response = await _httpClient.GetAsync("Account/Register");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
ValidateLayoutPage(responseContent); ValidateLayoutPage(responseContent);
var generatedEmail = Guid.NewGuid().ToString().Replace("-", string.Empty) + "@test.com"; var generatedEmail = Guid.NewGuid().ToString().Replace("-", string.Empty) + "@test.com";
@ -169,18 +170,18 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/Register", content).Result; response = await _httpClient.PostAsync("Account/Register", content);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_deploymentResult.ApplicationBaseUri)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_deploymentResult.ApplicationBaseUri)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
Assert.Contains("<div class=\"text-danger validation-summary-errors\" data-valmsg-summary=\"true\"><ul><li>The password and confirmation password do not match.</li>", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("<div class=\"text-danger validation-summary-errors\" data-valmsg-summary=\"true\"><ul><li>The password and confirmation password do not match.</li>", responseContent, StringComparison.OrdinalIgnoreCase);
_logger.LogInformation("Server side model validator rejected the user '{email}''s registration as passwords do not match.", generatedEmail); _logger.LogInformation("Server side model validator rejected the user '{email}''s registration as passwords do not match.", generatedEmail);
} }
public string RegisterValidUser() public async Task<string> RegisterValidUser()
{ {
var response = _httpClient.GetAsync("Account/Register").Result; var response = await _httpClient.GetAsync("Account/Register");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
ValidateLayoutPage(responseContent); ValidateLayoutPage(responseContent);
var generatedEmail = Guid.NewGuid().ToString().Replace("-", string.Empty) + "@test.com"; var generatedEmail = Guid.NewGuid().ToString().Replace("-", string.Empty) + "@test.com";
@ -194,8 +195,8 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/Register", content).Result; response = await _httpClient.PostAsync("Account/Register", content);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
//Account verification //Account verification
Assert.Equal<string>(_deploymentResult.ApplicationBaseUri + "Account/Register", response.RequestMessage.RequestUri.AbsoluteUri); Assert.Equal<string>(_deploymentResult.ApplicationBaseUri + "Account/Register", response.RequestMessage.RequestUri.AbsoluteUri);
@ -204,19 +205,19 @@ namespace E2ETests
var endIndex = responseContent.IndexOf("\">link</a>]]", startIndex); var endIndex = responseContent.IndexOf("\">link</a>]]", startIndex);
var confirmUrl = responseContent.Substring(startIndex, endIndex - startIndex); var confirmUrl = responseContent.Substring(startIndex, endIndex - startIndex);
confirmUrl = WebUtility.HtmlDecode(confirmUrl); confirmUrl = WebUtility.HtmlDecode(confirmUrl);
response = _httpClient.GetAsync(confirmUrl).Result; response = await _httpClient.GetAsync(confirmUrl);
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains("Thank you for confirming your email.", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("Thank you for confirming your email.", responseContent, StringComparison.OrdinalIgnoreCase);
return generatedEmail; return generatedEmail;
} }
public void RegisterExistingUser(string email) public async Task RegisterExistingUser(string email)
{ {
_logger.LogInformation("Trying to register a user with name '{email}' again", email); _logger.LogInformation("Trying to register a user with name '{email}' again", email);
var response = _httpClient.GetAsync("Account/Register").Result; var response = await _httpClient.GetAsync("Account/Register");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
_logger.LogInformation("Creating a new user with name '{email}'", email); _logger.LogInformation("Creating a new user with name '{email}'", email);
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
@ -227,18 +228,18 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/Register", content).Result; response = await _httpClient.PostAsync("Account/Register", content);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains(string.Format("User name &#x27;{0}&#x27; is already taken.", email), responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(string.Format("User name &#x27;{0}&#x27; is already taken.", email), responseContent, StringComparison.OrdinalIgnoreCase);
_logger.LogInformation("Identity threw a valid exception that user '{email}' already exists in the system", email); _logger.LogInformation("Identity threw a valid exception that user '{email}' already exists in the system", email);
} }
public void SignOutUser(string email) public async Task SignOutUser(string email)
{ {
_logger.LogInformation("Signing out from '{email}''s session", email); _logger.LogInformation("Signing out from '{email}''s session", email);
var response = _httpClient.GetAsync(string.Empty).Result; var response = await _httpClient.GetAsync(string.Empty);
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
ValidateLayoutPage(responseContent); ValidateLayoutPage(responseContent);
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
@ -246,8 +247,8 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/LogOff", content).Result; response = await _httpClient.PostAsync("Account/LogOff", content);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
if (!Helpers.RunningOnMono) if (!Helpers.RunningOnMono)
{ {
@ -268,11 +269,11 @@ namespace E2ETests
} }
} }
public void SignInWithInvalidPassword(string email, string invalidPassword) public async Task SignInWithInvalidPassword(string email, string invalidPassword)
{ {
var response = _httpClient.GetAsync("Account/Login").Result; var response = await _httpClient.GetAsync("Account/Login");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
_logger.LogInformation("Signing in with user '{email}'", email); _logger.LogInformation("Signing in with user '{email}'", email);
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
@ -282,19 +283,19 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/Login", content).Result; response = await _httpClient.PostAsync("Account/Login", content);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains("<div class=\"text-danger validation-summary-errors\" data-valmsg-summary=\"true\"><ul><li>Invalid login attempt.</li>", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("<div class=\"text-danger validation-summary-errors\" data-valmsg-summary=\"true\"><ul><li>Invalid login attempt.</li>", responseContent, StringComparison.OrdinalIgnoreCase);
//Verify cookie not sent //Verify cookie not sent
Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_deploymentResult.ApplicationBaseUri)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_deploymentResult.ApplicationBaseUri)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
_logger.LogInformation("Identity successfully prevented an invalid user login."); _logger.LogInformation("Identity successfully prevented an invalid user login.");
} }
public void SignInWithUser(string email, string password) public async Task SignInWithUser(string email, string password)
{ {
var response = _httpClient.GetAsync("Account/Login").Result; var response = await _httpClient.GetAsync("Account/Login");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
_logger.LogInformation("Signing in with user '{email}'", email); _logger.LogInformation("Signing in with user '{email}'", email);
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
@ -304,8 +305,8 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Account/Login", content).Result; response = await _httpClient.PostAsync("Account/Login", content);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains(string.Format("Hello {0}!", email), responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(string.Format("Hello {0}!", email), responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase);
//Verify cookie sent //Verify cookie sent
@ -313,11 +314,11 @@ namespace E2ETests
_logger.LogInformation("Successfully signed in with user '{email}'", email); _logger.LogInformation("Successfully signed in with user '{email}'", email);
} }
public void ChangePassword(string email) public async Task ChangePassword(string email)
{ {
var response = _httpClient.GetAsync("Manage/ChangePassword").Result; var response = await _httpClient.GetAsync("Manage/ChangePassword");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
new KeyValuePair<string, string>("OldPassword", "Password~1"), new KeyValuePair<string, string>("OldPassword", "Password~1"),
@ -327,14 +328,14 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Manage/ChangePassword", content).Result; response = await _httpClient.PostAsync("Manage/ChangePassword", content);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains("Your password has been changed.", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("Your password has been changed.", responseContent, StringComparison.OrdinalIgnoreCase);
Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_deploymentResult.ApplicationBaseUri)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_deploymentResult.ApplicationBaseUri)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
_logger.LogInformation("Successfully changed the password for user '{email}'", email); _logger.LogInformation("Successfully changed the password for user '{email}'", email);
} }
public string CreateAlbum() public async Task<string> CreateAlbum()
{ {
var albumName = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12); var albumName = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12);
#if DNX451 #if DNX451
@ -349,12 +350,12 @@ namespace E2ETests
}; };
IHubProxy proxy = hubConnection.CreateHubProxy("Announcement"); IHubProxy proxy = hubConnection.CreateHubProxy("Announcement");
hubConnection.Start().Wait(); await hubConnection.Start();
#endif #endif
_logger.LogInformation("Trying to create an album with name '{album}'", albumName); _logger.LogInformation("Trying to create an album with name '{album}'", albumName);
var response = _httpClient.GetAsync("Admin/StoreManager/create").Result; var response = await _httpClient.GetAsync("Admin/StoreManager/create");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
new KeyValuePair<string, string>("__RequestVerificationToken", HtmlDOMHelper.RetrieveAntiForgeryToken(responseContent, "/Admin/StoreManager/create")), new KeyValuePair<string, string>("__RequestVerificationToken", HtmlDOMHelper.RetrieveAntiForgeryToken(responseContent, "/Admin/StoreManager/create")),
@ -366,8 +367,8 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Admin/StoreManager/create", content).Result; response = await _httpClient.PostAsync("Admin/StoreManager/create", content);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Equal<string>(_deploymentResult.ApplicationBaseUri + "Admin/StoreManager", response.RequestMessage.RequestUri.AbsoluteUri); Assert.Equal<string>(_deploymentResult.ApplicationBaseUri + "Admin/StoreManager", response.RequestMessage.RequestUri.AbsoluteUri);
Assert.Contains(albumName, responseContent); Assert.Contains(albumName, responseContent);
#if DNX451 #if DNX451
@ -380,77 +381,77 @@ namespace E2ETests
return albumName; return albumName;
} }
public string FetchAlbumIdFromName(string albumName) public async Task<string> FetchAlbumIdFromName(string albumName)
{ {
// Run some CORS validation. // Run some CORS validation.
_logger.LogInformation("Fetching the album id of '{album}'", albumName); _logger.LogInformation("Fetching the album id of '{album}'", albumName);
_httpClient.DefaultRequestHeaders.Add("Origin", "http://notpermitteddomain.com"); _httpClient.DefaultRequestHeaders.Add("Origin", "http://notpermitteddomain.com");
var response = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", albumName)).Result; var response = await _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", albumName));
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
IEnumerable<string> values; IEnumerable<string> values;
Assert.False(response.Headers.TryGetValues("Access-Control-Allow-Origin", out values)); Assert.False(response.Headers.TryGetValues("Access-Control-Allow-Origin", out values));
_httpClient.DefaultRequestHeaders.Remove("Origin"); _httpClient.DefaultRequestHeaders.Remove("Origin");
_httpClient.DefaultRequestHeaders.Add("Origin", "http://example.com"); _httpClient.DefaultRequestHeaders.Add("Origin", "http://example.com");
response = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", albumName)).Result; response = await _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", albumName));
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
Assert.Equal("http://example.com", response.Headers.GetValues("Access-Control-Allow-Origin").First()); Assert.Equal("http://example.com", response.Headers.GetValues("Access-Control-Allow-Origin").First());
_httpClient.DefaultRequestHeaders.Remove("Origin"); _httpClient.DefaultRequestHeaders.Remove("Origin");
var albumId = response.Content.ReadAsStringAsync().Result; var albumId = await response.Content.ReadAsStringAsync();
_logger.LogInformation("Album id for album '{album}' is '{id}'", albumName, albumId); _logger.LogInformation("Album id for album '{album}' is '{id}'", albumName, albumId);
return albumId; return albumId;
} }
public void VerifyAlbumDetails(string albumId, string albumName) public async Task VerifyAlbumDetails(string albumId, string albumName)
{ {
_logger.LogInformation("Getting details of album with Id '{id}'", albumId); _logger.LogInformation("Getting details of album with Id '{id}'", albumId);
var response = _httpClient.GetAsync(string.Format("Admin/StoreManager/Details?id={0}", albumId)).Result; var response = await _httpClient.GetAsync(string.Format("Admin/StoreManager/Details?id={0}", albumId));
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains(albumName, responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(albumName, responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains("http://myapp/testurl", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("http://myapp/testurl", responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains(PrefixBaseAddress(string.Format("<a href=\"/{0}/Admin/StoreManager/Edit?id={1}\">Edit</a>", "{0}", albumId)), responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(PrefixBaseAddress(string.Format("<a href=\"/{0}/Admin/StoreManager/Edit?id={1}\">Edit</a>", "{0}", albumId)), responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains(PrefixBaseAddress("<a href=\"/{0}/Admin/StoreManager\">Back to List</a>"), responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(PrefixBaseAddress("<a href=\"/{0}/Admin/StoreManager\">Back to List</a>"), responseContent, StringComparison.OrdinalIgnoreCase);
} }
public void VerifyStatusCodePages() public async Task VerifyStatusCodePages()
{ {
_logger.LogInformation("Getting details of a non-existing album with Id '-1'"); _logger.LogInformation("Getting details of a non-existing album with Id '-1'");
var response = _httpClient.GetAsync("Admin/StoreManager/Details?id=-1").Result; var response = await _httpClient.GetAsync("Admin/StoreManager/Details?id=-1");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains("Item not found.", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("Item not found.", responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Equal(PrefixBaseAddress("/{0}/Home/StatusCodePage"), response.RequestMessage.RequestUri.AbsolutePath); Assert.Equal(PrefixBaseAddress("/{0}/Home/StatusCodePage"), response.RequestMessage.RequestUri.AbsolutePath);
} }
// This gets the view that non-admin users get to see. // This gets the view that non-admin users get to see.
public void GetAlbumDetailsFromStore(string albumId, string albumName) public async Task GetAlbumDetailsFromStore(string albumId, string albumName)
{ {
_logger.LogInformation("Getting details of album with Id '{id}'", albumId); _logger.LogInformation("Getting details of album with Id '{id}'", albumId);
var response = _httpClient.GetAsync(string.Format("Store/Details/{0}", albumId)).Result; var response = await _httpClient.GetAsync(string.Format("Store/Details/{0}", albumId));
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains(albumName, responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(albumName, responseContent, StringComparison.OrdinalIgnoreCase);
} }
public void AddAlbumToCart(string albumId, string albumName) public async Task AddAlbumToCart(string albumId, string albumName)
{ {
_logger.LogInformation("Adding album id '{albumId}' to the cart", albumId); _logger.LogInformation("Adding album id '{albumId}' to the cart", albumId);
var response = _httpClient.GetAsync(string.Format("ShoppingCart/AddToCart?id={0}", albumId)).Result; var response = await _httpClient.GetAsync(string.Format("ShoppingCart/AddToCart?id={0}", albumId));
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains(albumName, responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(albumName, responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains("<span class=\"glyphicon glyphicon glyphicon-shopping-cart\"></span>", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("<span class=\"glyphicon glyphicon glyphicon-shopping-cart\"></span>", responseContent, StringComparison.OrdinalIgnoreCase);
_logger.LogInformation("Verified that album is added to cart"); _logger.LogInformation("Verified that album is added to cart");
} }
public void CheckOutCartItems() public async Task CheckOutCartItems()
{ {
_logger.LogInformation("Checking out the cart contents..."); _logger.LogInformation("Checking out the cart contents...");
var response = _httpClient.GetAsync("Checkout/AddressAndPayment").Result; var response = await _httpClient.GetAsync("Checkout/AddressAndPayment");
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = await response.Content.ReadAsStringAsync();
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
@ -468,13 +469,13 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
response = _httpClient.PostAsync("Checkout/AddressAndPayment", content).Result; response = await _httpClient.PostAsync("Checkout/AddressAndPayment", content);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains("<h2>Checkout Complete</h2>", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("<h2>Checkout Complete</h2>", responseContent, StringComparison.OrdinalIgnoreCase);
Assert.StartsWith(_deploymentResult.ApplicationBaseUri + "Checkout/Complete/", response.RequestMessage.RequestUri.AbsoluteUri, StringComparison.OrdinalIgnoreCase); Assert.StartsWith(_deploymentResult.ApplicationBaseUri + "Checkout/Complete/", response.RequestMessage.RequestUri.AbsoluteUri, StringComparison.OrdinalIgnoreCase);
} }
public void DeleteAlbum(string albumId, string albumName) public async Task DeleteAlbum(string albumId, string albumName)
{ {
_logger.LogInformation("Deleting album '{album}' from the store..", albumName); _logger.LogInformation("Deleting album '{album}' from the store..", albumName);
@ -484,20 +485,20 @@ namespace E2ETests
}; };
var content = new FormUrlEncodedContent(formParameters.ToArray()); var content = new FormUrlEncodedContent(formParameters.ToArray());
var response = _httpClient.PostAsync("Admin/StoreManager/RemoveAlbum", content).Result; var response = await _httpClient.PostAsync("Admin/StoreManager/RemoveAlbum", content);
ThrowIfResponseStatusNotOk(response); await ThrowIfResponseStatusNotOk(response);
_logger.LogInformation("Verifying if the album '{album}' is deleted from store", albumName); _logger.LogInformation("Verifying if the album '{album}' is deleted from store", albumName);
response = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", albumName)).Result; response = await _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", albumName));
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
_logger.LogInformation("Album '{album}' with id '{Id}' is successfully deleted from the store.", albumName, albumId); _logger.LogInformation("Album '{album}' with id '{Id}' is successfully deleted from the store.", albumName, albumId);
} }
private void ThrowIfResponseStatusNotOk(HttpResponseMessage response) private async Task ThrowIfResponseStatusNotOk(HttpResponseMessage response)
{ {
if (response.StatusCode != HttpStatusCode.OK) if (response.StatusCode != HttpStatusCode.OK)
{ {
_logger.LogError(response.Content.ReadAsStringAsync().Result); _logger.LogError(await response.Content.ReadAsStringAsync());
throw new Exception(string.Format("Received the above response with status code : {0}", response.StatusCode)); throw new Exception(string.Format("Received the above response with status code : {0}", response.StatusCode));
} }
} }

View File

@ -64,10 +64,10 @@ namespace E2ETests
}, logger: logger, cancellationToken: deploymentResult.HostShutdownToken); }, logger: logger, cancellationToken: deploymentResult.HostShutdownToken);
var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult); var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult);
validator.VerifyNtlmHomePage(response); await validator.VerifyNtlmHomePage(response);
//Should be able to access the store as the Startup adds necessary permissions for the current user //Should be able to access the store as the Startup adds necessary permissions for the current user
validator.AccessStoreWithPermissions(); await validator.AccessStoreWithPermissions();
logger.LogInformation("Variation completed successfully."); logger.LogInformation("Variation completed successfully.");
} }

View File

@ -73,10 +73,10 @@ namespace E2ETests
}, logger: logger, cancellationToken: deploymentResult.HostShutdownToken); }, logger: logger, cancellationToken: deploymentResult.HostShutdownToken);
var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult); var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult);
validator.VerifyHomePage(response); await validator.VerifyHomePage(response);
// OpenIdConnect login. // OpenIdConnect login.
validator.LoginWithOpenIdConnect(); await validator.LoginWithOpenIdConnect();
logger.LogInformation("Variation completed successfully."); logger.LogInformation("Variation completed successfully.");
} }

View File

@ -96,10 +96,10 @@ namespace E2ETests
}, logger: logger, cancellationToken: deploymentResult.HostShutdownToken); }, logger: logger, cancellationToken: deploymentResult.HostShutdownToken);
var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult); var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult);
validator.VerifyHomePage(response); await validator.VerifyHomePage(response);
// Static files are served? // Static files are served?
validator.VerifyStaticContentServed(); await validator.VerifyStaticContentServed();
if (serverType != ServerType.IISExpress) if (serverType != ServerType.IISExpress)
{ {

View File

@ -165,88 +165,88 @@ namespace E2ETests
var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult); var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult);
validator.VerifyHomePage(response); await validator.VerifyHomePage(response);
// Verify the static file middleware can serve static content. // Verify the static file middleware can serve static content.
validator.VerifyStaticContentServed(); await validator.VerifyStaticContentServed();
// Making a request to a protected resource should automatically redirect to login page. // Making a request to a protected resource should automatically redirect to login page.
validator.AccessStoreWithoutPermissions(); await validator.AccessStoreWithoutPermissions();
// Register a user - Negative scenario where the Password & ConfirmPassword do not match. // Register a user - Negative scenario where the Password & ConfirmPassword do not match.
validator.RegisterUserWithNonMatchingPasswords(); await validator.RegisterUserWithNonMatchingPasswords();
// Register a valid user. // Register a valid user.
var generatedEmail = validator.RegisterValidUser(); var generatedEmail = await validator.RegisterValidUser();
validator.SignInWithUser(generatedEmail, "Password~1"); await validator.SignInWithUser(generatedEmail, "Password~1");
// Register a user - Negative scenario : Trying to register a user name that's already registered. // Register a user - Negative scenario : Trying to register a user name that's already registered.
validator.RegisterExistingUser(generatedEmail); await validator.RegisterExistingUser(generatedEmail);
// Logout from this user session - This should take back to the home page // Logout from this user session - This should take back to the home page
validator.SignOutUser(generatedEmail); await validator.SignOutUser(generatedEmail);
// Sign in scenarios: Invalid password - Expected an invalid user name password error. // Sign in scenarios: Invalid password - Expected an invalid user name password error.
validator.SignInWithInvalidPassword(generatedEmail, "InvalidPassword~1"); await validator.SignInWithInvalidPassword(generatedEmail, "InvalidPassword~1");
// Sign in scenarios: Valid user name & password. // Sign in scenarios: Valid user name & password.
validator.SignInWithUser(generatedEmail, "Password~1"); await validator.SignInWithUser(generatedEmail, "Password~1");
// Change password scenario // Change password scenario
validator.ChangePassword(generatedEmail); await validator.ChangePassword(generatedEmail);
// SignIn with old password and verify old password is not allowed and new password is allowed // SignIn with old password and verify old password is not allowed and new password is allowed
validator.SignOutUser(generatedEmail); await validator.SignOutUser(generatedEmail);
validator.SignInWithInvalidPassword(generatedEmail, "Password~1"); await validator.SignInWithInvalidPassword(generatedEmail, "Password~1");
validator.SignInWithUser(generatedEmail, "Password~2"); await validator.SignInWithUser(generatedEmail, "Password~2");
// Making a request to a protected resource that this user does not have access to - should automatically redirect to login page again // Making a request to a protected resource that this user does not have access to - should automatically redirect to login page again
validator.AccessStoreWithoutPermissions(generatedEmail); await validator.AccessStoreWithoutPermissions(generatedEmail);
// Logout from this user session - This should take back to the home page // Logout from this user session - This should take back to the home page
validator.SignOutUser(generatedEmail); await validator.SignOutUser(generatedEmail);
// Login as an admin user // Login as an admin user
validator.SignInWithUser("Administrator@test.com", "YouShouldChangeThisPassword1!"); await validator.SignInWithUser("Administrator@test.com", "YouShouldChangeThisPassword1!");
// Now navigating to the store manager should work fine as this user has the necessary permission to administer the store. // Now navigating to the store manager should work fine as this user has the necessary permission to administer the store.
validator.AccessStoreWithPermissions(); await validator.AccessStoreWithPermissions();
// Create an album // Create an album
var albumName = validator.CreateAlbum(); var albumName = await validator.CreateAlbum();
var albumId = validator.FetchAlbumIdFromName(albumName); var albumId = await validator.FetchAlbumIdFromName(albumName);
// Get details of the album // Get details of the album
validator.VerifyAlbumDetails(albumId, albumName); await validator.VerifyAlbumDetails(albumId, albumName);
// Verify status code pages acts on non-existing items. // Verify status code pages acts on non-existing items.
validator.VerifyStatusCodePages(); await validator.VerifyStatusCodePages();
// Get the non-admin view of the album. // Get the non-admin view of the album.
validator.GetAlbumDetailsFromStore(albumId, albumName); await validator.GetAlbumDetailsFromStore(albumId, albumName);
// Add an album to cart and checkout the same // Add an album to cart and checkout the same
validator.AddAlbumToCart(albumId, albumName); await validator.AddAlbumToCart(albumId, albumName);
validator.CheckOutCartItems(); await validator.CheckOutCartItems();
// Delete the album from store // Delete the album from store
validator.DeleteAlbum(albumId, albumName); await validator.DeleteAlbum(albumId, albumName);
// Logout from this user session - This should take back to the home page // Logout from this user session - This should take back to the home page
validator.SignOutUser("Administrator"); await validator.SignOutUser("Administrator");
// Google login // Google login
validator.LoginWithGoogle(); await validator.LoginWithGoogle();
// Facebook login // Facebook login
validator.LoginWithFacebook(); await validator.LoginWithFacebook();
// Twitter login // Twitter login
validator.LoginWithTwitter(); await validator.LoginWithTwitter();
// MicrosoftAccountLogin // MicrosoftAccountLogin
validator.LoginWithMicrosoftAccount(); await validator.LoginWithMicrosoftAccount();
logger.LogInformation("Variation completed successfully."); logger.LogInformation("Variation completed successfully.");
} }