-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from MarkZither/dev
Dev
- Loading branch information
Showing
10 changed files
with
252 additions
and
58 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
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
131 changes: 131 additions & 0 deletions
131
Test/Log4net.Appender.InfluxDBSyslog.Tests/InfluxAppenderTests.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 |
---|---|---|
@@ -0,0 +1,131 @@ | ||
using log4net; | ||
using log4net.Config; | ||
using log4net.Layout; | ||
using Log4net.Appender.InfluxDBSyslog; | ||
using Moq; | ||
using RichardSzalay.MockHttp; | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Reflection; | ||
using Xunit; | ||
|
||
namespace Log4net.Appender.InfluxDBSyslog.Tests | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
public class InfluxAppenderTests : IDisposable | ||
{ | ||
private MockRepository mockRepository; | ||
|
||
public InfluxAppenderTests() | ||
{ | ||
this.mockRepository = new MockRepository(MockBehavior.Strict); | ||
var layout = new PatternLayout("%.255message"); | ||
layout.ActivateOptions(); | ||
|
||
var appender = new InfluxAppender() | ||
{ | ||
Name = "InfluxAppender", | ||
Host = "localhost" | ||
}; | ||
appender.ActivateOptions(); | ||
|
||
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); | ||
BasicConfigurator.Configure(logRepository); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
this.mockRepository.VerifyAll(); | ||
} | ||
|
||
private InfluxAppender CreateInfluxAppender() | ||
{ | ||
return new InfluxAppender(); | ||
} | ||
|
||
[Fact] | ||
public void AppendTest() | ||
{ | ||
// Arrange | ||
var mockHttp = new MockHttpMessageHandler(); | ||
|
||
// Setup a respond for the user api (including a wildcard in the URL) | ||
mockHttp.When("http://localhost:8086/*") | ||
.Respond(HttpStatusCode.NoContent, "application/json", "{}"); // Respond with JSON | ||
mockHttp.Fallback.Respond(new HttpClient()); | ||
// Inject the handler or client into your application code | ||
var client = mockHttp.ToHttpClient(); | ||
|
||
Mock<InfluxAppender> mock = new Mock<InfluxAppender>(client) { CallBase = true }; | ||
mock.Object.Host = "localhost"; | ||
mock.Object.RemotePort = 8086; | ||
mock.Object.Facility = "App"; | ||
mock.Object.AppName = "MyTestApp"; | ||
|
||
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); | ||
|
||
BasicConfigurator.Configure(logRepository, mock.Object); | ||
|
||
var log = LogManager.GetLogger(typeof(InfluxAppender)); | ||
// Act | ||
log.Info("message"); | ||
|
||
//Assert | ||
Assert.True(true); | ||
} | ||
|
||
[Fact] | ||
public void ActivateOptions_StateUnderTest_ExpectedBehavior() | ||
{ | ||
// Arrange | ||
var unitUnderTest = this.CreateInfluxAppender(); | ||
|
||
// Act | ||
unitUnderTest.ActivateOptions(); | ||
|
||
// Assert | ||
Assert.True(true); | ||
} | ||
|
||
[Fact] | ||
public void PropertyRemotePort_StoresCorrectly() | ||
{ | ||
// Arrange | ||
var unitUnderTest = this.CreateInfluxAppender(); | ||
|
||
// Act | ||
unitUnderTest.RemotePort = 8086; | ||
|
||
// Assert | ||
Assert.Equal(8086, unitUnderTest.RemotePort); | ||
} | ||
|
||
[Fact] | ||
public void PropertyHost_StoresCorrectly() | ||
{ | ||
// Arrange | ||
var unitUnderTest = this.CreateInfluxAppender(); | ||
|
||
// Act | ||
unitUnderTest.Host = "localhost"; | ||
|
||
// Assert | ||
Assert.Equal("localhost", unitUnderTest.Host); | ||
} | ||
|
||
[Fact] | ||
public void PropertyScheme_StoresCorrectly() | ||
{ | ||
// Arrange | ||
var unitUnderTest = this.CreateInfluxAppender(); | ||
|
||
// Act | ||
unitUnderTest.Scheme = "https"; | ||
|
||
// Assert | ||
Assert.Equal("https", unitUnderTest.Scheme); | ||
} | ||
} | ||
} |
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
70 changes: 70 additions & 0 deletions
70
Test/Log4net.Appender.InfluxDBSyslog.Tests/SyslogSeverityTests.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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using Log4net.Appender.InfluxDBSyslog; | ||
using Moq; | ||
using System; | ||
using Xunit; | ||
|
||
namespace Log4net.Appender.InfluxDBSyslog.Tests | ||
{ | ||
public class SyslogSeverityTests : IDisposable | ||
{ | ||
private MockRepository mockRepository; | ||
|
||
|
||
|
||
public SyslogSeverityTests() | ||
{ | ||
this.mockRepository = new MockRepository(MockBehavior.Strict); | ||
|
||
|
||
} | ||
|
||
public void Dispose() | ||
{ | ||
this.mockRepository.VerifyAll(); | ||
} | ||
|
||
private SyslogSeverity CreateSyslogSeverity() | ||
{ | ||
return new SyslogSeverity(); | ||
} | ||
|
||
[Fact] | ||
public void PropertySeverity_StoresCorrectly() | ||
{ | ||
// Arrange | ||
var unitUnderTest = this.CreateSyslogSeverity(); | ||
|
||
// Act | ||
unitUnderTest.Severity = "crit"; | ||
|
||
// Assert | ||
Assert.Equal("crit", unitUnderTest.Severity); | ||
} | ||
|
||
[Fact] | ||
public void PropertySeverityCode_StoresCorrectly() | ||
{ | ||
// Arrange | ||
var unitUnderTest = this.CreateSyslogSeverity(); | ||
|
||
// Act | ||
unitUnderTest.SeverityCode = 1; | ||
|
||
// Assert | ||
Assert.Equal(1, unitUnderTest.SeverityCode); | ||
} | ||
|
||
[Fact] | ||
public void GetSyslogSeverity_Should_GetSyslogSeverityFromLog4netLevel() | ||
{ | ||
// Arrange | ||
|
||
// Act | ||
var severity = Log4netSyslogSeverityConvertor.GetSyslogSeverity(log4net.Core.Level.Warn); | ||
|
||
// Assert | ||
Assert.Equal("warning", severity.Severity); | ||
Assert.Equal(4, severity.SeverityCode); | ||
} | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/Log4net.Appender.InfluxDBSyslog/Log4netSyslogSeverityConvertor.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using log4net.Core; | ||
|
||
namespace Log4net.Appender.InfluxDBSyslog | ||
{ | ||
internal static class Log4netSyslogSeverityConvertor | ||
{ | ||
internal static SyslogSeverity GetSyslogSeverity(Level level) | ||
{ | ||
switch (level.Name) | ||
{ | ||
case "FATAL": | ||
return new SyslogSeverity() { Severity = "emerg", SeverityCode = 0 }; | ||
|
||
case "ERROR": | ||
return new SyslogSeverity() { Severity = "err", SeverityCode = 3 }; | ||
|
||
case "WARN": | ||
return new SyslogSeverity() { Severity = "warning", SeverityCode = 4 }; | ||
|
||
case "INFO": | ||
return new SyslogSeverity() { Severity = "info", SeverityCode = 4 }; | ||
|
||
case "DEBUG": | ||
return new SyslogSeverity() { Severity = "debug", SeverityCode = 6 }; | ||
|
||
default: | ||
return new SyslogSeverity() { Severity = "notice", SeverityCode = 7 }; | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/Log4net.Appender.InfluxDBSyslog/Properties/InternalsVisibleTo.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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Log4net.Appender.InfluxDBSyslog.Tests")] |
Oops, something went wrong.