fix: fixed the Git root searching plus added tests
parent
2d8829b8e9
commit
37f5e3f4cb
@ -1,7 +1,5 @@
|
||||
#dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=../artifacts/{assembly}-test-result.xml;MethodFormat=Default;FailureBodyFormat=Verbose" --collect:"XPlat Code Coverage"
|
||||
#dotnet new tool-manifest
|
||||
#dotnet tool install dotnet-reportgenerator-globaltool
|
||||
#dotnet tool run reportgenerator -reports:tests/*/TestResults/*/coverage.cobertura.xml -targetdir:./coverage "-reporttypes:Cobertura;TextSummary"
|
||||
#grep "Line coverage" coverage/Summary.txt
|
||||
|
||||
echo "Line coverage 0.00%"
|
||||
dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=../artifacts/{assembly}-test-result.xml;MethodFormat=Default;FailureBodyFormat=Verbose" --collect:"XPlat Code Coverage"
|
||||
dotnet new tool-manifest
|
||||
dotnet tool install dotnet-reportgenerator-globaltool
|
||||
dotnet tool run reportgenerator -reports:tests/*/TestResults/*/coverage.cobertura.xml -targetdir:./coverage "-reporttypes:Cobertura;TextSummary"
|
||||
grep "Line coverage" coverage/Summary.txt
|
||||
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace MfGames.IO.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Additional methods for types.
|
||||
/// </summary>
|
||||
public static class TypeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the directory for a given type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type assembly to get the directory.</param>
|
||||
/// <returns>The directory or null if the assembly or location is null.</returns>
|
||||
public static DirectoryInfo? GetDirectory(this Type? type)
|
||||
{
|
||||
return type?.Assembly.GetDirectory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the file for a given type's assembly.
|
||||
/// </summary>
|
||||
/// <param name="type">The type assembly to get the directory.</param>
|
||||
/// <returns>The directory or null if the assembly or location is null.</returns>
|
||||
public static FileInfo? GetFile(this Type? type)
|
||||
{
|
||||
return type?.Assembly.GetFile();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
using System.IO;
|
||||
|
||||
using MfGames.IO.Extensions;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace MfGames.IO.Tests
|
||||
{
|
||||
public class AssemblyExtensionsTests
|
||||
{
|
||||
[Fact]
|
||||
public void DirectoryExists()
|
||||
{
|
||||
DirectoryInfo? dir = this.GetType().Assembly.GetDirectory();
|
||||
|
||||
Assert.NotNull(dir);
|
||||
Assert.True(dir!.Exists);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FileExists()
|
||||
{
|
||||
FileInfo? file = this.GetType().Assembly.GetFile();
|
||||
|
||||
Assert.NotNull(file);
|
||||
Assert.True(file!.Exists);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System.IO;
|
||||
|
||||
using MfGames.IO.Extensions;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace MfGames.IO.Tests
|
||||
{
|
||||
public class GitRootTests
|
||||
{
|
||||
[Fact]
|
||||
public void FindGitRoot()
|
||||
{
|
||||
DirectoryInfo? dir = this.GetType().GetDirectory();
|
||||
DirectoryInfo? git = dir.FindGitRoot();
|
||||
|
||||
Assert.NotNull(git);
|
||||
Assert.True(git!.GetDirectories(".git").Length > 0);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\MfGames.IO\MfGames.IO.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue