2019-05-12 07:51:24 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-05-14 12:13:55 +02:00
|
|
|
|
using BTCPayServer.Tests.Logging;
|
2019-05-12 07:51:24 +02:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-05-13 10:59:15 +02:00
|
|
|
|
using OpenQA.Selenium;
|
2019-05-12 07:51:24 +02:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Tests
|
|
|
|
|
{
|
|
|
|
|
public static class Extensions
|
|
|
|
|
{
|
2019-05-13 10:59:15 +02:00
|
|
|
|
public static void AssertNoError(this IWebDriver driver)
|
|
|
|
|
{
|
2019-05-14 12:09:26 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2019-05-14 12:27:26 +02:00
|
|
|
|
Assert.NotEmpty(driver.FindElements(By.ClassName("navbar-brand")));
|
2019-05-14 12:09:26 +02:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
2019-05-14 12:13:55 +02:00
|
|
|
|
builder.AppendLine();
|
2019-05-14 12:19:23 +02:00
|
|
|
|
foreach (var logKind in new []{ LogType.Browser, LogType.Client, LogType.Driver, LogType.Server })
|
2019-05-14 12:09:26 +02:00
|
|
|
|
{
|
2019-05-14 12:13:55 +02:00
|
|
|
|
try
|
2019-05-14 12:09:26 +02:00
|
|
|
|
{
|
2019-05-14 12:19:23 +02:00
|
|
|
|
var logs = driver.Manage().Logs.GetLog(logKind);
|
2019-05-14 12:13:55 +02:00
|
|
|
|
builder.AppendLine($"Selenium [{logKind}]:");
|
2019-05-14 12:19:23 +02:00
|
|
|
|
foreach (var entry in logs)
|
2019-05-14 12:13:55 +02:00
|
|
|
|
{
|
|
|
|
|
builder.AppendLine($"[{entry.Level}]: {entry.Message}");
|
|
|
|
|
}
|
2019-05-14 12:09:26 +02:00
|
|
|
|
}
|
2019-05-14 12:13:55 +02:00
|
|
|
|
catch { }
|
2019-05-14 12:19:23 +02:00
|
|
|
|
builder.AppendLine($"---------");
|
2019-05-14 12:09:26 +02:00
|
|
|
|
}
|
2019-05-14 12:13:55 +02:00
|
|
|
|
Logs.Tester.LogInformation(builder.ToString());
|
2019-05-14 12:19:23 +02:00
|
|
|
|
builder = new StringBuilder();
|
|
|
|
|
builder.AppendLine($"Selenium [Sources]:");
|
|
|
|
|
builder.AppendLine(driver.PageSource);
|
|
|
|
|
builder.AppendLine($"---------");
|
|
|
|
|
Logs.Tester.LogInformation(builder.ToString());
|
2019-05-14 12:09:26 +02:00
|
|
|
|
throw;
|
|
|
|
|
}
|
2019-05-13 10:59:15 +02:00
|
|
|
|
}
|
2019-05-12 07:51:24 +02:00
|
|
|
|
public static T AssertViewModel<T>(this IActionResult result)
|
|
|
|
|
{
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
var vr = Assert.IsType<ViewResult>(result);
|
|
|
|
|
return Assert.IsType<T>(vr.Model);
|
|
|
|
|
}
|
|
|
|
|
public static async Task<T> AssertViewModelAsync<T>(this Task<IActionResult> task)
|
|
|
|
|
{
|
|
|
|
|
var result = await task;
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
var vr = Assert.IsType<ViewResult>(result);
|
|
|
|
|
return Assert.IsType<T>(vr.Model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|