Skip to content

Commit

Permalink
Added Integration Tests for Device Manager Service
Browse files Browse the repository at this point in the history
  • Loading branch information
DAQEM committed Jan 14, 2024
1 parent adc5d1c commit fca512e
Show file tree
Hide file tree
Showing 44 changed files with 402 additions and 94 deletions.
47 changes: 36 additions & 11 deletions .github/workflows/test_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ jobs:
run: npm run build
working-directory: ${{env.working-directory}}

integration-tests:
name: Integration Tests
snmp-polling-service-integration-tests:
name: SNMP Polling Service Integration Tests
runs-on: ubuntu-latest
env:
working-directory: Tests/Netmon.SNMPPolling.IntegrationTests
Expand All @@ -192,30 +192,55 @@ jobs:
netmon-snmp-test-agent
netmon-mysql
- name: Test SNMP Details
- name: Run Integration Tests
run: dotnet test --logger "console;verbosity=detailed" --logger "trx;LogFileName=test-results.trx" Netmon.SNMPPolling.IntegrationTests.csproj
working-directory: ${{env.working-directory}}

- name: Test
run: |
ls -al
ls -al TestResults
cat TestResults/test-results.trx | tail -n 10
- name: Integration Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: SNMP Polling Service Integration Test Report
path: "**/test-results.trx"
reporter: dotnet-trx
fail-on-error: true

device-manager-service-integration-tests:
name: Device Manager Service Integration Tests
runs-on: ubuntu-latest
env:
working-directory: Tests/Netmon.DeviceManager.IntegrationTests
needs: [account-service, device-manager-service, snmp-polling-service, user-web-app, admin-web-app, api-gateway]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Docker Compose Action
uses: isbang/compose-action@v1.5.1
with:
compose-file: "./docker-compose.yml"
services: |
netmon-account-service
netmon-mysql
- name: Run Integration Tests
run: dotnet test --logger "console;verbosity=detailed" --logger "trx;LogFileName=test-results.trx" Netmon.DeviceManager.IntegrationTests.csproj
working-directory: ${{env.working-directory}}

- name: Integration Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: Integration Test Report
name: Device Manager Service Integration Test Report
path: "**/test-results.trx"
reporter: dotnet-trx
fail-on-error: true

end-to-end-tests:
name: End to End Tests
runs-on: ubuntu-latest
needs: [integration-tests]
needs: [snmp-polling-service-integration-tests, device-manager-service-integration-tests]
timeout-minutes: 60

strategy:
Expand Down Expand Up @@ -244,7 +269,7 @@ jobs:
codeql:
name: CodeQL
runs-on: ubuntu-latest
needs: [integration-tests]
needs: [snmp-polling-service-integration-tests, device-manager-service-integration-tests]
timeout-minutes: 60
permissions:
actions: read
Expand Down
6 changes: 6 additions & 0 deletions Netmon.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Netmon.SNMPPolling.SNMP.Uni
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Netmon.AccountService", "Services\Netmon.AccountService\Netmon.AccountService.csproj", "{D96AA140-5388-45B9-A6DB-796F5E5D6805}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Netmon.DeviceManager.IntegrationTests", "Tests\Netmon.DeviceManager.IntegrationTests\Netmon.DeviceManager.IntegrationTests.csproj", "{DFC30258-5C45-408B-88C2-A4033740C79C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -90,5 +92,9 @@ Global
{D96AA140-5388-45B9-A6DB-796F5E5D6805}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D96AA140-5388-45B9-A6DB-796F5E5D6805}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D96AA140-5388-45B9-A6DB-796F5E5D6805}.Release|Any CPU.Build.0 = Release|Any CPU
{DFC30258-5C45-408B-88C2-A4033740C79C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DFC30258-5C45-408B-88C2-A4033740C79C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DFC30258-5C45-408B-88C2-A4033740C79C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DFC30258-5C45-408B-88C2-A4033740C79C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
23 changes: 15 additions & 8 deletions Netmon.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/Highlighting/HighlightingSourceSnapshotLocation/@EntryValue">C:\Users\basvd\AppData\Local\JetBrains\Rider2023.3\resharper-host\temp\Rider\vAny\CoverageData\_Netmon.1481318327\Snapshot\snapshot.utdcvr</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=e0a1c0c7_002Df1b5_002D473d_002D9b32_002Db8cc2963f373/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="GetPrivacyProvider_ShouldReturnAES192PrivacyProvider_WhenAES192ProtocolIsSelected" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;Or&gt;&#xD;
&lt;TestAncestor&gt;&#xD;
&lt;TestId&gt;NUnit3x::7F1D3097-C146-466F-8738-9C5AD15BC72A::net8.0::Netmon.SNMPPolling.SNMP.UnitTests.Security.PrivacyProviderTests.GetPrivacyProvider_ShouldReturnAES192PrivacyProvider_WhenAES192ProtocolIsSelected&lt;/TestId&gt;&#xD;
&lt;/TestAncestor&gt;&#xD;
&lt;Project Location="G:\School Projects\Netmon\Tests\Netmon.SNMPPolling.IntegrationTests" Presentation="&amp;lt;Netmon.SNMPPolling.IntegrationTests&amp;gt;" /&gt;&#xD;
&lt;Project Location="G:\School Projects\Netmon\Tests\Netmon.SNMPPolling.SNMP.UnitTests" Presentation="&amp;lt;Netmon.SNMPPolling.SNMP.UnitTests&amp;gt;" /&gt;&#xD;
&lt;/Or&gt;&#xD;
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=5bde24f9_002Dc65d_002D4e0e_002Dba0b_002D2567c6f9b509/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Test #3" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;TestAncestor&gt;&#xD;
&lt;TestId&gt;xUnit::DFC30258-5C45-408B-88C2-A4033740C79C::net8.0::Netmon.DeviceManager.IntegrationTests.DiscoverIntegrationTests&lt;/TestId&gt;&#xD;
&lt;/TestAncestor&gt;&#xD;
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=bd15442f_002D662b_002D464d_002Da47a_002D3f7d92e63832/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="Test" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;TestAncestor&gt;&#xD;
&lt;TestId&gt;xUnit::DFC30258-5C45-408B-88C2-A4033740C79C::net8.0::Netmon.DeviceManager.IntegrationTests.DiscoverIntegrationTests.Test&lt;/TestId&gt;&#xD;
&lt;/TestAncestor&gt;&#xD;
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=c71683dd_002Dd7b0_002D4d8e_002D8f85_002D88fb0030d125/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="Test #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;TestAncestor&gt;&#xD;
&lt;TestId&gt;xUnit::DFC30258-5C45-408B-88C2-A4033740C79C::net8.0::Netmon.DeviceManager.IntegrationTests.DiscoverIntegrationTests.Test&lt;/TestId&gt;&#xD;
&lt;/TestAncestor&gt;&#xD;
&lt;/SessionState&gt;</s:String>




Expand Down
6 changes: 3 additions & 3 deletions Services/Netmon.APIGateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["Netmon.APIGateway.csproj", "./"]
RUN dotnet restore "Netmon.APIGateway.csproj"
COPY ["Services/Netmon.APIGateway/Netmon.APIGateway.csproj", "Services/Netmon.APIGateway/"]
RUN dotnet restore "Services/Netmon.APIGateway/Netmon.APIGateway.csproj"
COPY . .
WORKDIR "/src/"
WORKDIR "/src/Services/Netmon.APIGateway"
RUN dotnet build "Netmon.APIGateway.csproj" -c Release -o /app/build

FROM build AS publish
Expand Down
3 changes: 2 additions & 1 deletion Services/Netmon.AccountService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
options.AddPolicy("CorsPolicy",
corsPolicyBuilder => corsPolicyBuilder.WithOrigins(builder.Configuration["Cors:AllowedOrigins"]?.Split(",") ?? Array.Empty<string>())
.AllowAnyMethod()
.AllowAnyHeader());
.AllowAnyHeader()
);
});

builder.Services.AddDataProtection()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Netmon.Data.Services.Read.Device;
using Netmon.Data.Services.Write.Device;

namespace Netmon.DeviceManager.Controllers.Device;

[ApiController]
[Authorize]
[Route("Device/Connection")]
public class DeviceConnectionController(
IDeviceConnectionReadService deviceConnectionReadService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Netmon.Data.Services.Read.Device;
using Netmon.Data.Services.Write.Device;
using Netmon.DeviceManager.DTO.Device;
Expand All @@ -7,6 +8,7 @@
namespace Netmon.DeviceManager.Controllers.Device;

[ApiController]
[Authorize]
[Route("Device")]
public class DeviceController(IDeviceReadService deviceReadService, IDeviceWriteService deviceWriteService)
: BaseController
Expand All @@ -21,12 +23,18 @@ public async Task<IActionResult> Get()
public async Task<IActionResult> GetDeviceById(Guid id, bool includeConnection = false)
{
IDevice? device = await deviceReadService.GetById(id, includeConnection);
return device == null ? NoContent() : Ok(DeviceWithConnectionDTO.FromDeviceWithConnection(device));
return device is null ? NoContent() : Ok(DeviceWithConnectionDTO.FromDeviceWithConnection(device));
}

[HttpPost]
public async Task<IActionResult> Post(DeviceCreateDTO deviceCreateDTO)
{
IDevice? existingDevice = await deviceReadService.GetByIpAddress(deviceCreateDTO.IpAddress);
if (existingDevice is not null)
{
return Conflict();
}

IDevice device = deviceCreateDTO.ToDevice();
device = await deviceWriteService.AddDeviceWithConnection(device);
DeviceWithConnectionDTO deviceDTO = DeviceWithConnectionDTO.FromDeviceWithConnection(device);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Netmon.Data.Services.Read.Component.Disk;
using Netmon.DeviceManager.DTO.Device.Statistics;
using Netmon.Models.Component.Disk;

namespace Netmon.DeviceManager.Controllers.Device.Statistics;

[ApiController]
[Authorize]
[Route("device/{id}/statistics/disk")]
public class DeviceDiskStatisticsController(IDiskReadService diskReadService) : BaseController
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Netmon.Data.Services.Read.Component.Interface;
using Netmon.DeviceManager.DTO.Device.Statistics;
using Netmon.Models.Component.Interface;

namespace Netmon.DeviceManager.Controllers.Device.Statistics;

[ApiController]
[Authorize]
[Route("device/{id}/statistics/interface")]
public class DeviceInterfaceStatisticsController(IInterfaceReadService interfaceReadService) : BaseController
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static DeviceConnectionDTO FromDeviceConnectionDBO(DeviceConnectionDBO de

public static DeviceConnectionDTO FromDeviceConnection(IDeviceConnection? deviceConnection)
{
if (deviceConnection == null) return new DeviceConnectionDTO();
if (deviceConnection is null) return new DeviceConnectionDTO();
return new DeviceConnectionDTO
{
Port = deviceConnection.Port,
Expand Down
7 changes: 6 additions & 1 deletion Services/Netmon.DeviceManager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,9 @@

}

app.Run();
app.Run();

namespace Netmon.DeviceManager
{
public class DeviceManagerProgram { }
}
12 changes: 6 additions & 6 deletions Services/Netmon.SNMPPolling/Controllers/DiscoverController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task<IActionResult> Details([FromBody] SNMPConnectionDTO snmpConnec
SNMPConnectionInfo snmpConnectionInfo = snmpConnectionDto.ToSNMPConnectionInfo();
IDevice? device = await devicePoller.PollDetails(snmpConnectionInfo);

if (device == null) return NotFound();
if (device is null) return NotFound();

return Ok(new
{
Expand All @@ -39,7 +39,7 @@ public async Task<IActionResult> Device([FromBody] SNMPConnectionDTO snmpConnect
SNMPConnectionInfo snmpConnectionInfo = snmpConnectionDto.ToSNMPConnectionInfo();
IDevice? device = await devicePoller.PollFull(snmpConnectionInfo);

return device == null ? NotFound() : Ok(DeviceOverviewDTO.FromDevice(device));
return device is null ? NotFound() : Ok(DeviceOverviewDTO.FromDevice(device));
}

[HttpPost("Disks")]
Expand All @@ -48,7 +48,7 @@ public async Task<IActionResult> Disks([FromBody] SNMPConnectionDTO snmpConnecti
SNMPConnectionInfo snmpConnectionInfo = snmpConnectionDto.ToSNMPConnectionInfo();
List<IDisk>? disks = await devicePoller.PollDisks(snmpConnectionInfo);

return disks == null ? NotFound() : Ok(disks.Select(DiskDTO.FromDisk).ToList());
return disks is null ? NotFound() : Ok(disks.Select(DiskDTO.FromDisk).ToList());
}

[HttpPost("Memory")]
Expand All @@ -57,7 +57,7 @@ public async Task<IActionResult> Memory([FromBody] SNMPConnectionDTO snmpConnect
SNMPConnectionInfo snmpConnectionInfo = snmpConnectionDto.ToSNMPConnectionInfo();
List<IMemory>? memory = await devicePoller.PollMemory(snmpConnectionInfo);

return memory == null ? NotFound() : Ok(memory.Select(MemoryDTO.FromMemory).ToList());
return memory is null ? NotFound() : Ok(memory.Select(MemoryDTO.FromMemory).ToList());
}

[HttpPost("Cpus")]
Expand All @@ -66,7 +66,7 @@ public async Task<IActionResult> Cpus([FromBody] SNMPConnectionDTO snmpConnectio
SNMPConnectionInfo snmpConnectionInfo = snmpConnectionDto.ToSNMPConnectionInfo();
List<ICpu>? cpus = await devicePoller.PollCpus(snmpConnectionInfo);

return cpus == null ? NotFound() : Ok(cpus.Select(CpuDTO.FromCpu).ToList());
return cpus is null ? NotFound() : Ok(cpus.Select(CpuDTO.FromCpu).ToList());
}

[HttpPost("Interfaces")]
Expand All @@ -75,6 +75,6 @@ public async Task<IActionResult> Interfaces([FromBody] SNMPConnectionDTO snmpCon
SNMPConnectionInfo snmpConnectionInfo = snmpConnectionDto.ToSNMPConnectionInfo();
List<IInterface>? interfaces = await devicePoller.PollInterfaces(snmpConnectionInfo);

return interfaces == null ? NotFound() : Ok(interfaces.Select(InterfaceDTO.FromInterface).ToList());
return interfaces is null ? NotFound() : Ok(interfaces.Select(InterfaceDTO.FromInterface).ToList());
}
}
2 changes: 1 addition & 1 deletion Services/Netmon.SNMPPolling/Controllers/PollController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task<IActionResult> Device([FromBody] SNMPConnectionDTO connectionI
SNMPConnectionInfo snmpConnectionInfo = connectionInfo.ToSNMPConnectionInfo();
IDevice? device = await devicePoller.PollFull(snmpConnectionInfo);

if (device == null) return NotFound();
if (device is null) return NotFound();

await deviceWriteService.AddOrUpdateFullDevice(device);

Expand Down
2 changes: 1 addition & 1 deletion Services/Netmon.SNMPPolling/DTO/DeviceConnectionDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DeviceConnectionDTO

public static DeviceConnectionDTO FromDeviceConnection(IDeviceConnection? deviceDeviceConnection)
{
if (deviceDeviceConnection == null) return new DeviceConnectionDTO();
if (deviceDeviceConnection is null) return new DeviceConnectionDTO();
return new DeviceConnectionDTO
{
SNMPVersion = deviceDeviceConnection.SNMPVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class CpuCoreMetricsWriteRepository(DevicesDatabase database) : ICpuCoreM
{
public async Task Add(CpuCoreMetricsDBO cpuCoreMetrics)
{
if (cpuCoreMetrics == null)
if (cpuCoreMetrics is null)
{
throw new ArgumentNullException(nameof(cpuCoreMetrics));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public class CpuCoreWriteRepository(
{
public async Task AddOrUpdate(CpuCoreDBO cpuCore)
{
if (cpuCore == null)
if (cpuCore is null)
{
throw new ArgumentNullException(nameof(cpuCore));
}

CpuCoreDBO? existingCpuCore = await database.CpuCores.FirstOrDefaultAsync(c => c.CpuId == cpuCore.CpuId && c.Index == cpuCore.Index);

if (existingCpuCore == null)
if (existingCpuCore is null)
{
cpuCore.Id = Guid.NewGuid();
await database.CpuCores.AddAsync(cpuCore);
Expand All @@ -29,7 +29,7 @@ public async Task AddOrUpdate(CpuCoreDBO cpuCore)
cpuCore.Id = existingCpuCore.Id;
database.Entry(existingCpuCore).CurrentValues.SetValues(cpuCore);

if (cpuCore.CpuCoreMetrics != null!)
if (cpuCore.CpuCoreMetrics is not null)
{
foreach (CpuCoreMetricsDBO cpuCoreMetrics in cpuCore.CpuCoreMetrics)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class CpuMetricsWriteRepository(DevicesDatabase database) : ICpuMetricsWr
{
public async Task Add(CpuMetricsDBO cpuMetrics)
{
if (cpuMetrics == null)
if (cpuMetrics is null)
{
throw new ArgumentNullException(nameof(cpuMetrics));
}
Expand Down
Loading

0 comments on commit fca512e

Please sign in to comment.