Logging API changes

This commit is contained in:
Brennan 2015-03-04 21:17:32 -08:00
parent a1e5048a0a
commit c230aa23e1
15 changed files with 2703 additions and 2312 deletions

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@ namespace E2ETests
{ {
try try
{ {
logger.WriteInformation("Trying to drop database '{0}'", databaseName); logger.LogInformation("Trying to drop database '{0}'", databaseName);
using (var conn = new SqlConnection(@"Server=(localdb)\MSSQLLocalDB;Database=master;Trusted_Connection=True;")) using (var conn = new SqlConnection(@"Server=(localdb)\MSSQLLocalDB;Database=master;Trusted_Connection=True;"))
{ {
conn.Open(); conn.Open();
@ -26,13 +26,13 @@ namespace E2ETests
END", databaseName); END", databaseName);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
logger.WriteInformation("Successfully dropped database {0}", databaseName); logger.LogInformation("Successfully dropped database {0}", databaseName);
} }
} }
catch (Exception exception) catch (Exception exception)
{ {
//Ignore if there is failure in cleanup. //Ignore if there is failure in cleanup.
logger.WriteWarning("Error occured while dropping database {0}. Exception : {1}", databaseName, exception.ToString()); logger.LogWarning("Error occured while dropping database {0}. Exception : {1}", databaseName, exception.ToString());
} }
} }
} }

View File

@ -105,19 +105,19 @@ namespace E2ETests
KpmBundle(startParameters, logger, Path.Combine(Environment.GetEnvironmentVariable("SystemDrive") + @"\", @"inetpub\wwwroot")); KpmBundle(startParameters, logger, Path.Combine(Environment.GetEnvironmentVariable("SystemDrive") + @"\", @"inetpub\wwwroot"));
// Drop a Microsoft.AspNet.Hosting.ini with ASPNET_ENV information. // Drop a Microsoft.AspNet.Hosting.ini with ASPNET_ENV information.
logger.WriteInformation("Creating Microsoft.AspNet.Hosting.ini file with ASPNET_ENV."); logger.LogInformation("Creating Microsoft.AspNet.Hosting.ini file with ASPNET_ENV.");
var iniFile = Path.Combine(startParameters.ApplicationPath, "Microsoft.AspNet.Hosting.ini"); var iniFile = Path.Combine(startParameters.ApplicationPath, "Microsoft.AspNet.Hosting.ini");
File.WriteAllText(iniFile, string.Format("ASPNET_ENV={0}", startParameters.EnvironmentName)); File.WriteAllText(iniFile, string.Format("ASPNET_ENV={0}", startParameters.EnvironmentName));
// Can't use localdb with IIS. Setting an override to use InMemoryStore. // Can't use localdb with IIS. Setting an override to use InMemoryStore.
logger.WriteInformation("Creating configoverride.json file to override default config."); logger.LogInformation("Creating configoverride.json file to override default config.");
var overrideConfig = Path.Combine(startParameters.ApplicationPath, "..", "approot", "src", "MusicStore", "configoverride.json"); var overrideConfig = Path.Combine(startParameters.ApplicationPath, "..", "approot", "src", "MusicStore", "configoverride.json");
overrideConfig = Path.GetFullPath(overrideConfig); overrideConfig = Path.GetFullPath(overrideConfig);
File.WriteAllText(overrideConfig, "{\"UseInMemoryStore\": \"true\"}"); File.WriteAllText(overrideConfig, "{\"UseInMemoryStore\": \"true\"}");
if (startParameters.ServerType == ServerType.IISNativeModule) if (startParameters.ServerType == ServerType.IISNativeModule)
{ {
logger.WriteInformation("Turning runAllManagedModulesForAllRequests=true in web.config."); logger.LogInformation("Turning runAllManagedModulesForAllRequests=true in web.config.");
// Set runAllManagedModulesForAllRequests=true // Set runAllManagedModulesForAllRequests=true
var webConfig = Path.Combine(startParameters.ApplicationPath, "web.config"); var webConfig = Path.Combine(startParameters.ApplicationPath, "web.config");
var configuration = new XmlDocument(); var configuration = new XmlDocument();
@ -134,7 +134,7 @@ namespace E2ETests
configuration.Save(webConfig); configuration.Save(webConfig);
} }
logger.WriteInformation("Successfully finished IIS application directory setup."); logger.LogInformation("Successfully finished IIS application directory setup.");
Thread.Sleep(1 * 1000); Thread.Sleep(1 * 1000);
} }
@ -189,12 +189,12 @@ namespace E2ETests
} }
//Mono now supports --appbase //Mono now supports --appbase
logger.WriteInformation("Setting the --appbase to {0}", startParameters.ApplicationPath); logger.LogInformation("Setting the --appbase to {0}", startParameters.ApplicationPath);
var bootstrapper = "klr"; var bootstrapper = "klr";
var commandName = startParameters.ServerType == ServerType.Kestrel ? "kestrel" : string.Empty; var commandName = startParameters.ServerType == ServerType.Kestrel ? "kestrel" : string.Empty;
logger.WriteInformation("Executing command: {klr} {appPath} {command}", bootstrapper, startParameters.ApplicationPath, commandName); logger.LogInformation("Executing command: {klr} {appPath} {command}", bootstrapper, startParameters.ApplicationPath, commandName);
var startInfo = new ProcessStartInfo var startInfo = new ProcessStartInfo
{ {
@ -206,11 +206,11 @@ namespace E2ETests
}; };
var hostProcess = Process.Start(startInfo); var hostProcess = Process.Start(startInfo);
logger.WriteInformation("Started {0}. Process Id : {1}", hostProcess.MainModule.FileName, hostProcess.Id); logger.LogInformation("Started {0}. Process Id : {1}", hostProcess.MainModule.FileName, hostProcess.Id);
if (hostProcess.HasExited) if (hostProcess.HasExited)
{ {
logger.WriteError("Host process {processName} exited with code {exitCode} or failed to start.", startInfo.FileName, hostProcess.ExitCode); logger.LogError("Host process {processName} exited with code {exitCode} or failed to start.", startInfo.FileName, hostProcess.ExitCode);
throw new Exception("Failed to start host"); throw new Exception("Failed to start host");
} }
@ -249,7 +249,7 @@ namespace E2ETests
var iisExpressPath = GetIISExpressPath(startParameters.RuntimeArchitecture); var iisExpressPath = GetIISExpressPath(startParameters.RuntimeArchitecture);
logger.WriteInformation("Executing command : {iisExpress} {args}", iisExpressPath, parameters); logger.LogInformation("Executing command : {iisExpress} {args}", iisExpressPath, parameters);
var startInfo = new ProcessStartInfo var startInfo = new ProcessStartInfo
{ {
@ -260,7 +260,7 @@ namespace E2ETests
}; };
var hostProcess = Process.Start(startInfo); var hostProcess = Process.Start(startInfo);
logger.WriteInformation("Started iisexpress. Process Id : {processId}", hostProcess.Id); logger.LogInformation("Started iisexpress. Process Id : {processId}", hostProcess.Id);
return hostProcess; return hostProcess;
} }
@ -268,7 +268,7 @@ namespace E2ETests
private static Process StartSelfHost(StartParameters startParameters, ILogger logger) private static Process StartSelfHost(StartParameters startParameters, ILogger logger)
{ {
var commandName = startParameters.ServerType == ServerType.WebListener ? "web" : "kestrel"; var commandName = startParameters.ServerType == ServerType.WebListener ? "web" : "kestrel";
logger.WriteInformation("Executing klr.exe --appbase {appPath} \"Microsoft.Framework.ApplicationHost\" {command}", startParameters.ApplicationPath, commandName); logger.LogInformation("Executing klr.exe --appbase {appPath} \"Microsoft.Framework.ApplicationHost\" {command}", startParameters.ApplicationPath, commandName);
var startInfo = new ProcessStartInfo var startInfo = new ProcessStartInfo
{ {
@ -284,17 +284,17 @@ namespace E2ETests
if (hostProcess.HasExited) if (hostProcess.HasExited)
{ {
logger.WriteError("Host process {processName} exited with code {exitCode} or failed to start.", startInfo.FileName, hostProcess.ExitCode); logger.LogError("Host process {processName} exited with code {exitCode} or failed to start.", startInfo.FileName, hostProcess.ExitCode);
throw new Exception("Failed to start host"); throw new Exception("Failed to start host");
} }
try try
{ {
logger.WriteInformation("Started {fileName}. Process Id : {processId}", hostProcess.MainModule.FileName, hostProcess.Id); logger.LogInformation("Started {fileName}. Process Id : {processId}", hostProcess.MainModule.FileName, hostProcess.Id);
} }
catch (Win32Exception win32Exception) catch (Win32Exception win32Exception)
{ {
logger.WriteWarning("Cannot access 64 bit modules from a 32 bit process. Failed with following message.", win32Exception); logger.LogWarning("Cannot access 64 bit modules from a 32 bit process. Failed with following message.", win32Exception);
} }
return hostProcess; return hostProcess;
@ -303,8 +303,8 @@ namespace E2ETests
private static string SwitchPathToRuntimeFlavor(RuntimeFlavor runtimeFlavor, RuntimeArchitecture runtimeArchitecture, ILogger logger) private static string SwitchPathToRuntimeFlavor(RuntimeFlavor runtimeFlavor, RuntimeArchitecture runtimeArchitecture, ILogger logger)
{ {
var pathValue = Environment.GetEnvironmentVariable("PATH"); var pathValue = Environment.GetEnvironmentVariable("PATH");
logger.WriteInformation(string.Empty); logger.LogInformation(string.Empty);
logger.WriteInformation("Current %PATH% value : {0}", pathValue); logger.LogInformation("Current %PATH% value : {0}", pathValue);
var replaceStr = new StringBuilder(). var replaceStr = new StringBuilder().
Append("kre"). Append("kre").
@ -322,8 +322,8 @@ namespace E2ETests
// Tweak the %PATH% to the point to the right RUNTIMEFLAVOR. // Tweak the %PATH% to the point to the right RUNTIMEFLAVOR.
Environment.SetEnvironmentVariable("PATH", pathValue); Environment.SetEnvironmentVariable("PATH", pathValue);
logger.WriteInformation(string.Empty); logger.LogInformation(string.Empty);
logger.WriteInformation("Changing to use runtime : {runtime}", runtimeName); logger.LogInformation("Changing to use runtime : {runtime}", runtimeName);
return runtimeName; return runtimeName;
} }
@ -332,7 +332,7 @@ namespace E2ETests
startParameters.BundledApplicationRootPath = Path.Combine(bundleRoot ?? Path.GetTempPath(), Guid.NewGuid().ToString()); startParameters.BundledApplicationRootPath = Path.Combine(bundleRoot ?? Path.GetTempPath(), Guid.NewGuid().ToString());
var parameters = string.Format("bundle {0} -o {1} --runtime {2}", startParameters.ApplicationPath, startParameters.BundledApplicationRootPath, startParameters.Runtime); var parameters = string.Format("bundle {0} -o {1} --runtime {2}", startParameters.ApplicationPath, startParameters.BundledApplicationRootPath, startParameters.Runtime);
logger.WriteInformation("Executing command kpm {args}", parameters); logger.LogInformation("Executing command kpm {args}", parameters);
var startInfo = new ProcessStartInfo var startInfo = new ProcessStartInfo
{ {
@ -352,7 +352,7 @@ namespace E2ETests
Path.Combine(startParameters.BundledApplicationRootPath, "wwwroot") : Path.Combine(startParameters.BundledApplicationRootPath, "wwwroot") :
Path.Combine(startParameters.BundledApplicationRootPath, "approot", "src", "MusicStore"); Path.Combine(startParameters.BundledApplicationRootPath, "approot", "src", "MusicStore");
logger.WriteInformation("kpm bundle finished with exit code : {exitCode}", hostProcess.ExitCode); logger.LogInformation("kpm bundle finished with exit code : {exitCode}", hostProcess.ExitCode);
} }
public static void CleanUpApplication(StartParameters startParameters, Process hostProcess, string musicStoreDbName, ILogger logger) public static void CleanUpApplication(StartParameters startParameters, Process hostProcess, string musicStoreDbName, ILogger logger)
@ -375,16 +375,16 @@ namespace E2ETests
hostProcess.WaitForExit(5 * 1000); hostProcess.WaitForExit(5 * 1000);
if (!hostProcess.HasExited) if (!hostProcess.HasExited)
{ {
logger.WriteWarning("Unable to terminate the host process with process Id '{processId}", hostProcess.Id); logger.LogWarning("Unable to terminate the host process with process Id '{processId}", hostProcess.Id);
} }
else else
{ {
logger.WriteInformation("Successfully terminated host process with process Id '{processId}'", hostProcess.Id); logger.LogInformation("Successfully terminated host process with process Id '{processId}'", hostProcess.Id);
} }
} }
else else
{ {
logger.WriteWarning("Host process already exited or never started successfully."); logger.LogWarning("Host process already exited or never started successfully.");
} }
if (!Helpers.RunningOnMono) if (!Helpers.RunningOnMono)
@ -405,7 +405,7 @@ namespace E2ETests
catch (Exception exception) catch (Exception exception)
{ {
//Ignore delete failures - just write a log //Ignore delete failures - just write a log
logger.WriteWarning("Failed to delete '{config}'. Exception : {exception}", startParameters.ApplicationHostConfigLocation, exception.Message); logger.LogWarning("Failed to delete '{config}'. Exception : {exception}", startParameters.ApplicationHostConfigLocation, exception.Message);
} }
} }
} }
@ -419,7 +419,7 @@ namespace E2ETests
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.WriteWarning("Failed to delete directory.", exception); logger.LogWarning("Failed to delete directory.", exception);
} }
} }
} }

View File

@ -22,7 +22,7 @@ namespace E2ETests
{ {
try try
{ {
logger.WriteWarning("Retry count {retryCount}..", retry + 1); logger.LogWarning("Retry count {retryCount}..", retry + 1);
retryBlock(); retryBlock();
break; //Went through successfully break; //Went through successfully
} }
@ -34,7 +34,7 @@ namespace E2ETests
#endif #endif
) )
{ {
logger.WriteWarning("Failed to complete the request.", exception); logger.LogWarning("Failed to complete the request.", exception);
Thread.Sleep(7 * 1000); //Wait for a while before retry. Thread.Sleep(7 * 1000); //Wait for a while before retry.
} }
} }

View File

@ -59,7 +59,7 @@ namespace E2ETests
applicationPool.ManagedRuntimeVersion = NATIVE_MODULE_MANAGED_RUNTIME_VERSION; applicationPool.ManagedRuntimeVersion = NATIVE_MODULE_MANAGED_RUNTIME_VERSION;
} }
applicationPool.Enable32BitAppOnWin64 = (_startParameters.RuntimeArchitecture == RuntimeArchitecture.x86); applicationPool.Enable32BitAppOnWin64 = (_startParameters.RuntimeArchitecture == RuntimeArchitecture.x86);
_logger.WriteInformation("Created {bit} application pool '{name}' with runtime version '{runtime}'.", _logger.LogInformation("Created {bit} application pool '{name}' with runtime version '{runtime}'.",
_startParameters.RuntimeArchitecture, applicationPool.Name, _startParameters.RuntimeArchitecture, applicationPool.Name,
applicationPool.ManagedRuntimeVersion ?? "default"); applicationPool.ManagedRuntimeVersion ?? "default");
return applicationPool; return applicationPool;
@ -67,14 +67,14 @@ namespace E2ETests
public void StopAndDeleteAppPool() public void StopAndDeleteAppPool()
{ {
_logger.WriteInformation("Stopping application pool '{name}' and deleting application.", _applicationPool.Name); _logger.LogInformation("Stopping application pool '{name}' and deleting application.", _applicationPool.Name);
_applicationPool.Stop(); _applicationPool.Stop();
// Remove the application from website. // Remove the application from website.
_application = Website.Applications.Where(a => a.Path == _application.Path).FirstOrDefault(); _application = Website.Applications.Where(a => a.Path == _application.Path).FirstOrDefault();
Website.Applications.Remove(_application); Website.Applications.Remove(_application);
_serverManager.ApplicationPools.Remove(_serverManager.ApplicationPools[_applicationPool.Name]); _serverManager.ApplicationPools.Remove(_serverManager.ApplicationPools[_applicationPool.Name]);
_serverManager.CommitChanges(); _serverManager.CommitChanges();
_logger.WriteInformation("Successfully stopped application pool '{name}' and deleted application from IIS.", _applicationPool.Name); _logger.LogInformation("Successfully stopped application pool '{name}' and deleted application from IIS.", _applicationPool.Name);
} }
} }
} }

View File

@ -19,7 +19,7 @@ namespace E2ETests
var response = _httpClient.GetAsync("Account/Login").Result; var response = _httpClient.GetAsync("Account/Login").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
_logger.WriteInformation("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>>
{ {
new KeyValuePair<string, string>("provider", "Facebook"), new KeyValuePair<string, string>("provider", "Facebook"),
@ -85,14 +85,14 @@ namespace E2ETests
//Verify cookie sent //Verify cookie sent
Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.ExternalLogin")); Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.ExternalLogin"));
_logger.WriteInformation("Successfully signed in with user '{email}'", "AspnetvnextTest@test.com"); _logger.LogInformation("Successfully signed in with user '{email}'", "AspnetvnextTest@test.com");
_logger.WriteInformation("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 = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123")).Result;
//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.WriteInformation("Middleware notifications were fired successfully"); _logger.LogInformation("Middleware notifications were fired successfully");
} }
} }
} }

View File

@ -19,7 +19,7 @@ namespace E2ETests
var response = _httpClient.GetAsync("Account/Login").Result; var response = _httpClient.GetAsync("Account/Login").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
_logger.WriteInformation("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>>
{ {
new KeyValuePair<string, string>("provider", "Google"), new KeyValuePair<string, string>("provider", "Google"),
@ -86,15 +86,15 @@ namespace E2ETests
//Verify cookie sent //Verify cookie sent
Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.ExternalLogin")); Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.ExternalLogin"));
_logger.WriteInformation("Successfully signed in with user '{email}'", "AspnetvnextTest@gmail.com"); _logger.LogInformation("Successfully signed in with user '{email}'", "AspnetvnextTest@gmail.com");
_logger.WriteInformation("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 = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123")).Result;
//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.WriteVerbose(response.Content.ReadAsStringAsync().Result); _logger.LogVerbose(response.Content.ReadAsStringAsync().Result);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
_logger.WriteInformation("Middleware notifications were fired successfully"); _logger.LogInformation("Middleware notifications were fired successfully");
} }
} }
} }

View File

@ -19,7 +19,7 @@ namespace E2ETests
var response = _httpClient.GetAsync("Account/Login").Result; var response = _httpClient.GetAsync("Account/Login").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
_logger.WriteInformation("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>>
{ {
new KeyValuePair<string, string>("provider", "Microsoft"), new KeyValuePair<string, string>("provider", "Microsoft"),
@ -85,15 +85,15 @@ namespace E2ETests
//Verify cookie sent //Verify cookie sent
Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.ExternalLogin")); Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.ExternalLogin"));
_logger.WriteInformation("Successfully signed in with user '{email}'", "microsoft@test.com"); _logger.LogInformation("Successfully signed in with user '{email}'", "microsoft@test.com");
_logger.WriteInformation("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 = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123")).Result;
//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.WriteInformation(response.Content.ReadAsStringAsync().Result); _logger.LogInformation(response.Content.ReadAsStringAsync().Result);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
_logger.WriteInformation("Middleware notifications were fired successfully"); _logger.LogInformation("Middleware notifications were fired successfully");
} }
} }
} }

View File

@ -19,7 +19,7 @@ namespace E2ETests
var response = _httpClient.GetAsync("Account/Login").Result; var response = _httpClient.GetAsync("Account/Login").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
_logger.WriteInformation("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>>
{ {
new KeyValuePair<string, string>("provider", "OpenIdConnect"), new KeyValuePair<string, string>("provider", "OpenIdConnect"),
@ -74,16 +74,16 @@ namespace E2ETests
//Verify cookie sent //Verify cookie sent
Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.ExternalLogin")); Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.ExternalLogin"));
_logger.WriteInformation("Successfully signed in with user '{email}'", "User3@aspnettest.onmicrosoft.com"); _logger.LogInformation("Successfully signed in with user '{email}'", "User3@aspnettest.onmicrosoft.com");
_logger.WriteInformation("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 = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123")).Result;
//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.WriteInformation("Middleware notifications were fired successfully"); _logger.LogInformation("Middleware notifications were fired successfully");
_logger.WriteInformation("Verifying the OpenIdConnect logout flow.."); _logger.LogInformation("Verifying the OpenIdConnect logout flow..");
response = _httpClient.GetAsync(string.Empty).Result; response = _httpClient.GetAsync(string.Empty).Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = response.Content.ReadAsStringAsync().Result;

View File

@ -13,24 +13,24 @@ namespace E2ETests
{ {
private void VerifyStaticContentServed() private void VerifyStaticContentServed()
{ {
_logger.WriteInformation("Validating if static contents are served.."); _logger.LogInformation("Validating if static contents are served..");
_logger.WriteInformation("Fetching favicon.ico.."); _logger.LogInformation("Fetching favicon.ico..");
var response = _httpClient.GetAsync("favicon.ico").Result; var response = _httpClient.GetAsync("favicon.ico").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
_logger.WriteInformation("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.WriteInformation("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 = _httpClient.GetAsync("favicon.ico").Result;
Assert.Equal(HttpStatusCode.NotModified, response.StatusCode); Assert.Equal(HttpStatusCode.NotModified, response.StatusCode);
_httpClient.DefaultRequestHeaders.IfNoneMatch.Clear(); _httpClient.DefaultRequestHeaders.IfNoneMatch.Clear();
_logger.WriteInformation("Successfully received a NotModified status"); _logger.LogInformation("Successfully received a NotModified status");
_logger.WriteInformation("Fetching /Content/bootstrap.css.."); _logger.LogInformation("Fetching /Content/bootstrap.css..");
response = _httpClient.GetAsync("Content/bootstrap.css").Result; response = _httpClient.GetAsync("Content/bootstrap.css").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
_logger.WriteInformation("Verified static contents are served successfully"); _logger.LogInformation("Verified static contents are served successfully");
} }
private void VerifyHomePage(HttpResponseMessage response, string responseContent, bool useNtlmAuthentication = false) private void VerifyHomePage(HttpResponseMessage response, string responseContent, bool useNtlmAuthentication = false)
@ -53,13 +53,13 @@ namespace E2ETests
Assert.Contains("www.github.com/aspnet/MusicStore", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("www.github.com/aspnet/MusicStore", responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains("/Images/home-showcase.png", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("/Images/home-showcase.png", responseContent, StringComparison.OrdinalIgnoreCase);
_logger.WriteInformation("Application initialization successful."); _logger.LogInformation("Application initialization successful.");
_logger.WriteInformation("Application runtime information"); _logger.LogInformation("Application runtime information");
var runtimeResponse = _httpClient.GetAsync("runtimeinfo").Result; var runtimeResponse = _httpClient.GetAsync("runtimeinfo").Result;
ThrowIfResponseStatusNotOk(runtimeResponse); ThrowIfResponseStatusNotOk(runtimeResponse);
var runtimeInfo = runtimeResponse.Content.ReadAsStringAsync().Result; var runtimeInfo = runtimeResponse.Content.ReadAsStringAsync().Result;
_logger.WriteInformation(runtimeInfo); _logger.LogInformation(runtimeInfo);
} }
private string PrefixBaseAddress(string url) private string PrefixBaseAddress(string url)
@ -87,7 +87,7 @@ namespace E2ETests
private void AccessStoreWithoutPermissions(string email = null) private void AccessStoreWithoutPermissions(string email = null)
{ {
_logger.WriteInformation("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 = _httpClient.GetAsync("Admin/StoreManager/").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
@ -95,29 +95,29 @@ namespace E2ETests
Assert.Contains("<title>Log in MVC Music Store</title>", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("<title>Log in 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);
Assert.Equal<string>(_applicationBaseUrl + PrefixBaseAddress("Account/Login?ReturnUrl=%2F{0}%2FAdmin%2FStoreManager%2F"), response.RequestMessage.RequestUri.AbsoluteUri); Assert.Equal<string>(_applicationBaseUrl + PrefixBaseAddress("Account/Login?ReturnUrl=%2F{0}%2FAdmin%2FStoreManager%2F"), response.RequestMessage.RequestUri.AbsoluteUri);
_logger.WriteInformation("Redirected to login page as expected."); _logger.LogInformation("Redirected to login page as expected.");
} }
private void AccessStoreWithPermissions() private void AccessStoreWithPermissions()
{ {
_logger.WriteInformation("Trying to access the store inventory.."); _logger.LogInformation("Trying to access the store inventory..");
var response = _httpClient.GetAsync("Admin/StoreManager/").Result; var response = _httpClient.GetAsync("Admin/StoreManager/").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
Assert.Equal<string>(_applicationBaseUrl + "Admin/StoreManager/", response.RequestMessage.RequestUri.AbsoluteUri); Assert.Equal<string>(_applicationBaseUrl + "Admin/StoreManager/", response.RequestMessage.RequestUri.AbsoluteUri);
_logger.WriteInformation("Successfully acccessed the store inventory"); _logger.LogInformation("Successfully acccessed the store inventory");
} }
private void RegisterUserWithNonMatchingPasswords() private void RegisterUserWithNonMatchingPasswords()
{ {
_logger.WriteInformation("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 = _httpClient.GetAsync("Account/Register").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
ValidateLayoutPage(responseContent); ValidateLayoutPage(responseContent);
var generatedEmail = Guid.NewGuid().ToString().Replace("-", string.Empty) + "@test.com"; var generatedEmail = Guid.NewGuid().ToString().Replace("-", string.Empty) + "@test.com";
_logger.WriteInformation("Creating a new user with name '{email}'", generatedEmail); _logger.LogInformation("Creating a new user with name '{email}'", generatedEmail);
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
new KeyValuePair<string, string>("Email", generatedEmail), new KeyValuePair<string, string>("Email", generatedEmail),
@ -131,7 +131,7 @@ namespace E2ETests
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = response.Content.ReadAsStringAsync().Result;
Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
Assert.Contains("<div class=\"validation-summary-errors text-danger\" data-valmsg-summary=\"true\"><ul><li>The password and confirmation password do not match.</li>", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("<div class=\"validation-summary-errors text-danger\" data-valmsg-summary=\"true\"><ul><li>The password and confirmation password do not match.</li>", responseContent, StringComparison.OrdinalIgnoreCase);
_logger.WriteInformation("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);
} }
private string RegisterValidUser() private string RegisterValidUser()
@ -142,7 +142,7 @@ namespace E2ETests
ValidateLayoutPage(responseContent); ValidateLayoutPage(responseContent);
var generatedEmail = Guid.NewGuid().ToString().Replace("-", string.Empty) + "@test.com"; var generatedEmail = Guid.NewGuid().ToString().Replace("-", string.Empty) + "@test.com";
_logger.WriteInformation("Creating a new user with name '{email}'", generatedEmail); _logger.LogInformation("Creating a new user with name '{email}'", generatedEmail);
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
new KeyValuePair<string, string>("Email", generatedEmail), new KeyValuePair<string, string>("Email", generatedEmail),
@ -171,11 +171,11 @@ namespace E2ETests
private void RegisterExistingUser(string email) private void RegisterExistingUser(string email)
{ {
_logger.WriteInformation("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 = _httpClient.GetAsync("Account/Register").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
_logger.WriteInformation("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>>
{ {
new KeyValuePair<string, string>("Email", email), new KeyValuePair<string, string>("Email", email),
@ -188,12 +188,12 @@ namespace E2ETests
response = _httpClient.PostAsync("Account/Register", content).Result; response = _httpClient.PostAsync("Account/Register", content).Result;
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = response.Content.ReadAsStringAsync().Result;
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.WriteInformation("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);
} }
private void SignOutUser(string email) private void SignOutUser(string email)
{ {
_logger.WriteInformation("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 = _httpClient.GetAsync(string.Empty).Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
@ -216,7 +216,7 @@ namespace E2ETests
Assert.Contains("/Images/home-showcase.png", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("/Images/home-showcase.png", responseContent, StringComparison.OrdinalIgnoreCase);
//Verify cookie cleared on logout //Verify cookie cleared on logout
Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
_logger.WriteInformation("Successfully signed out of '{email}''s session", email); _logger.LogInformation("Successfully signed out of '{email}''s session", email);
} }
else else
{ {
@ -231,7 +231,7 @@ namespace E2ETests
var response = _httpClient.GetAsync("Account/Login").Result; var response = _httpClient.GetAsync("Account/Login").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
_logger.WriteInformation("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>>
{ {
new KeyValuePair<string, string>("Email", email), new KeyValuePair<string, string>("Email", email),
@ -245,7 +245,7 @@ namespace E2ETests
Assert.Contains("<div class=\"validation-summary-errors text-danger\"><ul><li>Invalid login attempt.</li>", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("<div class=\"validation-summary-errors text-danger\"><ul><li>Invalid login attempt.</li>", responseContent, StringComparison.OrdinalIgnoreCase);
//Verify cookie not sent //Verify cookie not sent
Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
_logger.WriteInformation("Identity successfully prevented an invalid user login."); _logger.LogInformation("Identity successfully prevented an invalid user login.");
} }
private void SignInWithUser(string email, string password) private void SignInWithUser(string email, string password)
@ -253,7 +253,7 @@ namespace E2ETests
var response = _httpClient.GetAsync("Account/Login").Result; var response = _httpClient.GetAsync("Account/Login").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
_logger.WriteInformation("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>>
{ {
new KeyValuePair<string, string>("Email", email), new KeyValuePair<string, string>("Email", email),
@ -268,7 +268,7 @@ namespace E2ETests
Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("Log off", responseContent, StringComparison.OrdinalIgnoreCase);
//Verify cookie sent //Verify cookie sent
Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
_logger.WriteInformation("Successfully signed in with user '{email}'", email); _logger.LogInformation("Successfully signed in with user '{email}'", email);
} }
private void ChangePassword(string email) private void ChangePassword(string email)
@ -289,7 +289,7 @@ namespace E2ETests
responseContent = response.Content.ReadAsStringAsync().Result; responseContent = response.Content.ReadAsStringAsync().Result;
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(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
_logger.WriteInformation("Successfully changed the password for user '{email}'", email); _logger.LogInformation("Successfully changed the password for user '{email}'", email);
} }
private string CreateAlbum() private string CreateAlbum()
@ -301,7 +301,7 @@ namespace E2ETests
var hubConnection = new HubConnection(_applicationBaseUrl + "SignalR"); var hubConnection = new HubConnection(_applicationBaseUrl + "SignalR");
hubConnection.Received += (data) => hubConnection.Received += (data) =>
{ {
_logger.WriteVerbose("Data received by SignalR client: {receivedData}", data); _logger.LogVerbose("Data received by SignalR client: {receivedData}", data);
dataFromHub = data; dataFromHub = data;
OnReceivedEvent.Set(); OnReceivedEvent.Set();
}; };
@ -309,7 +309,7 @@ namespace E2ETests
IHubProxy proxy = hubConnection.CreateHubProxy("Announcement"); IHubProxy proxy = hubConnection.CreateHubProxy("Announcement");
hubConnection.Start().Wait(); hubConnection.Start().Wait();
#endif #endif
_logger.WriteInformation("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 = _httpClient.GetAsync("Admin/StoreManager/create").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
@ -329,28 +329,28 @@ namespace E2ETests
Assert.Equal<string>(_applicationBaseUrl + "Admin/StoreManager", response.RequestMessage.RequestUri.AbsoluteUri); Assert.Equal<string>(_applicationBaseUrl + "Admin/StoreManager", response.RequestMessage.RequestUri.AbsoluteUri);
Assert.Contains(albumName, responseContent); Assert.Contains(albumName, responseContent);
#if ASPNET50 #if ASPNET50
_logger.WriteInformation("Waiting for the SignalR client to receive album created announcement"); _logger.LogInformation("Waiting for the SignalR client to receive album created announcement");
OnReceivedEvent.WaitOne(TimeSpan.FromSeconds(10)); OnReceivedEvent.WaitOne(TimeSpan.FromSeconds(10));
dataFromHub = dataFromHub ?? "No relevant data received from Hub"; dataFromHub = dataFromHub ?? "No relevant data received from Hub";
Assert.Contains(albumName, dataFromHub); Assert.Contains(albumName, dataFromHub);
#endif #endif
_logger.WriteInformation("Successfully created an album with name '{album}' in the store", albumName); _logger.LogInformation("Successfully created an album with name '{album}' in the store", albumName);
return albumName; return albumName;
} }
private string FetchAlbumIdFromName(string albumName) private string FetchAlbumIdFromName(string albumName)
{ {
_logger.WriteInformation("Fetching the album id of '{album}'", albumName); _logger.LogInformation("Fetching the album id of '{album}'", albumName);
var response = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", albumName)).Result; var response = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", albumName)).Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var albumId = response.Content.ReadAsStringAsync().Result; var albumId = response.Content.ReadAsStringAsync().Result;
_logger.WriteInformation("Album id for album '{album}' is '{id}'", albumName, albumId); _logger.LogInformation("Album id for album '{album}' is '{id}'", albumName, albumId);
return albumId; return albumId;
} }
private void VerifyAlbumDetails(string albumId, string albumName) private void VerifyAlbumDetails(string albumId, string albumName)
{ {
_logger.WriteInformation("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 = _httpClient.GetAsync(string.Format("Admin/StoreManager/Details?id={0}", albumId)).Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
@ -362,7 +362,7 @@ namespace E2ETests
private void VerifyStatusCodePages() private void VerifyStatusCodePages()
{ {
_logger.WriteInformation("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 = _httpClient.GetAsync("Admin/StoreManager/Details?id=-1").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
@ -373,7 +373,7 @@ namespace E2ETests
// This gets the view that non-admin users get to see. // This gets the view that non-admin users get to see.
private void GetAlbumDetailsFromStore(string albumId, string albumName) private void GetAlbumDetailsFromStore(string albumId, string albumName)
{ {
_logger.WriteInformation("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 = _httpClient.GetAsync(string.Format("Store/Details/{0}", albumId)).Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
@ -382,18 +382,18 @@ namespace E2ETests
private void AddAlbumToCart(string albumId, string albumName) private void AddAlbumToCart(string albumId, string albumName)
{ {
_logger.WriteInformation("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 = _httpClient.GetAsync(string.Format("ShoppingCart/AddToCart?id={0}", albumId)).Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
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.WriteInformation("Verified that album is added to cart"); _logger.LogInformation("Verified that album is added to cart");
} }
private void CheckOutCartItems() private void CheckOutCartItems()
{ {
_logger.WriteInformation("Checking out the cart contents..."); _logger.LogInformation("Checking out the cart contents...");
var response = _httpClient.GetAsync("Checkout/AddressAndPayment").Result; var response = _httpClient.GetAsync("Checkout/AddressAndPayment").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
@ -422,7 +422,7 @@ namespace E2ETests
private void DeleteAlbum(string albumId, string albumName) private void DeleteAlbum(string albumId, string albumName)
{ {
_logger.WriteInformation("Deleting album '{album}' from the store..", albumName); _logger.LogInformation("Deleting album '{album}' from the store..", albumName);
var formParameters = new List<KeyValuePair<string, string>> var formParameters = new List<KeyValuePair<string, string>>
{ {
@ -433,17 +433,17 @@ namespace E2ETests
var response = _httpClient.PostAsync("Admin/StoreManager/RemoveAlbum", content).Result; var response = _httpClient.PostAsync("Admin/StoreManager/RemoveAlbum", content).Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
_logger.WriteInformation("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 = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", albumName)).Result;
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
_logger.WriteInformation("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 void ThrowIfResponseStatusNotOk(HttpResponseMessage response)
{ {
if (response.StatusCode != HttpStatusCode.OK) if (response.StatusCode != HttpStatusCode.OK)
{ {
_logger.WriteError(response.Content.ReadAsStringAsync().Result); _logger.LogError(response.Content.ReadAsStringAsync().Result);
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

@ -22,7 +22,7 @@ namespace E2ETests
var response = _httpClient.GetAsync("Account/Login").Result; var response = _httpClient.GetAsync("Account/Login").Result;
ThrowIfResponseStatusNotOk(response); ThrowIfResponseStatusNotOk(response);
var responseContent = response.Content.ReadAsStringAsync().Result; var responseContent = response.Content.ReadAsStringAsync().Result;
_logger.WriteInformation("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>>
{ {
new KeyValuePair<string, string>("provider", "Twitter"), new KeyValuePair<string, string>("provider", "Twitter"),
@ -85,14 +85,14 @@ namespace E2ETests
//Verify cookie sent //Verify cookie sent
Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application")); Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.Application"));
Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.ExternalLogin")); Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.ExternalLogin"));
_logger.WriteInformation("Successfully signed in with user '{email}'", "twitter@test.com"); _logger.LogInformation("Successfully signed in with user '{email}'", "twitter@test.com");
_logger.WriteInformation("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 = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123")).Result;
//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.WriteInformation("Middleware notifications were fired successfully"); _logger.LogInformation("Middleware notifications were fired successfully");
} }
} }
} }

View File

@ -19,7 +19,7 @@ namespace E2ETests
{ {
using (_logger.BeginScope("NtlmAuthenticationTest")) using (_logger.BeginScope("NtlmAuthenticationTest"))
{ {
_logger.WriteInformation("Variation Details : HostType = {hostType}, RuntimeFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}", _logger.LogInformation("Variation Details : HostType = {hostType}, RuntimeFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}",
serverType, runtimeFlavor, architecture, applicationBaseUrl); serverType, runtimeFlavor, architecture, applicationBaseUrl);
_startParameters = new StartParameters _startParameters = new StartParameters
@ -35,7 +35,7 @@ namespace E2ETests
var testStartTime = DateTime.Now; var testStartTime = DateTime.Now;
var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);
_logger.WriteInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName)); _logger.LogInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));
//Override the connection strings using environment based configuration //Override the connection strings using environment based configuration
Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName)); Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));
@ -63,7 +63,7 @@ namespace E2ETests
initializationCompleteTime = DateTime.Now; initializationCompleteTime = DateTime.Now;
}, logger: _logger); }, logger: _logger);
_logger.WriteInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds",
(initializationCompleteTime - testStartTime).TotalSeconds); (initializationCompleteTime - testStartTime).TotalSeconds);
VerifyHomePage(response, responseContent, true); VerifyHomePage(response, responseContent, true);
@ -77,15 +77,15 @@ namespace E2ETests
AccessStoreWithPermissions(); AccessStoreWithPermissions();
var testCompletionTime = DateTime.Now; var testCompletionTime = DateTime.Now;
_logger.WriteInformation("[Time]: All tests completed in '{t}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds); _logger.LogInformation("[Time]: All tests completed in '{t}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds);
_logger.WriteInformation("[Time]: Total time taken for this test variation '{t}' seconds", (testCompletionTime - testStartTime).TotalSeconds); _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", (testCompletionTime - testStartTime).TotalSeconds);
testSuccessful = true; testSuccessful = true;
} }
finally finally
{ {
if (!testSuccessful) if (!testSuccessful)
{ {
_logger.WriteError("Some tests failed. Proceeding with cleanup."); _logger.LogError("Some tests failed. Proceeding with cleanup.");
} }
DeploymentUtility.CleanUpApplication(_startParameters, hostProcess, musicStoreDbName, _logger); DeploymentUtility.CleanUpApplication(_startParameters, hostProcess, musicStoreDbName, _logger);

View File

@ -30,7 +30,7 @@ namespace E2ETests
{ {
using (_logger.BeginScope("OpenIdConnectTestSuite")) using (_logger.BeginScope("OpenIdConnectTestSuite"))
{ {
_logger.WriteInformation("Variation Details : HostType = {hostType}, DonetFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}", _logger.LogInformation("Variation Details : HostType = {hostType}, DonetFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}",
serverType, donetFlavor, architecture, applicationBaseUrl); serverType, donetFlavor, architecture, applicationBaseUrl);
_startParameters = new StartParameters _startParameters = new StartParameters
@ -44,7 +44,7 @@ namespace E2ETests
var testStartTime = DateTime.Now; var testStartTime = DateTime.Now;
var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);
_logger.WriteInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName)); _logger.LogInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));
//Override the connection strings using environment based configuration //Override the connection strings using environment based configuration
Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName)); Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));
@ -78,7 +78,7 @@ namespace E2ETests
initializationCompleteTime = DateTime.Now; initializationCompleteTime = DateTime.Now;
}, logger: _logger); }, logger: _logger);
_logger.WriteInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds",
(initializationCompleteTime - testStartTime).TotalSeconds); (initializationCompleteTime - testStartTime).TotalSeconds);
VerifyHomePage(response, responseContent); VerifyHomePage(response, responseContent);
@ -87,15 +87,15 @@ namespace E2ETests
LoginWithOpenIdConnect(); LoginWithOpenIdConnect();
var testCompletionTime = DateTime.Now; var testCompletionTime = DateTime.Now;
_logger.WriteInformation("[Time]: All tests completed in '{t}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds); _logger.LogInformation("[Time]: All tests completed in '{t}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds);
_logger.WriteInformation("[Time]: Total time taken for this test variation '{t}' seconds", (testCompletionTime - testStartTime).TotalSeconds); _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", (testCompletionTime - testStartTime).TotalSeconds);
testSuccessful = true; testSuccessful = true;
} }
finally finally
{ {
if (!testSuccessful) if (!testSuccessful)
{ {
_logger.WriteError("Some tests failed. Proceeding with cleanup."); _logger.LogError("Some tests failed. Proceeding with cleanup.");
} }
DeploymentUtility.CleanUpApplication(_startParameters, hostProcess, musicStoreDbName, _logger); DeploymentUtility.CleanUpApplication(_startParameters, hostProcess, musicStoreDbName, _logger);

View File

@ -40,7 +40,7 @@ namespace E2ETests
{ {
using (_logger.BeginScope("Publish_And_Run_Tests")) using (_logger.BeginScope("Publish_And_Run_Tests"))
{ {
_logger.WriteInformation("Variation Details : HostType = {hostType}, RuntimeFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}", _logger.LogInformation("Variation Details : HostType = {hostType}, RuntimeFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}",
serverType, runtimeFlavor, architecture, applicationBaseUrl); serverType, runtimeFlavor, architecture, applicationBaseUrl);
_startParameters = new StartParameters _startParameters = new StartParameters
@ -54,7 +54,7 @@ namespace E2ETests
var testStartTime = DateTime.Now; var testStartTime = DateTime.Now;
var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);
_logger.WriteInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName)); _logger.LogInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));
//Override the connection strings using environment based configuration //Override the connection strings using environment based configuration
Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName)); Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));
@ -83,7 +83,7 @@ namespace E2ETests
initializationCompleteTime = DateTime.Now; initializationCompleteTime = DateTime.Now;
}, logger: _logger); }, logger: _logger);
_logger.WriteInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds",
(initializationCompleteTime - testStartTime).TotalSeconds); (initializationCompleteTime - testStartTime).TotalSeconds);
VerifyHomePage(response, responseContent, true); VerifyHomePage(response, responseContent, true);
@ -100,15 +100,15 @@ namespace E2ETests
} }
var testCompletionTime = DateTime.Now; var testCompletionTime = DateTime.Now;
_logger.WriteInformation("[Time]: All tests completed in '{t}' seconds.", (testCompletionTime - initializationCompleteTime).TotalSeconds); _logger.LogInformation("[Time]: All tests completed in '{t}' seconds.", (testCompletionTime - initializationCompleteTime).TotalSeconds);
_logger.WriteInformation("[Time]: Total time taken for this test variation '{t}' seconds.", (testCompletionTime - testStartTime).TotalSeconds); _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds.", (testCompletionTime - testStartTime).TotalSeconds);
testSuccessful = true; testSuccessful = true;
} }
finally finally
{ {
if (!testSuccessful) if (!testSuccessful)
{ {
_logger.WriteError("Some tests failed. Proceeding with cleanup."); _logger.LogError("Some tests failed. Proceeding with cleanup.");
} }
DeploymentUtility.CleanUpApplication(_startParameters, hostProcess, musicStoreDbName, _logger); DeploymentUtility.CleanUpApplication(_startParameters, hostProcess, musicStoreDbName, _logger);

View File

@ -22,7 +22,7 @@ namespace E2ETests
{ {
var loggerFactory = new LoggerFactory(); var loggerFactory = new LoggerFactory();
loggerFactory.AddConsole(); loggerFactory.AddConsole();
_logger = loggerFactory.Create<SmokeTests>(); _logger = loggerFactory.CreateLogger<SmokeTests>();
} }
[ConditionalTheory] [ConditionalTheory]
@ -94,7 +94,7 @@ namespace E2ETests
{ {
using (_logger.BeginScope("SmokeTestSuite")) using (_logger.BeginScope("SmokeTestSuite"))
{ {
_logger.WriteInformation("Variation Details : HostType = {hostType}, DonetFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}", _logger.LogInformation("Variation Details : HostType = {hostType}, DonetFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}",
serverType, donetFlavor, architecture, applicationBaseUrl); serverType, donetFlavor, architecture, applicationBaseUrl);
_startParameters = new StartParameters _startParameters = new StartParameters
@ -108,7 +108,7 @@ namespace E2ETests
var testStartTime = DateTime.Now; var testStartTime = DateTime.Now;
var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);
_logger.WriteInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName)); _logger.LogInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));
//Override the connection strings using environment based configuration //Override the connection strings using environment based configuration
Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName)); Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));
@ -142,7 +142,7 @@ namespace E2ETests
initializationCompleteTime = DateTime.Now; initializationCompleteTime = DateTime.Now;
}, logger: _logger); }, logger: _logger);
_logger.WriteInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds",
(initializationCompleteTime - testStartTime).TotalSeconds); (initializationCompleteTime - testStartTime).TotalSeconds);
VerifyHomePage(response, responseContent); VerifyHomePage(response, responseContent);
@ -229,15 +229,15 @@ namespace E2ETests
LoginWithMicrosoftAccount(); LoginWithMicrosoftAccount();
var testCompletionTime = DateTime.Now; var testCompletionTime = DateTime.Now;
_logger.WriteInformation("[Time]: All tests completed in '{t}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds); _logger.LogInformation("[Time]: All tests completed in '{t}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds);
_logger.WriteInformation("[Time]: Total time taken for this test variation '{t}' seconds", (testCompletionTime - testStartTime).TotalSeconds); _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", (testCompletionTime - testStartTime).TotalSeconds);
testSuccessful = true; testSuccessful = true;
} }
finally finally
{ {
if (!testSuccessful) if (!testSuccessful)
{ {
_logger.WriteError("Some tests failed. Proceeding with cleanup."); _logger.LogError("Some tests failed. Proceeding with cleanup.");
} }
DeploymentUtility.CleanUpApplication(_startParameters, hostProcess, musicStoreDbName, _logger); DeploymentUtility.CleanUpApplication(_startParameters, hostProcess, musicStoreDbName, _logger);