Adding some more test scenarios to MusicStore and moving the scenarios in methods.
This commit is contained in:
parent
8409e9518b
commit
11a71e950d
|
|
@ -23,7 +23,7 @@ namespace MusicStore.Controllers
|
|||
//
|
||||
// GET: /Account/Login
|
||||
[AllowAnonymous]
|
||||
public IActionResult Login(string returnUrl=null)
|
||||
public IActionResult Login(string returnUrl = null)
|
||||
{
|
||||
ViewBag.ReturnUrl = returnUrl;
|
||||
return View();
|
||||
|
|
@ -34,7 +34,7 @@ namespace MusicStore.Controllers
|
|||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl=null)
|
||||
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
|
|
@ -93,7 +93,7 @@ namespace MusicStore.Controllers
|
|||
|
||||
//
|
||||
// GET: /Account/Manage
|
||||
public IActionResult Manage(ManageMessageId? message=null)
|
||||
public IActionResult Manage(ManageMessageId? message = null)
|
||||
{
|
||||
ViewBag.StatusMessage =
|
||||
message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
"DefaultAdminPassword": "YouShouldChangeThisPassword1!",
|
||||
"Data": {
|
||||
"DefaultConnection": {
|
||||
"Connectionstring": "Server=(localdb)\\v11.0;Database=MusicStore7;Trusted_Connection=True;MultipleActiveResultSets=true"
|
||||
"Connectionstring": "Server=(localdb)\\v11.0;Database=MusicStore;Trusted_Connection=True;MultipleActiveResultSets=true"
|
||||
},
|
||||
"IdentityConnection": {
|
||||
"Connectionstring": "Server=(localdb)\\v11.0;Database=MusicStoreIdentity7;Trusted_Connection=True;MultipleActiveResultSets=true"
|
||||
"Connectionstring": "Server=(localdb)\\v11.0;Database=MusicStoreIdentity;Trusted_Connection=True;MultipleActiveResultSets=true"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,11 +8,14 @@ namespace E2ETests
|
|||
{
|
||||
public class SmokeTests
|
||||
{
|
||||
private string ApplicationBaseUrl = null;
|
||||
|
||||
[Theory]
|
||||
[InlineData(HostType.Helios, KreFlavor.DesktopClr, "http://localhost:5001/")]
|
||||
//[InlineData(HostType.SelfHost, KreFlavor.DesktopClr, "http://localhost:5002/")]
|
||||
public void SmokeTestSuite(HostType hostType, KreFlavor kreFlavor, string applicationBaseUrl)
|
||||
{
|
||||
ApplicationBaseUrl = applicationBaseUrl;
|
||||
var hostProcess = DeploymentUtility.StartApplication(hostType, kreFlavor);
|
||||
|
||||
try
|
||||
|
|
@ -21,32 +24,127 @@ namespace E2ETests
|
|||
var httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(applicationBaseUrl) };
|
||||
|
||||
//Request to base address and check if various parts of the body are rendered
|
||||
var response = httpClient.GetAsync(string.Empty).Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Console.WriteLine("Home page content : {0}", responseContent);
|
||||
Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Register", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Login", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("mvcmusicstore.codeplex.com", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("/Images/home-showcase.png", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Console.WriteLine("Application initialization successful.");
|
||||
VerifyHomePage(httpClient);
|
||||
|
||||
//Making a request to a protected resource should automatically redirect to login page
|
||||
Console.WriteLine("Trying to access StoreManager without signing in..");
|
||||
response = httpClient.GetAsync("/StoreManager/").Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Contains("<h4>Use a local account to log in.</h4>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Equal<string>(applicationBaseUrl + "Account/Login?ReturnUrl=%2FStoreManager%2F", response.RequestMessage.RequestUri.AbsoluteUri);
|
||||
Console.WriteLine("Redirected to login page as expected.");
|
||||
AccessStoreWithoutPermissions(httpClient);
|
||||
|
||||
//Register a user - Need a way to get the antiforgery token and send it in the request as a form encoded parameter
|
||||
response = httpClient.GetAsync("/Account/Register").Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
//Register a user - Negative scenario where the Password & ConfirmPassword do not match
|
||||
RegisterUserWithNonMatchingPasswords(httpClient, httpClientHandler);
|
||||
|
||||
var generatedUserName = Guid.NewGuid().ToString().Replace("-", string.Empty);
|
||||
Console.WriteLine("Creating a new user with name '{0}'", generatedUserName);
|
||||
var formParameters = new List<KeyValuePair<string, string>>
|
||||
//Register a valid user
|
||||
var generatedUserName = RegisterValidUser(httpClient, httpClientHandler);
|
||||
|
||||
//Register a user - Negative scenario : Trying to register a user name that's already registered.
|
||||
RegisterExistingUser(httpClient, httpClientHandler, generatedUserName);
|
||||
|
||||
//Logout from this user session - This should take back to the home page
|
||||
SignOutUser(httpClient, httpClientHandler, generatedUserName);
|
||||
|
||||
//Sign in scenarios: Invalid password - Expected an invalid user name password error.
|
||||
SignInWithInvalidPassword(httpClient, httpClientHandler, generatedUserName);
|
||||
|
||||
//Sign in scenarios: Valid user name & password.
|
||||
SignInWithUser(httpClient, httpClientHandler, generatedUserName, "Password~1");
|
||||
|
||||
//Change password scenario
|
||||
ChangePassword(httpClient, httpClientHandler, generatedUserName);
|
||||
|
||||
//Making a request to a protected resource that this user does not have access to - should automatically redirect to login page again
|
||||
AccessStoreWithoutPermissions(httpClient, generatedUserName);
|
||||
|
||||
//Logout from this user session - This should take back to the home page
|
||||
SignOutUser(httpClient, httpClientHandler, generatedUserName);
|
||||
|
||||
//Login as an admin user
|
||||
SignInWithUser(httpClient, httpClientHandler, "Administrator", "YouShouldChangeThisPassword1!");
|
||||
|
||||
//Now navigating to the store manager should work fine as this user has the necessary permission to administer the store.
|
||||
AccessStoreWithPermissions(httpClient);
|
||||
|
||||
//Create an album
|
||||
CreateAlbum(httpClient, httpClientHandler);
|
||||
|
||||
//Logout from this user session - This should take back to the home page
|
||||
SignOutUser(httpClient, httpClientHandler, "Administrator");
|
||||
}
|
||||
finally
|
||||
{
|
||||
//Shutdown the host process
|
||||
hostProcess.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
private void VerifyHomePage(HttpClient httpClient)
|
||||
{
|
||||
var response = httpClient.GetAsync(string.Empty).Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Console.WriteLine("Home page content : {0}", responseContent);
|
||||
Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<li><a href=\"/\">Home</a></li>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<a class=\"dropdown-toggle\" data-toggle=\"dropdown\">Store <b class=\"caret\"></b></a>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<ul class=\"dropdown-menu\">", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<li class=\"divider\"></li>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<a href=\"/Store/Details/", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Register", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Login", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("mvcmusicstore.codeplex.com", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("/Images/home-showcase.png", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Console.WriteLine("Application initialization successful.");
|
||||
}
|
||||
|
||||
private void AccessStoreWithoutPermissions(HttpClient httpClient, string generatedUserName = null)
|
||||
{
|
||||
Console.WriteLine("Trying to access StoreManager that needs ManageStore claim with the current user : {0}", generatedUserName ?? "Anonymous");
|
||||
var response = httpClient.GetAsync("/StoreManager/").Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Contains("<h4>Use a local account to log in.</h4>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Equal<string>(ApplicationBaseUrl + "Account/Login?ReturnUrl=%2FStoreManager%2F", response.RequestMessage.RequestUri.AbsoluteUri);
|
||||
Console.WriteLine("Redirected to login page as expected.");
|
||||
}
|
||||
|
||||
private void AccessStoreWithPermissions(HttpClient httpClient)
|
||||
{
|
||||
Console.WriteLine("Trying to access the store inventory..");
|
||||
var response = httpClient.GetAsync("/StoreManager/").Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Equal<string>(ApplicationBaseUrl + "StoreManager/", response.RequestMessage.RequestUri.AbsoluteUri);
|
||||
Console.WriteLine("Successfully acccessed the store inventory");
|
||||
}
|
||||
|
||||
private void RegisterUserWithNonMatchingPasswords(HttpClient httpClient, HttpClientHandler httpClientHandler)
|
||||
{
|
||||
Console.WriteLine("Trying to create user with not matching password and confirm password");
|
||||
var response = httpClient.GetAsync("/Account/Register").Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
var generatedUserName = Guid.NewGuid().ToString().Replace("-", string.Empty);
|
||||
Console.WriteLine("Creating a new user with name '{0}'", generatedUserName);
|
||||
var formParameters = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("UserName", generatedUserName),
|
||||
new KeyValuePair<string, string>("Password", "Password~1"),
|
||||
new KeyValuePair<string, string>("ConfirmPassword", "Password~2"),
|
||||
new KeyValuePair<string, string>("__RequestVerificationToken", HtmlDOMHelper.RetrieveAntiForgeryToken(responseContent, "/Account/Register")),
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/Account/Register", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Null(httpClientHandler.CookieContainer.GetCookies(new Uri(ApplicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Security.Application"));
|
||||
Assert.Contains("The password and confirmation password do not match.", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Console.WriteLine("Server side model validator rejected the user '{0}''s registration as passwords do not match.", generatedUserName);
|
||||
}
|
||||
|
||||
private string RegisterValidUser(HttpClient httpClient, HttpClientHandler httpClientHandler)
|
||||
{
|
||||
var response = httpClient.GetAsync("/Account/Register").Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
var generatedUserName = Guid.NewGuid().ToString().Replace("-", string.Empty);
|
||||
Console.WriteLine("Creating a new user with name '{0}'", generatedUserName);
|
||||
var formParameters = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("UserName", generatedUserName),
|
||||
new KeyValuePair<string, string>("Password", "Password~1"),
|
||||
|
|
@ -54,73 +152,132 @@ namespace E2ETests
|
|||
new KeyValuePair<string, string>("__RequestVerificationToken", HtmlDOMHelper.RetrieveAntiForgeryToken(responseContent, "/Account/Register")),
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/Account/Register", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Contains(string.Format("Hello {0}!", generatedUserName), responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
//Verify cookie sent
|
||||
Assert.NotNull(httpClientHandler.CookieContainer.GetCookies(new Uri(applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Security.Application"));
|
||||
Console.WriteLine("Successfully registered user '{0}' and signed in", generatedUserName);
|
||||
var content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/Account/Register", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Contains(string.Format("Hello {0}!", generatedUserName), responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
//Verify cookie sent
|
||||
Assert.NotNull(httpClientHandler.CookieContainer.GetCookies(new Uri(ApplicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Security.Application"));
|
||||
Console.WriteLine("Successfully registered user '{0}' and signed in", generatedUserName);
|
||||
return generatedUserName;
|
||||
}
|
||||
|
||||
//Making a request to a protected resource that this user does not have access to - should automatically redirect to login page again
|
||||
Console.WriteLine("Trying to access StoreManager that needs special permissions that {0} does not claim", generatedUserName);
|
||||
response = httpClient.GetAsync("/StoreManager/").Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Contains("<h4>Use a local account to log in.</h4>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Equal<string>(applicationBaseUrl + "Account/Login?ReturnUrl=%2FStoreManager%2F", response.RequestMessage.RequestUri.AbsoluteUri);
|
||||
Console.WriteLine("Redirected to login page as expected.");
|
||||
private void RegisterExistingUser(HttpClient httpClient, HttpClientHandler httpClientHandler, string generatedUserName)
|
||||
{
|
||||
Console.WriteLine("Trying to register a user with name '{0}' again", generatedUserName);
|
||||
var response = httpClient.GetAsync("/Account/Register").Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Console.WriteLine("Creating a new user with name '{0}'", generatedUserName);
|
||||
var formParameters = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("UserName", generatedUserName),
|
||||
new KeyValuePair<string, string>("Password", "Password~1"),
|
||||
new KeyValuePair<string, string>("ConfirmPassword", "Password~1"),
|
||||
new KeyValuePair<string, string>("__RequestVerificationToken", HtmlDOMHelper.RetrieveAntiForgeryToken(responseContent, "/Account/Register")),
|
||||
};
|
||||
|
||||
//Logout from this user session - This should take back to the home page
|
||||
Console.WriteLine("Signing out from '{0}''s session", generatedUserName);
|
||||
formParameters = new List<KeyValuePair<string, string>>
|
||||
var content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/Account/Register", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
//Bug? Registering the same user again does not throw this error
|
||||
Assert.Contains(string.Format("Name {0} is already taken.", generatedUserName), responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Console.WriteLine("Identity threw a valid exception that user '{0}' already exists in the system", generatedUserName);
|
||||
}
|
||||
|
||||
private void SignOutUser(HttpClient httpClient, HttpClientHandler httpClientHandler, string generatedUserName)
|
||||
{
|
||||
Console.WriteLine("Signing out from '{0}''s session", generatedUserName);
|
||||
var response = httpClient.GetAsync(string.Empty).Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
var formParameters = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("__RequestVerificationToken", HtmlDOMHelper.RetrieveAntiForgeryToken(responseContent, "/Account/LogOff")),
|
||||
};
|
||||
|
||||
content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/Account/LogOff", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Register", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Login", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("mvcmusicstore.codeplex.com", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("/Images/home-showcase.png", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
//Verify cookie cleared on logout
|
||||
Assert.Null(httpClientHandler.CookieContainer.GetCookies(new Uri(applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Security.Application"));
|
||||
Console.WriteLine("Successfully signed out of '{0}''s session", generatedUserName);
|
||||
var content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/Account/LogOff", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Register", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Login", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("mvcmusicstore.codeplex.com", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("/Images/home-showcase.png", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
//Verify cookie cleared on logout
|
||||
Assert.Null(httpClientHandler.CookieContainer.GetCookies(new Uri(ApplicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Security.Application"));
|
||||
Console.WriteLine("Successfully signed out of '{0}''s session", generatedUserName);
|
||||
}
|
||||
|
||||
//Login as an admin user
|
||||
Console.WriteLine("Signing in as '{0}'", "Administrator");
|
||||
response = httpClient.GetAsync("/Account/Login").Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
formParameters = new List<KeyValuePair<string, string>>
|
||||
private void SignInWithInvalidPassword(HttpClient httpClient, HttpClientHandler httpClientHandler, string generatedUserName)
|
||||
{
|
||||
var response = httpClient.GetAsync("/Account/Login").Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Console.WriteLine("Signing in with user '{0}'", generatedUserName);
|
||||
var formParameters = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("UserName", "Administrator"),
|
||||
new KeyValuePair<string, string>("Password", "YouShouldChangeThisPassword1!"),
|
||||
new KeyValuePair<string, string>("UserName", generatedUserName),
|
||||
new KeyValuePair<string, string>("Password", "InvalidPassword~1"),
|
||||
new KeyValuePair<string, string>("__RequestVerificationToken", HtmlDOMHelper.RetrieveAntiForgeryToken(responseContent, "/Account/Login")),
|
||||
};
|
||||
|
||||
content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/Account/Login", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Contains(string.Format("Hello {0}!", "Administrator"), responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Console.WriteLine("Successfully signed in as '{0}'", "Administrator");
|
||||
var content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/Account/Login", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Contains("<div class=\"validation-summary-errors\"><ul><li>Invalid username or password.</li>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
//Verify cookie not sent
|
||||
Assert.Null(httpClientHandler.CookieContainer.GetCookies(new Uri(ApplicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Security.Application"));
|
||||
Console.WriteLine("Identity successfully prevented an invalid user login.");
|
||||
}
|
||||
|
||||
//Now navigating to the store manager should work fine as this user has the necessary permission to administer the store.
|
||||
Console.WriteLine("Trying to access the store inventory..");
|
||||
response = httpClient.GetAsync("/StoreManager/").Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Equal<string>(applicationBaseUrl + "StoreManager/", response.RequestMessage.RequestUri.AbsoluteUri);
|
||||
Console.WriteLine("Successfully acccessed the store inventory");
|
||||
private void SignInWithUser(HttpClient httpClient, HttpClientHandler httpClientHandler, string generatedUserName, string password)
|
||||
{
|
||||
var response = httpClient.GetAsync("/Account/Login").Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Console.WriteLine("Signing in with user '{0}'", generatedUserName);
|
||||
var formParameters = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("UserName", generatedUserName),
|
||||
new KeyValuePair<string, string>("Password", password),
|
||||
new KeyValuePair<string, string>("__RequestVerificationToken", HtmlDOMHelper.RetrieveAntiForgeryToken(responseContent, "/Account/Login")),
|
||||
};
|
||||
|
||||
//Create an album
|
||||
var albumName = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12);
|
||||
Console.WriteLine("Trying to create an album with name '{0}'", albumName);
|
||||
response = httpClient.GetAsync("/StoreManager/create").Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
formParameters = new List<KeyValuePair<string, string>>
|
||||
var content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/Account/Login", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Contains(string.Format("Hello {0}!", generatedUserName), responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
//Verify cookie sent
|
||||
Assert.NotNull(httpClientHandler.CookieContainer.GetCookies(new Uri(ApplicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Security.Application"));
|
||||
Console.WriteLine("Successfully signed in with user '{0}'", generatedUserName);
|
||||
}
|
||||
|
||||
private void ChangePassword(HttpClient httpClient, HttpClientHandler httpClientHandler, string generatedUserName)
|
||||
{
|
||||
var response = httpClient.GetAsync("/Account/Manage").Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
var formParameters = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("OldPassword", "Password~1"),
|
||||
new KeyValuePair<string, string>("NewPassword", "Password~2"),
|
||||
new KeyValuePair<string, string>("ConfirmPassword", "Password~2"),
|
||||
new KeyValuePair<string, string>("__RequestVerificationToken", HtmlDOMHelper.RetrieveAntiForgeryToken(responseContent, "/Account/Manage")),
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/Account/Manage", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Contains("Your password has been changed.", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.NotNull(httpClientHandler.CookieContainer.GetCookies(new Uri(ApplicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Security.Application"));
|
||||
Console.WriteLine("Successfully changed the password for user '{0}'", generatedUserName);
|
||||
}
|
||||
|
||||
private void CreateAlbum(HttpClient httpClient, HttpClientHandler httpClientHandler)
|
||||
{
|
||||
var albumName = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12);
|
||||
Console.WriteLine("Trying to create an album with name '{0}'", albumName);
|
||||
var response = httpClient.GetAsync("/StoreManager/create").Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
var formParameters = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("__RequestVerificationToken", HtmlDOMHelper.RetrieveAntiForgeryToken(responseContent, "/StoreManager/create")),
|
||||
new KeyValuePair<string, string>("GenreId", "1"),
|
||||
|
|
@ -130,37 +287,12 @@ namespace E2ETests
|
|||
new KeyValuePair<string, string>("AlbumArtUrl", "TestUrl"),
|
||||
};
|
||||
|
||||
content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/StoreManager/create", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Equal<string>(applicationBaseUrl + "StoreManager", response.RequestMessage.RequestUri.AbsoluteUri);
|
||||
Assert.Contains(albumName, responseContent);
|
||||
Console.WriteLine("Successfully created an album with name '{0}' in the store", albumName);
|
||||
|
||||
//Logout from this user session - This should take back to the home page
|
||||
Console.WriteLine("Signing out of '{0}''s session", "Administrator");
|
||||
formParameters = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("__RequestVerificationToken", HtmlDOMHelper.RetrieveAntiForgeryToken(responseContent, "/Account/LogOff")),
|
||||
};
|
||||
|
||||
content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/Account/LogOff", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Register", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Login", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("mvcmusicstore.codeplex.com", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("/Images/home-showcase.png", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
//Verify cookie cleared on logout
|
||||
Assert.Null(httpClientHandler.CookieContainer.GetCookies(new Uri(applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Security.Application"));
|
||||
Console.WriteLine("Successfully signed out of '{0}''s session", "Administrator");
|
||||
}
|
||||
finally
|
||||
{
|
||||
//Shutdown the host process
|
||||
hostProcess.Kill();
|
||||
}
|
||||
var content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = httpClient.PostAsync("/StoreManager/create", content).Result;
|
||||
responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
Assert.Equal<string>(ApplicationBaseUrl + "StoreManager", response.RequestMessage.RequestUri.AbsoluteUri);
|
||||
Assert.Contains(albumName, responseContent);
|
||||
Console.WriteLine("Successfully created an album with name '{0}' in the store", albumName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue