Files
cefsharp/CefSharp/Callback/TaskDeleteCookiesCallback.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

57 lines
1.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;
using System.Threading.Tasks;
using CefSharp.Internals;
namespace CefSharp
{
/// <summary>
/// Provides a callback implementation of <see cref="IDeleteCookiesCallback"/>.
/// </summary>
public class TaskDeleteCookiesCallback : IDeleteCookiesCallback
{
public const int InvalidNoOfCookiesDeleted = -1;
private readonly TaskCompletionSource<int> taskCompletionSource;
private volatile bool isDisposed;
public TaskDeleteCookiesCallback()
{
taskCompletionSource = new TaskCompletionSource<int>();
}
void IDeleteCookiesCallback.OnComplete(int numDeleted)
{
taskCompletionSource.TrySetResultAsync(numDeleted);
}
public Task<int> Task
{
get { return taskCompletionSource.Task; }
}
bool IDeleteCookiesCallback.IsDisposed
{
get { return isDisposed; }
}
void IDisposable.Dispose()
{
var task = taskCompletionSource.Task;
//If the Task hasn't completed and this is being disposed then
//set the TCS to InvalidNoOfCookiesDeleted
if (task.IsCompleted == false)
{
taskCompletionSource.TrySetResultAsync(InvalidNoOfCookiesDeleted);
}
isDisposed = true;
}
}
}