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.LogInformation("Validating if static contents are served..");
_logger.LogInformation("Fetching favicon.ico..");
var response = _httpClient.GetAsync("favicon.ico").Result;
ThrowIfResponseStatusNotOk(response);
_logger.LogInformation("Etag received: {etag}", response.Headers.ETag.Tag);
//Check if you receive a NotModified on sending an etag
_logger.LogInformation("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.LogInformation("Successfully received a NotModified status");
_logger.LogInformation("Fetching /Content/bootstrap.css..");
response = _httpClient.GetAsync("Content/bootstrap.css").Result;
ThrowIfResponseStatusNotOk(response);
_logger.LogInformation("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("www.github.com/aspnet/MusicStore", responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains("/Images/home-showcase.png", responseContent, StringComparison.OrdinalIgnoreCase);
_logger.LogInformation("Application initialization successful.");
_logger.LogInformation("Application runtime information");
var runtimeResponse = _httpClient.GetAsync("runtimeinfo").Result;
ThrowIfResponseStatusNotOk(runtimeResponse);
var runtimeInfo = runtimeResponse.Content.ReadAsStringAsync().Result;
_logger.LogInformation(runtimeInfo);
}
private string PrefixBaseAddress(string url)
{
#if DNX451
url = (_startParameters.ServerType == ServerType.IISNativeModule ||
_startParameters.ServerType == ServerType.IIS) ?
string.Format(url, _startParameters.IISApplication.VirtualDirectoryName) :
string.Format(url, string.Empty);
#else
url = string.Format(url, string.Empty);
#endif
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("