-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create unit tests for TCP collector.
- Loading branch information
Showing
4 changed files
with
107 additions
and
1 deletion.
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
11 changes: 11 additions & 0 deletions
11
test/Serilog.Sinks.Splunk.TCP.Tests/Properties/launchSettings.json
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,11 @@ | ||
{ | ||
"profiles": { | ||
"test": { | ||
"commandName": "test" | ||
}, | ||
"test-dnxcore50": { | ||
"commandName": "test", | ||
"sdkVersion": "dnx-coreclr-win-x86.1.0.0-rc1-final" | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
test/Serilog.Sinks.Splunk.TCP.Tests/Serilog.Sinks.Splunk.TCP.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net462</TargetFramework> | ||
<AssemblyName>Serilog.Sinks.Splunk.Tests</AssemblyName> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<IsPackable>false</IsPackable> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
<PackageReference Include="xunit" Version="2.7.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.msbuild" Version="6.0.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Serilog.Sinks.TCP\Serilog.Sinks.Splunk.TCP.csproj" /> | ||
</ItemGroup> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.NetworkInformation; | ||
using System.Net.Sockets; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Serilog.Events; | ||
using Xunit; | ||
|
||
namespace Serilog.Sinks.Splunk.TCP.Tests; | ||
|
||
public class TCPCollectorTests | ||
{ | ||
[Fact] | ||
public void LoggerExtensionTest() | ||
{ | ||
using (var TestEnvironment = new TestEnvironment()) | ||
{ | ||
var log = new LoggerConfiguration() | ||
.WriteTo.SplunkViaTcp( | ||
new Serilog.Sinks.Splunk.SplunkTcpSinkConnectionInfo("127.0.0.1", 10001), | ||
restrictedToMinimumLevel: LevelAlias.Minimum, | ||
formatProvider: null, | ||
renderTemplate: true) | ||
.CreateLogger(); | ||
|
||
log.Information("Hello World"); | ||
} | ||
} | ||
|
||
} | ||
|
||
class TestEnvironment : IDisposable | ||
{ | ||
TcpListener TcpServer; | ||
|
||
readonly public int TcpServerAddress; | ||
|
||
public TestEnvironment(int TcpServerAddress = 10001) | ||
{ | ||
this.TcpServerAddress = TcpServerAddress; | ||
|
||
TcpServer = new TcpListener(IPAddress.Loopback, TcpServerAddress); | ||
|
||
TcpServer.Start(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
TcpServer.Stop(); | ||
} | ||
} |