-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96b35df
commit 7baa7bc
Showing
13 changed files
with
295 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# This workflow will build a .NET project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | ||
|
||
name: .NET | ||
|
||
on: | ||
push: | ||
branches: ["master"] | ||
pull_request: | ||
branches: ["master"] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
issues: read | ||
checks: write | ||
pull-requests: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: 8.0.x | ||
|
||
- name: Restore dependencies | ||
run: dotnet restore | ||
|
||
- name: Build | ||
run: dotnet build | ||
|
||
- name: Test | ||
run: dotnet test --logger:trx | ||
|
||
- name: Publish Test Results | ||
uses: EnricoMi/publish-unit-test-result-action@v2 | ||
if: always() | ||
with: | ||
files: | | ||
/home/runner/work/nlog-ntfy/nlog-ntfy/src/MichelMichels.NLog.Targets.Ntfy.Tests/TestResults/*.trx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>8.0.0.0</Version> | ||
<FileVersion>8.0.0.0</FileVersion> | ||
<InformationalVersion>8.0.0.0</InformationalVersion> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
src/MichelMichels.NLog.Targets.Ntfy.Tests/MichelMichels.NLog.Targets.Ntfy.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" /> | ||
<PackageReference Include="coverlet.collector" Version="6.0.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\MichelMichels.NLog.Targets.Ntfy\MichelMichels.NLog.Targets.Ntfy.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
</Project> |
114 changes: 56 additions & 58 deletions
114
src/MichelMichels.NLog.Targets.Ntfy.Tests/NtfyLayoutRendererTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,75 @@ | ||
using NLog; | ||
using MichelMichels.NLog.Targets.Ntfy; | ||
|
||
namespace MichelMichels.NLog.Targets.Ntfy.Tests | ||
namespace MichelMichels.NLog.Targets.Ntfy.Tests; | ||
|
||
[TestClass] | ||
public class NtfyLayoutRendererTests | ||
{ | ||
[TestClass] | ||
public class NtfyLayoutRendererTests | ||
[TestMethod] | ||
public void DefaultDateRendered() | ||
{ | ||
[TestMethod] | ||
public void DefaultDateRendered() | ||
{ | ||
// Arrange | ||
var layoutRenderer = new NtfyLayoutRenderer(); | ||
// Arrange | ||
var layoutRenderer = new NtfyLayoutRenderer(); | ||
|
||
// Act | ||
// Act | ||
|
||
// Assert | ||
Assert.IsTrue(layoutRenderer.IsDateRendered); | ||
} | ||
// Assert | ||
Assert.IsTrue(layoutRenderer.IsDateRendered); | ||
} | ||
|
||
[TestMethod] | ||
public void DateNotRendered() | ||
[TestMethod] | ||
public void DateNotRendered() | ||
{ | ||
// Arrange | ||
var layoutRenderer = new NtfyLayoutRenderer() | ||
{ | ||
// Arrange | ||
var layoutRenderer = new NtfyLayoutRenderer() | ||
{ | ||
IsDateRendered = false, | ||
}; | ||
var logEvent = new LogEventInfo(LogLevel.Info, "TestLogger", "This is a test message."); | ||
IsDateRendered = false, | ||
}; | ||
var logEvent = new LogEventInfo(LogLevel.Info, "TestLogger", "This is a test message."); | ||
|
||
// Act | ||
var result = layoutRenderer.Render(logEvent); | ||
// Act | ||
var result = layoutRenderer.Render(logEvent); | ||
|
||
// Assert | ||
Assert.IsFalse(layoutRenderer.IsDateRendered); | ||
Assert.AreEqual(2, result.Split('\n').Length); | ||
} | ||
// Assert | ||
Assert.IsFalse(layoutRenderer.IsDateRendered); | ||
Assert.AreEqual(2, result.Split('\n').Length); | ||
} | ||
|
||
[TestMethod] | ||
public void DebugRenderTest() | ||
{ | ||
// Arrange | ||
var renderer = new NtfyLayoutRenderer(); | ||
var logEvent = new LogEventInfo(LogLevel.Debug, "TestLogger", "This is a test log event."); | ||
var date = logEvent.TimeStamp; | ||
var dateString = date.ToString("dd/MM/yyyy"); | ||
var timeString = date.ToString("HH:mm"); | ||
[TestMethod] | ||
public void DebugRenderTest() | ||
{ | ||
// Arrange | ||
var renderer = new NtfyLayoutRenderer(); | ||
var logEvent = new LogEventInfo(LogLevel.Debug, "TestLogger", "This is a test log event."); | ||
var date = logEvent.TimeStamp; | ||
var dateString = date.ToString("dd/MM/yyyy"); | ||
var timeString = date.ToString("HH:mm"); | ||
|
||
// Act | ||
var result = renderer.Render(logEvent); | ||
// Act | ||
var result = renderer.Render(logEvent); | ||
|
||
// Assert | ||
Assert.AreEqual(5, result.Split('\n').Length); | ||
Assert.IsTrue(result.Split('\n')[0].Contains(dateString)); | ||
Assert.IsTrue(result.Split('\n')[1].Contains(timeString)); | ||
Assert.IsTrue(result.Split('\n')[3].Contains("This is a test log event.")); | ||
Assert.IsTrue(string.IsNullOrEmpty(result.Split("\n")[4])); | ||
} | ||
// Assert | ||
Assert.AreEqual(5, result.Split('\n').Length); | ||
Assert.IsTrue(result.Split('\n')[0].Contains(dateString)); | ||
Assert.IsTrue(result.Split('\n')[1].Contains(timeString)); | ||
Assert.IsTrue(result.Split('\n')[3].Contains("This is a test log event.")); | ||
Assert.IsTrue(string.IsNullOrEmpty(result.Split("\n")[4])); | ||
} | ||
|
||
[TestMethod] | ||
public void ExceptionTest() | ||
[TestMethod] | ||
public void ExceptionTest() | ||
{ | ||
// Arrange | ||
var renderer = new NtfyLayoutRenderer(); | ||
var logEvent = new LogEventInfo(LogLevel.Error, "TestLogger", "This is a test log event.") | ||
{ | ||
// Arrange | ||
var renderer = new NtfyLayoutRenderer(); | ||
var logEvent = new LogEventInfo(LogLevel.Error, "TestLogger", "This is a test log event.") | ||
{ | ||
Exception = new ArgumentNullException(), | ||
}; | ||
Exception = new ArgumentNullException(), | ||
}; | ||
|
||
// Act | ||
var result = renderer.Render(logEvent); | ||
// Act | ||
var result = renderer.Render(logEvent); | ||
|
||
// Assert | ||
Assert.AreEqual(7, result.Split('\n').Length); | ||
} | ||
// Assert | ||
Assert.AreEqual(7, result.Split('\n').Length); | ||
} | ||
} |
Oops, something went wrong.