-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add .Net Standard 2.0. Add test and Travis CI.
- Loading branch information
Showing
11 changed files
with
386 additions
and
30 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,6 @@ | ||
language: csharp | ||
mono: none | ||
dotnet: 2.0.0 | ||
solution: ZabbixSender.Async.sln | ||
script: | ||
- dotnet test ZabbixSender.Async.Tests |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using Newtonsoft.Json.Linq; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ZabbixSender.Async.Tests | ||
{ | ||
[TestFixture] | ||
public class FormatterTests | ||
{ | ||
private static readonly byte[] ZabbixHeader = new byte[] { 90, 66, 88, 68, 1 }; | ||
|
||
[Test] | ||
public void RequestShouldStartWithZabbixHeader() | ||
{ | ||
using (var stream = new MemoryStream()) | ||
{ | ||
new Formatter().WriteRequest(stream, new[] { new SendData() }); | ||
Encoding.ASCII.GetString(stream.ToArray()).ShouldStartWith("ZBXD"); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task RequestShouldStartWithZabbixHeaderAsync() | ||
{ | ||
using (var stream = new MemoryStream()) | ||
{ | ||
await new Formatter().WriteRequestAsync(stream, new[] { new SendData() }); | ||
Encoding.ASCII.GetString(stream.ToArray()).ShouldStartWith("ZBXD"); | ||
} | ||
} | ||
|
||
[Test] | ||
public void RequestShouldEndWithJson() | ||
{ | ||
using (var stream = new MemoryStream()) | ||
{ | ||
new Formatter().WriteRequest(stream, new[] | ||
{ | ||
new SendData | ||
{ | ||
Host = "host1", | ||
Key = "key1" | ||
}, | ||
new SendData | ||
{ | ||
Host = "host2", | ||
Key = "key2", | ||
Value = "value2", | ||
Clock = new System.DateTime(2018, 12, 18) | ||
}, | ||
}); | ||
|
||
var result = Encoding.ASCII.GetString(stream.ToArray()); | ||
|
||
var json = JToken.Parse(result.Substring(result.IndexOf('{'))); | ||
|
||
json.ShouldNotBeNull(); | ||
json.ShouldBeOfType<JObject>(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task RequestShouldEndWithJsonAsync() | ||
{ | ||
using (var stream = new MemoryStream()) | ||
{ | ||
await new Formatter().WriteRequestAsync(stream, new[] | ||
{ | ||
new SendData | ||
{ | ||
Host = "host1", | ||
Key = "key1" | ||
}, | ||
new SendData | ||
{ | ||
Host = "host2", | ||
Key = "key2", | ||
Value = "value2", | ||
Clock = new System.DateTime(2018, 12, 18) | ||
}, | ||
}); | ||
|
||
var result = Encoding.ASCII.GetString(stream.ToArray()); | ||
|
||
var json = JToken.Parse(result.Substring(result.IndexOf('{'))); | ||
|
||
json.ShouldNotBeNull(); | ||
json.ShouldBeOfType<JObject>(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void ShouldCheckResponseHeader() | ||
{ | ||
using (var stream = new MemoryStream()) | ||
Should.Throw<ProtocolException>(() => new Formatter().ReadResponse(stream)); | ||
} | ||
|
||
[Test] | ||
public void ShouldCheckResponseHeaderAsyncc() | ||
{ | ||
using (var stream = new MemoryStream()) | ||
Should.Throw<ProtocolException>(async () => await new Formatter().ReadResponseAsync(stream)); | ||
} | ||
|
||
[Test] | ||
public void ShouldRethrowJsonError() | ||
{ | ||
using (var stream = new MemoryStream( | ||
ZabbixHeader | ||
.Concat(new byte[8]) | ||
.Concat(Encoding.ASCII.GetBytes("[ \"invalid\" ]")) | ||
.ToArray())) | ||
Should.Throw<ProtocolException>(() => new Formatter().ReadResponse(stream)); | ||
} | ||
|
||
[Test] | ||
public void ShouldRethrowJsonErrorAsync() | ||
{ | ||
using (var stream = new MemoryStream( | ||
ZabbixHeader | ||
.Concat(new byte[8]) | ||
.Concat(Encoding.ASCII.GetBytes("[ \"invalid\" ]")) | ||
.ToArray())) | ||
Should.Throw<ProtocolException>(async () => await new Formatter().ReadResponseAsync(stream)); | ||
} | ||
} | ||
} |
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,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> | ||
<PackageReference Include="NUnit" Version="3.11.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.11.2" /> | ||
<PackageReference Include="Shouldly" Version="3.0.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ZabbixSender.Async\ZabbixSender.Async.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
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
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,16 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks> | ||
<Version>1.0.3</Version> | ||
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks> | ||
<Version>1.0.4</Version> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Copyright>Apache License 2.0 (stop-cran, 2018)</Copyright> | ||
<Authors>stop-cran <[email protected]></Authors> | ||
<Company>stop-cran <[email protected]></Company> | ||
<RepositoryUrl>https://github.com/stop-cran/ZabbixSender.Async</RepositoryUrl> | ||
<PackageReleaseNotes>Added documentation XML.</PackageReleaseNotes> | ||
<Description>The package provides a tool to send data to Zabbix in the same way as zabbix_sender tool. It implements Zabbix Sender Protocol 4.0.</Description> | ||
<PackageReleaseNotes>Added .Net Standard 2.0.</PackageReleaseNotes> | ||
<Description>A tool to send data to Zabbix in the same way as zabbix_sender tool. It implements Zabbix Sender Protocol 4.0.</Description> | ||
<DocumentationFile>ZabbixSender.Async.xml</DocumentationFile> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
|
Oops, something went wrong.