using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading;
using Microsoft.AspNet.SignalR.Client;
using Xunit;
namespace E2ETests
{
public partial class SmokeTests
{
private void VerifyStaticContentServed()
{
Console.WriteLine("Validating if static contents are served..");
Console.WriteLine("Fetching favicon.ico..");
var response = _httpClient.GetAsync("favicon.ico").Result;
ThrowIfResponseStatusNotOk(response);
Console.WriteLine("Etag received: {0}", response.Headers.ETag.Tag);
//Check if you receive a NotModified on sending an etag
Console.WriteLine("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();
Console.WriteLine("Successfully received a NotModified status");
Console.WriteLine("Fetching /Content/bootstrap.css..");
response = _httpClient.GetAsync("Content/bootstrap.css").Result;
ThrowIfResponseStatusNotOk(response);
Console.WriteLine("Verified static contents are served successfully");
}
private void VerifyHomePage(HttpResponseMessage response, string responseContent, bool useNtlmAuthentication = false)
{
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);
Console.WriteLine("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("