Files
cefsharp/CefSharp.Test/Framework/AsyncExtensionFacts.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

78 lines
2.5 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 Moq;
using Xunit;
using Xunit.Abstractions;
namespace CefSharp.Test.Framework
{
/// <summary>
/// Async Extensions - This test doesn't need to be part of the
/// </summary>
public class AsyncExtensionFacts
{
private readonly ITestOutputHelper output;
public AsyncExtensionFacts(ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public async Task DeleteCookiesReturnsTaskWhenReturnsFalse()
{
var mockCookieManager = new Mock<ICookieManager>();
//When the DeleteCookies method returns false we'll expect to get a -1 as result
mockCookieManager.Setup(x => x.DeleteCookies("test.com", "testcookie", null)).Returns(false);
var result = await mockCookieManager.Object.DeleteCookiesAsync("test.com", "testcookie");
Assert.Equal(TaskDeleteCookiesCallback.InvalidNoOfCookiesDeleted, result);
}
[Fact]
public async Task TaskDeleteCookiesCallbackOnComplete()
{
const int numberOfCookiesDeleted = 10;
var callback = new TaskDeleteCookiesCallback();
//Execute OnComplete on seperate Thread as in practice will be called on the CEF IO Thread.
Task.Delay(100).ContinueWith(x =>
{
var c = (IDeleteCookiesCallback)callback;
c.OnComplete(numberOfCookiesDeleted);
c.Dispose();
}, TaskScheduler.Default);
var result = await callback.Task;
Assert.Equal(numberOfCookiesDeleted, result);
}
[Fact]
public async Task TaskDeleteCookiesCallbackDispose()
{
var callback = new TaskDeleteCookiesCallback();
//Execute Dispose on seperate Thread as in practice will be called on the CEF IO Thread.
Task.Delay(100).ContinueWith(x =>
{
var c = (IDeleteCookiesCallback)callback;
//Dispose of the callback, no cookies were deleted
//This is a realworld example of how CEF interacts with the callback
c.Dispose();
}, TaskScheduler.Default);
var result = await callback.Task;
Assert.Equal(TaskDeleteCookiesCallback.InvalidNoOfCookiesDeleted, result);
}
}
}