using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Server.Testing;
using Microsoft.Framework.Logging;
using Xunit;
namespace E2ETests
{
public partial class Validator
{
private HttpClient _httpClient;
private HttpClientHandler _httpClientHandler;
private readonly ILogger _logger;
private readonly DeploymentResult _deploymentResult;
public Validator(
HttpClient httpClient,
HttpClientHandler httpClientHandler,
ILogger logger,
DeploymentResult deploymentResult)
{
_httpClient = httpClient;
_httpClientHandler = httpClientHandler;
_logger = logger;
_deploymentResult = deploymentResult;
}
public async Task VerifyHomePage(
HttpResponseMessage response,
bool useNtlmAuthentication = false)
{
var responseContent = await response.Content.ReadAsStringAsync();
if (response.StatusCode != HttpStatusCode.OK)
{
Console.WriteLine("Home page content : {0}", responseContent);
}
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
ValidateLayoutPage(responseContent);
Assert.Contains(PrefixBaseAddress("Home Page – ASP.NET 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 = await _httpClient.GetAsync("runtimeinfo");
// https://github.com/aspnet/Diagnostics/issues/108
if (_deploymentResult.DeploymentParameters.RuntimeFlavor != RuntimeFlavor.CoreClr)
{
//Helpers.ThrowIfResponseStatusNotOk(runtimeResponse, _logger);
}
//var runtimeInfo = await runtimeResponse.Content.ReadAsStringAsync();
//_logger.LogInformation(runtimeInfo);
}
public async Task VerifyNtlmHomePage(HttpResponseMessage response)
{
await VerifyHomePage(response, useNtlmAuthentication: true);
var homePageContent = await response.Content.ReadAsStringAsync();
//Check if the user name appears in the page
Assert.Contains(
string.Format("{0}\\{1}", Environment.GetEnvironmentVariable("USERDOMAIN"), Environment.GetEnvironmentVariable("USERNAME")),
homePageContent, StringComparison.OrdinalIgnoreCase);
}
public void ValidateLayoutPage(string responseContent)
{
Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase);
Assert.Contains(PrefixBaseAddress("