I have a WPF dotnet Core 3.1 project and a separate test project, where I wish to be able to test ViewModels and Converters etc that reference WPF datatypes, such as the IValueConverter interface.
A minimal example is this dummy class in the WPF project:
Code:
public class DummyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
with this simple test:
Code:
[TestFixture]
public class DummyConverterTests
{
[Test]
public void ConverterTest()
{
var converter = new DummyConverter();
Assert.That(converter, Is.Not.Null);
}
}
NCrunch seems to fail already during the exploration phase, marking the test with "Not runnable: Exception occured during exploration". When it anyway finds the test and tries to run it it gets marked as failed with the trace output:
Quote:
System.IO.FileNotFoundException : Could not load file or assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
at MyWpfProject.Tests.Converters.DummyConverterTests.ConverterTest()
The test runs fine in Visual Studio 2019 Test Explorer. NCrunch can still run other tests in the test project that doesn't reference wpf.
Here is the project file for the test project:
Code:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>MyWpfProject.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MySolution\MyWpfProject.csproj" />
</ItemGroup>
</Project>
I have tried modifying the test project file like this:
Code:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>MyWpfProject.Tests</RootNamespace>
<UseWpf>true</UseWpf>
</PropertyGroup>
...
so the wpf assemblies are referenced, but it doesn't make any difference.
I haven't been able to figure out or find any other way to get the necessary wpf assemblies referenced in dotnet core.
Using NCrunch 4.2.0.7 in Visual Studio 2019 and dotnet core 3.1.
Thanks for any help,
Best regards Magnus
(I have the NCrunch license registered on my work mail but couldn't remember the password and tired of waiting for the reset password mail after 30 minutes...)