Skip to content

Commit

Permalink
[.NET] Add test project and support for including native libs in build
Browse files Browse the repository at this point in the history
  • Loading branch information
burkenyo authored and speth committed Aug 17, 2022
1 parent 445fefd commit 5d1e645
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
2 changes: 2 additions & 0 deletions interfaces/dotnet/.gitignore
Expand Up @@ -35,3 +35,5 @@ msbuild.wrn

# Visual Studio 2015
.vs/

lib
34 changes: 34 additions & 0 deletions interfaces/dotnet/Cantera.Tests/Cantera.Tests.csproj
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<ProjectReference Include="..\Cantera\Cantera.csproj" />
</ItemGroup>

<Target Name="CopyLibraries" AfterTargets="AfterBuild">
<ItemGroup>
<Libraries Include="$([MSBuild]::NormalizePath(../lib/))*" />
</ItemGroup>

<Copy SourceFiles="@(Libraries)" DestinationFolder="$(OutDir)" />
</Target>

</Project>
19 changes: 19 additions & 0 deletions interfaces/dotnet/Cantera.Tests/CanteraExceptionTest.cs
@@ -0,0 +1,19 @@
using Cantera.Interop;
using Xunit;

namespace Cantera.Tests;

public class CanteraExceptionTest
{
[Fact]
public void CanteraException_Thrown()
{
Assert.Throws<CanteraException>(() =>
{
LibCantera.thermo_newFromFile(".yaml", "");
// test that an error message is gathered from the native library
CanteraException.ThrowLatest();
});
}
}
33 changes: 33 additions & 0 deletions interfaces/dotnet/Cantera.Tests/CanteraInfoTest.cs
@@ -0,0 +1,33 @@
using Xunit;

namespace Cantera.Tests;

public class CanteraInfoTest
{
[Fact]
public void CanteraInfo_VersionRetrieved()
{
// version string should start with a number
Assert.Matches("^[1-9]", CanteraInfo.Version);
}

[Fact]
public void CanteraInfo_GitCommitRetrieved()
{
Assert.NotEmpty(CanteraInfo.GitCommit);
}

[Fact]
public void CanteraInfo_DataDirectoryAdded()
{
var dirs = CanteraInfo.DataDirectories;
var originalCount = dirs.Count;
var longestDir = dirs.MaxBy(d => d.FullName.Length);

Assert.NotNull(longestDir);

dirs.Add(Path.Join(longestDir!.FullName, "garbazh"));

Assert.Equal(originalCount + 1, dirs.Count);
}
}
8 changes: 7 additions & 1 deletion interfaces/dotnet/Cantera.sln
@@ -1,10 +1,12 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cantera", "Cantera\Cantera.csproj", "{9FAB2B8A-5BAA-4D44-B0E4-1B00A45A7DAC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cantera.Tests", "Cantera.Tests\Cantera.Tests.csproj", "{55B543FD-7CDF-4147-8B52-15894B92B6EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -18,5 +20,9 @@ Global
{9FAB2B8A-5BAA-4D44-B0E4-1B00A45A7DAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9FAB2B8A-5BAA-4D44-B0E4-1B00A45A7DAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9FAB2B8A-5BAA-4D44-B0E4-1B00A45A7DAC}.Release|Any CPU.Build.0 = Release|Any CPU
{55B543FD-7CDF-4147-8B52-15894B92B6EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{55B543FD-7CDF-4147-8B52-15894B92B6EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{55B543FD-7CDF-4147-8B52-15894B92B6EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{55B543FD-7CDF-4147-8B52-15894B92B6EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

0 comments on commit 5d1e645

Please sign in to comment.