Skip to content

Commit

Permalink
Net Core - Add XUnit Test Project
Browse files Browse the repository at this point in the history
Issue #3197
  • Loading branch information
amaitland committed Jul 24, 2020
1 parent 22d494b commit 1af1065
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 1 deletion.
1 change: 1 addition & 0 deletions CefSharp.Example/CefExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static class CefExample
public const string BaseUrl = "https://" + ExampleDomain;
public const string DefaultUrl = BaseUrl + "/home.html";
public const string BindingTestUrl = BaseUrl + "/BindingTest.html";
public const string BindingTestNetCoreUrl = BaseUrl + "/BindingTestNetCore.html";
public const string BindingTestSingleUrl = BaseUrl + "/BindingTestSingle.html";
public const string BindingTestsAsyncTaskUrl = BaseUrl + "/BindingTestsAsyncTask.html";
public const string LegacyBindingTestUrl = BaseUrl + "/LegacyBindingTest.html";
Expand Down
3 changes: 3 additions & 0 deletions CefSharp.Example/CefSharp.Example.netcore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@
<Content Include="Resources\assets\js\jquery.js" />
<Content Include="Resources\assets\js\shBrushCSharp.js" />
<Content Include="Resources\assets\js\shCore.js" />
<Content Include="Resources\BindingTestAsync.js" />
<Content Include="Resources\BindingTestNetCore.html" />
<Content Include="Resources\BindingTestsAsyncTask.html" />
<Content Include="Resources\BindingApiCustomObjectNameTest.html" />
<Content Include="Resources\BindingTestSingle.html" />
<Content Include="Resources\BindingTestSync.js" />
<Content Include="Resources\DragDropCursorsTest.html" />
<Content Include="Resources\JavascriptCallbackTest.html" />
<Content Include="Resources\LegacyBindingTest.html" />
Expand Down
53 changes: 53 additions & 0 deletions CefSharp.Test/CefSharp.Test.netcore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<!-- Note: We cannot use the recommended style of specifying <Project Sdk=...> because we need
to set BaseIntermediateOutputPath and BaseOutputPath before the SDK props are imported. -->
<PropertyGroup>
<BaseIntermediateOutputPath>obj.netcore\</BaseIntermediateOutputPath>
<BaseOutputPath>bin.netcore\</BaseOutputPath>
</PropertyGroup>

<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk.WindowsDesktop" />

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>CefSharp.Test</RootNamespace>
<AssemblyName>CefSharp.Test</AssemblyName>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Platforms>x86;x64</Platforms>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CefSharp\CefSharp.netcore.csproj" />
<ProjectReference Include="..\CefSharp.Core\CefSharp.Core.netcore.vcxproj" />
<ProjectReference Include="..\CefSharp.OffScreen\CefSharp.OffScreen.netcore.csproj" />
<ProjectReference Include="..\CefSharp.WinForms\CefSharp.WinForms.netcore.csproj" />
<ProjectReference Include="..\CefSharp.Wpf\CefSharp.Wpf.netcore.csproj" />
<ProjectReference Include="..\CefSharp.Example\CefSharp.Example.netcore.csproj" />
<PackageReference Condition="'$(PlatformTarget)' == 'x86'" Include="cef.redist.x86" Version="84.3.3" />
<PackageReference Condition="'$(PlatformTarget)' == 'x64'" Include="cef.redist.x64" Version="84.3.3" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Moq" Version="4.13.0" />
<PackageReference Include="Nito.AsyncEx.Context" Version="5.0.0" />
<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Xunit.StaFact" Version="0.3.18" />
</ItemGroup>

<ItemGroup>
<!-- Don't include items from the "bin" and "obj" folders used by the .NET Framework projects. -->
<None Remove="bin/**/*.*" />
<None Remove="obj/**/*.*" />
<Compile Remove="obj/**/*.*" />
</ItemGroup>

<Import Project="$(SolutionDir)\CefSharp.AfterBuild.targets" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk.WindowsDesktop" />
</Project>
8 changes: 8 additions & 0 deletions CefSharp.Test/Framework/ConcurrentMethodRunnerQueueFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public async Task StopConcurrentMethodRunnerQueueWhenMethodRunning()
var boundObject = new AsyncBoundObject();

var objectRepository = new JavascriptObjectRepository();
#if NETCOREAPP
objectRepository.Register("testObject", boundObject, new BindingOptions { CamelCaseJavascriptNames = false });
#else
objectRepository.Register("testObject", boundObject, true, new BindingOptions { CamelCaseJavascriptNames = false });
#endif
var methodInvocation = new MethodInvocation(1, 1, 1, nameof(boundObject.AsyncWaitTwoSeconds), 1);
methodInvocation.Parameters.Add("Echo Me!");
var methodRunnerQueue = new ConcurrentMethodRunnerQueue(objectRepository);
Expand All @@ -49,7 +53,11 @@ public async Task ValidateAsyncTaskMethodOutput()
var boundObject = new AsyncBoundObject();

var objectRepository = new JavascriptObjectRepository();
#if NETCOREAPP
objectRepository.Register("testObject", boundObject, new BindingOptions { CamelCaseJavascriptNames = false });
#else
objectRepository.Register("testObject", boundObject, true, new BindingOptions { CamelCaseJavascriptNames = false });
#endif
var methodInvocation = new MethodInvocation(1, 1, 1, nameof(boundObject.AsyncWaitTwoSeconds), 1);
methodInvocation.Parameters.Add(expectedResult);
var methodRunnerQueue = new ConcurrentMethodRunnerQueue(objectRepository);
Expand Down
23 changes: 23 additions & 0 deletions CefSharp.Test/JavascriptBinding/IntegrationTestFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ public IntegrationTestFacts(ITestOutputHelper output, CefSharpFixture fixture)
this.output = output;
}

#if NETCOREAPP
[Fact]
public async Task LoadJavaScriptBindingQunitTestsSuccessfulCompletion()
{
using (var browser = new ChromiumWebBrowser(CefExample.BindingTestNetCoreUrl, automaticallyCreateBrowser: false))
{
//TODO: Extract this into some sort of helper setup method
var bindingOptions = BindingOptions.DefaultBinder;
var repo = browser.JavascriptObjectRepository;

repo.Register("boundAsync", new AsyncBoundObject(), options: bindingOptions);
repo.Register("boundAsync2", new AsyncBoundObject(), options: bindingOptions);

browser.CreateBrowser();
var success = await browser.WaitForQUnitTestExeuctionToComplete();

Assert.True(success);

output.WriteLine("QUnit Tests result: {0}", success);
}
}
#else
[Fact]
public async Task LoadJavaScriptBindingQunitTestsSuccessfulCompletion()
{
Expand All @@ -52,6 +74,7 @@ public async Task LoadJavaScriptBindingQunitTestsSuccessfulCompletion()
output.WriteLine("QUnit Tests result: {0}", success);
}
}
#endif

[Fact]
public async Task IsObjectCachedWithInvalidObjectNameReturnsFalse()
Expand Down
9 changes: 8 additions & 1 deletion CefSharp.Test/OffScreen/OffScreenBrowserBasicFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ public async Task CrossSiteNavigationJavascriptBinding()

using (var browser = new ChromiumWebBrowser("https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/url"))
{
#if NETCOREAPP
browser.JavascriptObjectRepository.Register("bound", boundObj);
#else
browser.JavascriptObjectRepository.Register("bound", boundObj, true);
#endif

await browser.LoadPageAsync();
browser.GetMainFrame().ExecuteJavaScriptAsync(script);
Expand Down Expand Up @@ -149,8 +153,11 @@ public async Task JavascriptBindingMultipleObjects()
browser.JavascriptObjectRepository.ResolveObject += (s, e) =>
{
objectNames.Add(e.ObjectName);

#if NETCOREAPP
e.ObjectRepository.Register(e.ObjectName, boundObj);
#else
e.ObjectRepository.Register(e.ObjectName, boundObj, isAsync: true);
#endif
};

await browser.LoadPageAsync();
Expand Down
14 changes: 14 additions & 0 deletions CefSharp3.netcore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CefSharp.OffScreen.Example.
{FBFBD752-467C-444F-93E4-80D6242E8513} = {FBFBD752-467C-444F-93E4-80D6242E8513}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CefSharp.Test.netcore", "CefSharp.Test\CefSharp.Test.netcore.csproj", "{51890C83-8FA3-4C9D-B3B7-A7DDF3C14A40}"
ProjectSection(ProjectDependencies) = postProject
{6C4BB501-2F8E-48AC-9AB5-8CFB2D74185C} = {6C4BB501-2F8E-48AC-9AB5-8CFB2D74185C}
{FBFBD752-467C-444F-93E4-80D6242E8513} = {FBFBD752-467C-444F-93E4-80D6242E8513}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -159,6 +165,14 @@ Global
{A430C9D4-0952-44A2-989A-23C476B7A1F0}.Release|x64.Build.0 = Release|x64
{A430C9D4-0952-44A2-989A-23C476B7A1F0}.Release|x86.ActiveCfg = Release|x86
{A430C9D4-0952-44A2-989A-23C476B7A1F0}.Release|x86.Build.0 = Release|x86
{51890C83-8FA3-4C9D-B3B7-A7DDF3C14A40}.Debug|x64.ActiveCfg = Debug|x64
{51890C83-8FA3-4C9D-B3B7-A7DDF3C14A40}.Debug|x64.Build.0 = Debug|x64
{51890C83-8FA3-4C9D-B3B7-A7DDF3C14A40}.Debug|x86.ActiveCfg = Debug|x86
{51890C83-8FA3-4C9D-B3B7-A7DDF3C14A40}.Debug|x86.Build.0 = Debug|x86
{51890C83-8FA3-4C9D-B3B7-A7DDF3C14A40}.Release|x64.ActiveCfg = Release|x64
{51890C83-8FA3-4C9D-B3B7-A7DDF3C14A40}.Release|x64.Build.0 = Release|x64
{51890C83-8FA3-4C9D-B3B7-A7DDF3C14A40}.Release|x86.ActiveCfg = Release|x86
{51890C83-8FA3-4C9D-B3B7-A7DDF3C14A40}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 1af1065

Please sign in to comment.