dwCheckApi icon indicating copy to clipboard operation
dwCheckApi copied to clipboard

Needs Unit Tests

Open GaProgMan opened this issue 8 years ago • 3 comments

Using the xUnit.NET Test template (dotnet new xunit) add unit tests for the source code in the src directory.

Add the xUnit.NET test library to a directory at the root level (i.e. alongside the src directory) called tests

GaProgMan avatar Jun 01 '17 13:06 GaProgMan

An xunit test class library has been added. However the services, contexts and helpers need to be mocked to ensure that we are properly testing everything

GaProgMan avatar Jun 13 '17 21:06 GaProgMan

Add unit tests for db model to view model mappers (i.e BookViewModelHelper)

Example:

var new dbModel
{
      prop = value,
};
var viewModel = dbToViewModelMapper(dbModel);
Assert.AreEqual(value, viewModel.value, $"{nameof(viewModel.value)} should be mapped correctly.");

GaProgMan avatar Jun 20 '17 16:06 GaProgMan

Since I've moved this project to .NET core 2.1 (2.1.301), the xunit test runner no longer runs. It quits out with an error:

Detecting target frameworks in dwCheckApi.Tests.csproj... Building for framework netcoreapp2.1... dwCheckApi.Tests -> /home/jay/Code/Azure/dwCheckApi/dwCheckApi.Tests/bin/Debug/netcoreapp2.1/dwCheckApi.Tests.dll Running .NET Core 2.1.0 tests for framework netcoreapp2.1... It was not possible to find any compatible framework version The specified framework 'Microsoft.NETCore.App', version '2.1.0' was not found.

  • Check application dependencies and target a framework version installed at: /usr/share/dotnet/
  • Installing .NET Core prerequisites might help resolve this problem: http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
  • The .NET Core framework and SDK can be installed from: https://aka.ms/dotnet-download
  • The following versions are installed: 2.1.1 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

This is a known issue and has been reported on the xunit repo. There is currently a work around by using the latest build from MyGet.

I've TEMPORARILY gotten around this by including:

<RuntimeFrameworkVersion>2.1.0-rc1</RuntimeFrameworkVersion>

in the dwCheckApi.Tests.csproj and ensuring that I have the 2.1.0-rc1 SDK and runtime installed:

jay@Omoikane:~$ dotnet --list-sdks
2.1.300-rc1-008673 [/usr/share/dotnet/sdk]
2.1.301 [/usr/share/dotnet/sdk]
jay@Omoikane:~$ dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.0-rc1-final [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.0-rc1-final [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.0-rc1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Doing this allows all unit tests to be run (until a new build of xunit is released to NuGet)

GaProgMan avatar Jun 27 '18 19:06 GaProgMan