-
-
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.
Added SNMP Unit and Integration Test
- Loading branch information
Showing
14 changed files
with
737 additions
and
39 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 |
---|---|---|
|
@@ -62,6 +62,6 @@ | |
</Button> | ||
</div> | ||
</div> | ||
<DevicesTable {devices} /> | ||
<DevicesTable {devices} id={""} /> | ||
</div> | ||
</div> |
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 |
---|---|---|
|
@@ -87,4 +87,7 @@ | |
app.UseMiddleware<ExceptionMiddleware>(); | ||
} | ||
|
||
app.Run(); | ||
app.Run(); | ||
|
||
|
||
public partial class SNMPPollingProgram { } |
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 was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
Tests/Netmon.SNMPPolling.Tests/Integration/SNMPDiscoverIntegrationTests.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,36 @@ | ||
using System.Net.Http.Json; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Xunit; | ||
|
||
namespace Netmon.SNMPPolling.Tests.Integration; | ||
|
||
public class SNMPDiscoverIntegrationTests : IClassFixture<WebApplicationFactory<SNMPPollingProgram>> | ||
{ | ||
private readonly WebApplicationFactory<SNMPPollingProgram> _factory; | ||
|
||
public SNMPDiscoverIntegrationTests(WebApplicationFactory<SNMPPollingProgram> factory) | ||
{ | ||
_factory = factory; | ||
} | ||
|
||
[Theory] | ||
[InlineData("/Discover/Details")] | ||
public async Task Get_EndpointsReturnSuccessAndCorrectContentType(string url) | ||
{ | ||
// Arrange | ||
HttpClient client = _factory.CreateClient(); | ||
|
||
// Act | ||
HttpResponseMessage response = await client.PostAsJsonAsync(url, new | ||
{ | ||
version = "V2", | ||
ipAddress = "192.168.178.7", | ||
port = 161, | ||
community = "public" | ||
}); | ||
|
||
// Assert | ||
response.EnsureSuccessStatusCode(); | ||
Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType?.ToString()); | ||
} | ||
} |
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
133 changes: 133 additions & 0 deletions
133
Tests/Netmon.SNMPPolling.Tests/Unit/SNMP/Converter/Component/MIBCpuConverterTests.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,133 @@ | ||
using Lextm.SharpSnmpLib; | ||
using Netmon.Models.Component.Cpu; | ||
using Netmon.Models.Component.Cpu.Core; | ||
using Netmon.Models.Component.Cpu.Core.Metric; | ||
using Netmon.Models.Component.Cpu.Metric; | ||
using Netmon.SNMPPolling.SNMP.Converter.Component; | ||
using Netmon.SNMPPolling.SNMP.MIB; | ||
using Netmon.SNMPPolling.SNMP.MIB.HostResources; | ||
using Netmon.SNMPPolling.SNMP.MIB.HostResources.Device; | ||
using Netmon.SNMPPolling.SNMP.MIB.HostResources.Device.Device; | ||
using Netmon.SNMPPolling.SNMP.MIB.HostResources.Device.Processor; | ||
using Netmon.SNMPPolling.SNMP.MIB.UCDavis; | ||
using Netmon.SNMPPolling.SNMP.MIB.UCDavis.CpuLoad; | ||
using NUnit.Framework; | ||
|
||
namespace Netmon.SNMPPolling.Tests.SNMP.Converter.Component; | ||
|
||
[TestFixture] | ||
public class MIBCpuConverterTests | ||
{ | ||
[Test] | ||
public void ConvertMIBsToComponent_ShouldReturnEmptyList_WhenNoHostResourcesMIB() | ||
{ | ||
// Arrange | ||
List<IMIB> mibs = new(); | ||
MIBCpuConverter converter = new(); | ||
|
||
// Act | ||
List<ICpu> result = converter.ConvertMIBsToComponent(mibs); | ||
|
||
// Assert | ||
Assert.IsEmpty(result); | ||
} | ||
|
||
[Test] | ||
public void ConvertMIBsToComponent_ShouldReturnCpuWithCoresAndMetrics_WhenHostResourcesMIBExists() | ||
{ | ||
// Arrange | ||
HostResourcesMIB hostResourcesMIB = new() | ||
{ | ||
HrDevice = new HrDevice | ||
{ | ||
HrProcessorTable = new HrProcessorTable | ||
{ | ||
HrProcessorEntries = new List<HrProcessorEntry> | ||
{ | ||
new() | ||
{ | ||
HrProcessorIndex = new Integer32(1), | ||
HrProcessorLoad = new Integer32(50) | ||
} | ||
} | ||
}, | ||
HrDeviceTable = new HrDeviceTable | ||
{ | ||
HrDeviceEntries = new List<HrDeviceEntry> | ||
{ | ||
new() | ||
{ | ||
HrDeviceIndex = new Integer32(1), | ||
HrDeviceDescr = new OctetString("Processor 1") | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
List<IMIB> mibs = new() { hostResourcesMIB }; | ||
|
||
MIBCpuConverter converter = new(); | ||
|
||
// Act | ||
List<ICpu> result = converter.ConvertMIBsToComponent(mibs); | ||
|
||
// Assert | ||
Assert.IsNotEmpty(result); | ||
Assert.That(result, Has.Count.EqualTo(1)); | ||
|
||
ICpu cpu = result.First(); | ||
Assert.That(cpu.Index, Is.EqualTo(1)); | ||
Assert.IsNotEmpty(cpu.Cores); | ||
Assert.That(cpu.Cores, Has.Count.EqualTo(1)); | ||
|
||
ICpuCore core = cpu.Cores.First(); | ||
Assert.That(core.Index, Is.EqualTo(1)); | ||
Assert.That(core.Name, Is.EqualTo("Processor 1")); | ||
Assert.That(core.Metrics, Is.Not.Empty); | ||
Assert.That(core.Metrics, Has.Count.EqualTo(1)); | ||
|
||
ICpuCoreMetric metric = core.Metrics.First(); | ||
Assert.That(metric, Is.InstanceOf<CpuCoreMetric>()); | ||
Assert.That(((CpuCoreMetric)metric).Load, Is.EqualTo(50)); | ||
} | ||
|
||
[Test] | ||
public void ConvertMIBsToComponent_ShouldReturnCpuWithMetrics_WhenUCDavisMIBExists() | ||
{ | ||
// Arrange | ||
UCDavisMIB ucDavisMIB = new() | ||
{ | ||
LaLoadTable = new LaLoadTable | ||
{ | ||
LaLoadEntries = new List<LaLoadEntry> | ||
{ | ||
new() { LaLoadInt = new Integer32(1) }, | ||
new() { LaLoadInt = new Integer32(2) }, | ||
new() { LaLoadInt = new Integer32(3) } | ||
} | ||
} | ||
}; | ||
|
||
List<IMIB> mibs = new() { ucDavisMIB }; | ||
|
||
MIBCpuConverter converter = new(); | ||
|
||
// Act | ||
List<ICpu> result = converter.ConvertMIBsToComponent(mibs); | ||
|
||
// Assert | ||
Assert.IsNotEmpty(result); | ||
Assert.That(result, Has.Count.EqualTo(1)); | ||
|
||
ICpu cpu = result.First(); | ||
Assert.That(cpu.Index, Is.EqualTo(1)); | ||
Assert.IsEmpty(cpu.Cores); | ||
|
||
ICpuMetric metric = cpu.Metrics.First(); | ||
Assert.IsInstanceOf<CpuMetric>(metric); | ||
Assert.That(((CpuMetric)metric).OneMinuteLoad, Is.EqualTo(1)); | ||
Assert.That(((CpuMetric)metric).FiveMinuteLoad, Is.EqualTo(2)); | ||
Assert.That(((CpuMetric)metric).FifteenMinuteLoad, Is.EqualTo(3)); | ||
} | ||
} |
Oops, something went wrong.