using System; using System.Collections.Generic; using System.Net; using System.Net.Http; using Xunit; namespace E2ETests { public class SmokeTests { private const string Connection_string_Format = "Server=(localdb)\\v11.0;Database={0};Trusted_Connection=True;MultipleActiveResultSets=true"; private string ApplicationBaseUrl; private HttpClient httpClient; private HttpClientHandler httpClientHandler; [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) { var testStartTime = DateTime.Now; var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); var musicStoreIdentityDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); Console.WriteLine("Pointing MusicStore DB to '{0}'", string.Format(Connection_string_Format, musicStoreDbName)); Console.WriteLine("Pointing MusicStoreIdentity DB to '{0}'", string.Format(Connection_string_Format, musicStoreIdentityDbName)); //Override the connection strings using environment based configuration Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(Connection_string_Format, musicStoreDbName)); Environment.SetEnvironmentVariable("SQLAZURECONNSTR_IdentityConnection", string.Format(Connection_string_Format, musicStoreIdentityDbName)); ApplicationBaseUrl = applicationBaseUrl; var hostProcess = DeploymentUtility.StartApplication(hostType, kreFlavor, musicStoreIdentityDbName); try { httpClientHandler = new HttpClientHandler(); httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(applicationBaseUrl) }; //Request to base address and check if various parts of the body are rendered & measure the cold startup time. var response = httpClient.GetAsync(string.Empty).Result; var responseContent = response.Content.ReadAsStringAsync().Result; var initializationCompleteTime = DateTime.Now; Console.WriteLine("[Time]: Approximate time taken for application initialization : '{0}' seconds", (initializationCompleteTime - testStartTime).TotalSeconds); VerifyHomePage(response, responseContent); //Making a request to a protected resource should automatically redirect to login page AccessStoreWithoutPermissions(); //Register a user - Negative scenario where the Password & ConfirmPassword do not match RegisterUserWithNonMatchingPasswords(); //Register a valid user var generatedUserName = RegisterValidUser(); //Register a user - Negative scenario : Trying to register a user name that's already registered. RegisterExistingUser(generatedUserName); //Logout from this user session - This should take back to the home page SignOutUser(generatedUserName); //Sign in scenarios: Invalid password - Expected an invalid user name password error. SignInWithInvalidPassword(generatedUserName, "InvalidPassword~1"); //Sign in scenarios: Valid user name & password. SignInWithUser(generatedUserName, "Password~1"); //Change password scenario ChangePassword(generatedUserName); //SignIn with old password and verify old password is not allowed and new password is allowed SignOutUser(generatedUserName); SignInWithInvalidPassword(generatedUserName, "Password~1"); SignInWithUser(generatedUserName, "Password~2"); //Making a request to a protected resource that this user does not have access to - should automatically redirect to login page again AccessStoreWithoutPermissions(generatedUserName); //Logout from this user session - This should take back to the home page SignOutUser(generatedUserName); //Login as an admin user SignInWithUser("Administrator", "YouShouldChangeThisPassword1!"); //Now navigating to the store manager should work fine as this user has the necessary permission to administer the store. AccessStoreWithPermissions(); //Create an album var albumName = CreateAlbum(); var albumId = FetchAlbumIdFromName(albumName); //Get details of the album VerifyAlbumDetails(albumId, albumName); //Logout from this user session - This should take back to the home page SignOutUser("Administrator"); var testCompletionTime = DateTime.Now; Console.WriteLine("[Time]: All tests completed in '{0}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds); Console.WriteLine("[Time]: Total time taken for this test variation '{0}' seconds", (testCompletionTime - testStartTime).TotalSeconds); } finally { //Shutdown the host process hostProcess.Kill(); DbUtils.DropDatabase(musicStoreDbName); DbUtils.DropDatabase(musicStoreIdentityDbName); } } private void VerifyHomePage(HttpResponseMessage response, string responseContent) { Console.WriteLine("Home page content : {0}", responseContent); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("
  • Home
  • ", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("Store ", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("