using System; using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Threading; using Microsoft.AspNet.SignalR.Client; using Microsoft.Framework.Logging; using Xunit; namespace E2ETests { public partial class SmokeTests { private void VerifyStaticContentServed() { _logger.WriteInformation("Validating if static contents are served.."); _logger.WriteInformation("Fetching favicon.ico.."); var response = _httpClient.GetAsync("favicon.ico").Result; ThrowIfResponseStatusNotOk(response); _logger.WriteInformation("Etag received: {0}", response.Headers.ETag.Tag); //Check if you receive a NotModified on sending an etag _logger.WriteInformation("Sending an IfNoneMatch header with e-tag"); _httpClient.DefaultRequestHeaders.IfNoneMatch.Add(response.Headers.ETag); response = _httpClient.GetAsync("favicon.ico").Result; Assert.Equal(HttpStatusCode.NotModified, response.StatusCode); _httpClient.DefaultRequestHeaders.IfNoneMatch.Clear(); _logger.WriteInformation("Successfully received a NotModified status"); _logger.WriteInformation("Fetching /Content/bootstrap.css.."); response = _httpClient.GetAsync("Content/bootstrap.css").Result; ThrowIfResponseStatusNotOk(response); _logger.WriteInformation("Verified static contents are served successfully"); } private void VerifyHomePage(HttpResponseMessage response, string responseContent, bool useNtlmAuthentication = false) { // This seems to not print anything if the successive Assert fails. //_logger.WriteVerbose("Home page content : {0}", responseContent); Console.WriteLine("Home page content : {0}", responseContent); Assert.Equal(HttpStatusCode.OK, response.StatusCode); ValidateLayoutPage(responseContent); Assert.Contains(PrefixBaseAddress("Home Page – MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase); if (!useNtlmAuthentication) { //We don't display these for Ntlm 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); _logger.WriteInformation("Application initialization successful."); } private string PrefixBaseAddress(string url) { url = (_startParameters.ServerType == ServerType.IISNativeModule || _startParameters.ServerType == ServerType.IIS) ? string.Format(url, _startParameters.IISApplication.VirtualDirectoryName) : string.Format(url, string.Empty); return url.Replace("//", "/").Replace("%2F%2F", "%2F").Replace("%2F/", "%2F"); } private void ValidateLayoutPage(string responseContent) { Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(PrefixBaseAddress("
  • Home
  • "), responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains(PrefixBaseAddress("Store "), responseContent, StringComparison.OrdinalIgnoreCase); Assert.Contains("