Files
cefsharp/CefSharp.Test/OffScreen/OffScreenBrowserBasicFacts.cs
T
amaitland 9407ba1828 Due to limitations of VC++ we must run our tests in the default appdomain, it's possible to use xunit for testing.
Readd CefSharp.Test.csproj to solution
Add some very basic unit tests using xunit, DisableTestParallelization, Set xunit.appDomain to denied in app.config to disable using appdomains (https://xunit.github.io/docs/configuring-with-xml.html)
Add xunit vs test running packages, using 2.2.0 version as 2.3.0 was throwing an exception similar to https://github.com/xunit/xunit/issues/1514
TODO: Take a look at https://github.com/NuGet/NuGetGallery/tree/master/tests/NuGetGallery.Facts for some ideas on structuring xunit tests (look at implementing Theory)

NOTE: I am not providing this as a definitive set of tests, it's simply here to get someone else started in creating tests as it appears people have trouble dealing with AppDomain problem
Only includes Tests for the OffScreen version at this stage.
2017-10-25 10:44:38 +10:00

60 lines
2.0 KiB
C#

// Copyright © 2010-2017 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System.Threading.Tasks;
using CefSharp.OffScreen;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions;
namespace CefSharp.Test.OffScreen
{
//NOTE: All Test classes must be part of this collection as it manages the Cef Initialize/Shutdown lifecycle
[Collection(CefSharpFixtureCollection.Key)]
public class OffScreenBrowserBasicFacts
{
private readonly ITestOutputHelper output;
private readonly CefSharpFixture fixture;
public OffScreenBrowserBasicFacts(ITestOutputHelper output, CefSharpFixture fixture)
{
this.fixture = fixture;
this.output = output;
}
[Fact]
public async Task CanLoadGoogle()
{
using(var browser = new ChromiumWebBrowser("www.google.com"))
{
await browser.LoadPageAsync();
var mainFrame = browser.GetMainFrame();
Assert.True(mainFrame.IsValid);
Assert.True(mainFrame.Url.Contains("www.google"));
output.WriteLine("Url {0}", mainFrame.Url);
}
}
[Fact]
public async Task CanLoadGoogleAndEvaluateScript()
{
using (var browser = new ChromiumWebBrowser("www.google.com"))
{
await browser.LoadPageAsync();
var mainFrame = browser.GetMainFrame();
Assert.True(mainFrame.IsValid);
Assert.True(mainFrame.Url.Contains("www.google"));
var javascriptResponse = await browser.EvaluateScriptAsync("2 + 2");
Assert.True(javascriptResponse.Success);
Assert.Equal(4, (int)javascriptResponse.Result);
output.WriteLine("Result of 2 + 2: {0}", javascriptResponse.Result);
}
}
}
}