Skip to content

Commit

Permalink
Added markdown readme files to nuget packages (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm authored Nov 15, 2021
1 parent 4f12b48 commit a88b812
Show file tree
Hide file tree
Showing 24 changed files with 362 additions and 14 deletions.
10 changes: 10 additions & 0 deletions .azuredevops/Pipelines/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ stages:
value: 39ce9363-a308-4580-8610-ee11f4953539/01001223-8651-4b73-a7ca-ba27c3e10a3c

steps:
- script: git submodule update --init --recursive
displayName: Update git submodules

- task: UseDotNet@2
displayName: "Use dotnet sdk 2.1.x"
inputs:
Expand Down Expand Up @@ -90,6 +93,13 @@ stages:
errorActionPreference: 'silentlyContinue'
ignoreLASTEXITCODE: true

# regenerate markdowns without links (in order to generate markdown to be included in nuget package)
- pwsh: |
dotnet tool install --tool-path . MarkdownSnippets.Tool
./mdsnippets --omit-snippet-links true
displayName: Re-generate markdown without links
name: mdsnippets
- task: DotNetCoreCLI@2
displayName: DotNet Restore
inputs:
Expand Down
9 changes: 1 addition & 8 deletions .azuredevops/Pipelines/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,4 @@ stages:
command: push
packagesToPush: '$(Pipeline.Workspace)/CI/packages/*.nupkg;!$(Pipeline.Workspace)/**/*.symbols.nupkg'
nuGetFeedType: external
publishFeedCredentials: nuget.org
# - task: NuGetCommand@2
# displayName: NuGet push snupkg
# inputs:
# command: push
# packagesToPush: '$(Pipeline.Workspace)/CI/packages/*.snupkg'
# nuGetFeedType: external
# publishFeedCredentials: nuget.org
publishFeedCredentials: nuget.org
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task LoadAsStream()
<a id='snippet-loadastestfile'></a>
```cs
[Fact]
public async Task LoadAsTestFile()
public async Task LoadAsTestFileWithJson()
{
// You can also load the test file as a TestFile object.
TestFile testFile = EasyTestFile.Load();
Expand All @@ -76,7 +76,7 @@ public async Task LoadAsTestFile()
string text = await testFile.AsText();
}
```
<sup><a href='/tests/EasyTestFile.Xunit.Tests/Samples/UnitTestClass.cs#L39-L55' title='Snippet source file'>snippet source</a> | <a href='#snippet-loadastestfile' title='Start of snippet'>anchor</a></sup>
<sup><a href='/tests/EasyTestFile.Xunit.Tests/Samples/UnitTestClass.cs#L75-L91' title='Snippet source file'>snippet source</a> | <a href='#snippet-loadastestfile' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" Condition="$(Configuration) == 'Release'" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.240" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" Condition="$(Configuration) == 'Release'" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.240" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/EasyTestFile.Json/EasyTestFile.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<PackageId>EasyTestFile.NewtonsoftJson</PackageId>
<PackageTags>EasyTestFile;UnitTests;IntegrationTests;Json</PackageTags>
<Description>EasyTestFile NewtonsoftJson extension making it easy to read files as objects.</Description>
<PackageReadmeFile>PackageDescription.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -14,4 +15,8 @@
<ItemGroup>
<ProjectReference Include="..\EasyTestFile\EasyTestFile.csproj" PrivateAssets="None" />
</ItemGroup>

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\PackageDescription.md" Pack="true" PackagePath="$(PackageReadmeFile)" Visible="false" />
</ItemGroup>
</Project>
34 changes: 34 additions & 0 deletions src/EasyTestFile.Json/PackageDescription.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# EasyTestFile

EasyTestFile is a library that simplifies the creation and usage of testfiles in unittests.
Testfiles (like text, json, xml, binary, jpg, etc. etc.) are named based on the class and method name, are created if not exist, and are embedded as resource making sure the execution of the test is deterministic and do not rely on untracked files etc.

# EasyTestFile.Json

This package contains extension method(s) to deserialize TestFiles using json.

<!-- snippet: LoadJson -->
<a id='snippet-loadjson'></a>
```cs
[Fact] // or [Test]
public async Task JsonTestFile()
{
// load testfile
var settings = new EasyTestFileSettings();
settings.UseExtension("json");
TestFile testFile = EasyTestFile.Load(settings);

// deserialize testfile using Newtonsoft Json.
Person person = await testFile.AsObjectUsingNewtonsoft<Person>();

// do something with person object
// i.e. sut.Process(person);
}

public class Person
{
public string Name { get; set; }
}
```
<sup><a href='/tests/EasyTestFile.Xunit.Tests/Samples/UnitTestClass.cs#L36-L56' title='Snippet source file'>snippet source</a> | <a href='#snippet-loadjson' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
5 changes: 5 additions & 0 deletions src/EasyTestFile.Nunit/EasyTestFile.Nunit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<PackageId>EasyTestFile.NUnit</PackageId>
<PackageTags>EasyTestFile;UnitTests;IntegrationTests;NUnit</PackageTags>
<Description>Enables EasyTestFile when writing test using NUnit.</Description>
<PackageReadmeFile>PackageDescription.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -14,4 +15,8 @@
<ItemGroup>
<ProjectReference Include="..\EasyTestFile\EasyTestFile.csproj" PrivateAssets="None" />
</ItemGroup>

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\PackageDescription.md" Pack="true" PackagePath="$(PackageReadmeFile)" Visible="false" />
</ItemGroup>
</Project>
63 changes: 63 additions & 0 deletions src/EasyTestFile.Nunit/PackageDescription.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# EasyTestFile

EasyTestFile is a library that simplifies the creation and usage of testfiles in unittests.
Testfiles (like text, json, xml, binary, jpg, etc. etc.) are named based on the class and method name, are created if not exist, and are embedded as resource making sure the execution of the test is deterministic and do not rely on untracked files etc.

# EasyTestFile.Nunit

This package is required when your project uses NUnit for unittesting. No setup is required.

## Samples

<!-- snippet: NunitLoadAsText -->
<a id='snippet-nunitloadastext'></a>
```cs
[Test]
public async Task LoadAsText()
{
// Executing this test for the first time will create an empty testfile and throw an exception.
// Executing this test for the second time, this statement will read the testfile
// and returns the content as a string.
string text = await EasyTestFile.LoadAsText();

// and do whatever you want
}
```
<sup><a href='/tests/EasyTestFile.Nunit.Tests/Samples/UnitTestClass.cs#L11-L22' title='Snippet source file'>snippet source</a> | <a href='#snippet-nunitloadastext' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

<!-- snippet: NunitLoadAsStream -->
<a id='snippet-nunitloadasstream'></a>
```cs
[Test]
public async Task LoadAsStream()
{
// You can also load the testfile content as a stream.
Stream stream = await EasyTestFile.LoadAsStream();

}
```
<sup><a href='/tests/EasyTestFile.Nunit.Tests/Samples/UnitTestClass.cs#L24-L32' title='Snippet source file'>snippet source</a> | <a href='#snippet-nunitloadasstream' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or load the TestFile object first

<!-- snippet: NunitLoadAsTestFileBasic -->
<a id='snippet-nunitloadastestfilebasic'></a>
```cs
[Test]
public async Task LoadAsTestFile()
{
// You can also load the test file as a TestFile object.
TestFile testFile = EasyTestFile.Load();

// then you can load the content as a stream
Stream stream = testFile.AsStream();

// or like
string text = await testFile.AsText();
}
```
<sup><a href='/tests/EasyTestFile.Nunit.Tests/Samples/UnitTestClass.cs#L58-L71' title='Snippet source file'>snippet source</a> | <a href='#snippet-nunitloadastestfilebasic' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

5 changes: 5 additions & 0 deletions src/EasyTestFile.Xunit/EasyTestFile.Xunit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<PackageId>EasyTestFile.XUnit</PackageId>
<PackageTags>EasyTestFile;UnitTests;IntegrationTests;XUnit</PackageTags>
<Description>Enables EasyTestFile when writing test using XUnit.</Description>
<PackageReadmeFile>PackageDescription.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,4 +17,8 @@
<ItemGroup>
<ProjectReference Include="..\EasyTestFile\EasyTestFile.csproj" PrivateAssets="None" />
</ItemGroup>

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\PackageDescription.md" Pack="true" PackagePath="$(PackageReadmeFile)" Visible="false" />
</ItemGroup>
</Project>
77 changes: 77 additions & 0 deletions src/EasyTestFile.Xunit/PackageDescription.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# EasyTestFile

EasyTestFile is a library that simplifies the creation and usage of testfiles in unittests.
Testfiles (like text, json, xml, binary, jpg, etc. etc.) are named based on the class and method name, are created if not exist, and are embedded as resource making sure the execution of the test is deterministic and do not rely on untracked files etc.

# EasyTestFile.Nunit

This package is required when your project uses NUnit for unittesting. Make sure your test class is annotated with the attribute `[EasyTestFileXunit.UsesEasyTestFile]`.

## Attribute usage
<!-- snippet: XUnitAttributeUsage -->
<a id='snippet-xunitattributeusage'></a>
```cs
[UsesEasyTestFile]
public class TestClass1
{
// The attribute is required when using XUnit.
}
```
<sup><a href='/tests/EasyTestFile.Xunit.Tests/Samples/Samples.cs#L6-L12' title='Snippet source file'>snippet source</a> | <a href='#snippet-xunitattributeusage' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

## Usage

Default options to load as text or load as stream:

<!-- snippet: LoadAsText -->
<a id='snippet-loadastext'></a>
```cs
[Fact]
public async Task LoadAsText()
{
// Executing this test for the first time will create an empty testfile and throw an exception.
// Executing this test for the second time, this statement will read the testfile
// and returns the content as a string.
string text = await EasyTestFile.LoadAsText();

// and do whatever you want
}
```
<sup><a href='/tests/EasyTestFile.Xunit.Tests/Samples/UnitTestClass.cs#L12-L23' title='Snippet source file'>snippet source</a> | <a href='#snippet-loadastext' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

<!-- snippet: LoadAsStream -->
<a id='snippet-loadasstream'></a>
```cs
[Fact]
public async Task LoadAsStream()
{
// You can also load the testfile content as a stream.
Stream stream = await EasyTestFile.LoadAsStream();

}
```
<sup><a href='/tests/EasyTestFile.Xunit.Tests/Samples/UnitTestClass.cs#L25-L33' title='Snippet source file'>snippet source</a> | <a href='#snippet-loadasstream' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or load the TestFile object first

<!-- snippet: LoadAsTestFileBasic -->
<a id='snippet-loadastestfilebasic'></a>
```cs
[Fact]
public async Task LoadAsTestFile()
{
// You can also load the test file as a TestFile object.
TestFile testFile = EasyTestFile.Load();

// then you can load the content as a stream
Stream stream = testFile.AsStream();

// or like
string text = await testFile.AsText();
}
```
<sup><a href='/tests/EasyTestFile.Xunit.Tests/Samples/UnitTestClass.cs#L59-L72' title='Snippet source file'>snippet source</a> | <a href='#snippet-loadastestfilebasic' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
5 changes: 5 additions & 0 deletions src/EasyTestFile/EasyTestFile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<PackageId>EasyTestFile</PackageId>
<PackageTags>EasyTestFile;UnitTests;IntegrationTests;TestFiles</PackageTags>
<Description>EasyTestFile makes it easy to create and load files used in unittests.</Description>
<PackageReadmeFile>PackageDescription.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -25,4 +26,8 @@
</ItemGroup>
</Otherwise>
</Choose>

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\PackageDescription.md" Pack="true" PackagePath="$(PackageReadmeFile)" Visible="false" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions src/EasyTestFile/PackageDescription.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# EasyTestFile

EasyTestFile is a library that simplifies the creation and usage of testfiles in unittests.
Testfiles (like text, json, xml, binary, jpg, etc. etc.) are named based on the class and method name, are created if not exist, and are embedded as resource making sure the execution of the test is deterministic and do not rely on untracked files etc.

This package contains EasyTestFile framework independent logic. You should also refrence [EasyTestFile.XUnit](https://www.nuget.org/packages/EasyTestFile.XUnit/) or [EasyTestFile.NUnit](https://www.nuget.org/packages/EasyTestFile.NUnit/) depending on your test framwork.
10 changes: 10 additions & 0 deletions tests/EasyTestFile.Nunit.Tests/Samples/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[*.cs]
#
# Rules disabled due to sample code.
#

# IDE0007: Use implicit type
dotnet_diagnostic.IDE0007.severity = none

# IDE0059: Unnecessary assignment of a value
dotnet_diagnostic.IDE0059.severity = none
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Loading

0 comments on commit a88b812

Please sign in to comment.