Skip to content

Commit

Permalink
add json output tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed May 7, 2024
1 parent 5157a05 commit dce2cd9
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Doki.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doki.Output.Extensions", "s
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doki.Output.Json", "src\Doki.Output.Json\Doki.Output.Json.csproj", "{00BCCBC0-A719-489C-A746-559B4D055B56}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doki.Output.Json.Tests", "tests\Doki.Output.Json.Tests\Doki.Output.Json.Tests.csproj", "{6CCD9EE6-B3FC-485F-9155-553165141B20}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -43,6 +45,7 @@ Global
{33DFFEBE-DB9E-4960-BB4E-3B58399E132C} = {568576F3-3D48-459E-B4D2-1790DAE80E7A}
{A89D22B2-2427-4863-A2D9-9E1BEFF37C61} = {568576F3-3D48-459E-B4D2-1790DAE80E7A}
{00BCCBC0-A719-489C-A746-559B4D055B56} = {568576F3-3D48-459E-B4D2-1790DAE80E7A}
{6CCD9EE6-B3FC-485F-9155-553165141B20} = {8C7B5305-B599-4F08-B28B-DD9F1715DD51}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6F31B87A-2BD3-4FB4-8C08-7E059A338D4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -89,5 +92,9 @@ Global
{00BCCBC0-A719-489C-A746-559B4D055B56}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00BCCBC0-A719-489C-A746-559B4D055B56}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00BCCBC0-A719-489C-A746-559B4D055B56}.Release|Any CPU.Build.0 = Release|Any CPU
{6CCD9EE6-B3FC-485F-9155-553165141B20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CCD9EE6-B3FC-485F-9155-553165141B20}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CCD9EE6-B3FC-485F-9155-553165141B20}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CCD9EE6-B3FC-485F-9155-553165141B20}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
31 changes: 31 additions & 0 deletions tests/Doki.Output.Json.Tests/Doki.Output.Json.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<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="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Doki.Output.Json\Doki.Output.Json.csproj" />
<ProjectReference Include="..\..\src\Doki\Doki.csproj" />
<ProjectReference Include="..\assemblies\Doki.TestAssembly.InheritanceChain.Abstractions\Doki.TestAssembly.InheritanceChain.Abstractions.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions tests/Doki.Output.Json.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
57 changes: 57 additions & 0 deletions tests/Doki.Output.Json.Tests/JsonOutputTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Text.Json;
using System.Xml.XPath;
using Doki.TestAssembly.InheritanceChain.Abstractions;
using Microsoft.Extensions.Logging.Abstractions;

namespace Doki.Output.Json.Tests;

public class JsonOutputTests
{
[Fact]
public async Task Test_Deserialization()
{
var outputDirectory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "doki"));

var emptyDocumentation = new XPathDocument(new StringReader("""
<?xml version="1.0"?>
<doc>
<assembly>
<name>Doki.TestAssembly.InheritanceChain.Abstractions</name>
</assembly>
<members>
<member name="T:Doki.TestAssembly.InheritanceChain.Abstractions.AbstractClass">
<summary>
This is an abstract class. See <see cref="T:Doki.TestAssembly.InheritanceChain.Abstractions.AbstractClass"/> for more information.
</summary>
<example>
This is an example of how to use the <see cref="T:Doki.TestAssembly.InheritanceChain.Abstractions.AbstractClass"/> class.
<code>
public class ExampleClass : AbstractClass {}
</code>
</example>
</member>
</members>
</doc>
"""));

var generator = new DocumentationGenerator();

generator.AddAssembly(typeof(AbstractClass).Assembly, emptyDocumentation);

generator.AddOutput(new JsonOutput(new OutputOptions<JsonOutput>
{
OutputDirectory = outputDirectory
}));

await generator.GenerateAsync(NullLogger.Instance);

var jsonFile = outputDirectory.GetFiles().Single();

var json = await File.ReadAllTextAsync(jsonFile.FullName);

var documentation = JsonSerializer.Deserialize<AssemblyDocumentation>(json);
Assert.NotNull(documentation);


}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
namespace Doki.TestAssembly.InheritanceChain.Abstractions;

/// <summary>
/// This is an abstract class. See <see cref="AbstractClass"/> for more information.
/// </summary>
/// <example>
/// This is an example of how to use the <see cref="AbstractClass"/> class.
/// <code>
/// public class ExampleClass : AbstractClass {}
/// </code>
/// </example>
public abstract class AbstractClass
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

</Project>

0 comments on commit dce2cd9

Please sign in to comment.