-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Increase retrieved edge device logs #591 * Add and update unit tests on edge device logs * Add unit tests on EdgeDeviceClientService * Add ut on ModuleLogsDialog
- Loading branch information
1 parent
344f181
commit aa6e384
Showing
15 changed files
with
571 additions
and
59 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
96 changes: 96 additions & 0 deletions
96
src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/Edge_Devices/ModuleLogsDialogTests.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,96 @@ | ||
// Copyright (c) CGI France. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.Edge_Devices | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using AzureIoTHub.Portal.Client.Pages.Edge_Devices; | ||
using AzureIoTHub.Portal.Client.Services; | ||
using AzureIoTHub.Portal.Models.v10; | ||
using Bunit; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using MudBlazor; | ||
using MudBlazor.Interop; | ||
using MudBlazor.Services; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class ModuleLogsDialogTests | ||
{ | ||
|
||
#pragma warning disable CA2213 // Disposable fields should be disposed | ||
private Bunit.TestContext testContext; | ||
#pragma warning restore CA2213 // Disposable fields should be disposed | ||
|
||
private MockRepository mockRepository; | ||
private Mock<IEdgeDeviceClientService> edgeDeviceClientServiceMock; | ||
private Mock<IDialogService> mockDialogService; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
this.testContext = new Bunit.TestContext(); | ||
|
||
this.mockRepository = new MockRepository(MockBehavior.Strict); | ||
this.edgeDeviceClientServiceMock = this.mockRepository.Create<IEdgeDeviceClientService>(); | ||
this.mockDialogService = this.mockRepository.Create<IDialogService>(); | ||
|
||
_ = this.testContext.Services.AddMudServices(); | ||
|
||
_ = this.testContext.Services.AddSingleton(this.edgeDeviceClientServiceMock.Object); | ||
|
||
_ = this.testContext.Services.AddSingleton(this.mockDialogService.Object); | ||
|
||
_ = this.testContext.JSInterop.Setup<BoundingClientRect>("mudElementRef.getBoundingClientRect", _ => true); | ||
_ = this.testContext.JSInterop.SetupVoid("mudPopover.connect", _ => true); | ||
} | ||
|
||
|
||
|
||
private IRenderedComponent<TComponent> RenderComponent<TComponent>(params ComponentParameter[] parameters) | ||
where TComponent : IComponent | ||
{ | ||
return this.testContext.RenderComponent<TComponent>(parameters); | ||
} | ||
|
||
[Test] | ||
public void ModuleLogsDialogParametersMustBeCorrect() | ||
{ | ||
// Arrange | ||
var deviceId = Guid.NewGuid().ToString(); | ||
|
||
var edgeModule = new IoTEdgeModule | ||
{ | ||
Version = "1.0", | ||
ModuleName = Guid.NewGuid().ToString() | ||
}; | ||
|
||
var expectedLog = new IoTEdgeDeviceLog | ||
{ | ||
Id = deviceId, | ||
Text = Guid.NewGuid().ToString(), | ||
LogLevel = 1, | ||
TimeStamp = DateTime.UtcNow | ||
}; | ||
|
||
var expectedLogs = new List<IoTEdgeDeviceLog>() | ||
{ | ||
expectedLog | ||
}; | ||
|
||
_ = edgeDeviceClientServiceMock.Setup(c => c.GetEdgeDeviceLogs(It.Is<string>(x => x.Equals(deviceId, StringComparison.Ordinal)), It.Is<IoTEdgeModule>(x => x.Equals(edgeModule)))) | ||
.ReturnsAsync(expectedLogs); | ||
|
||
// Act | ||
var cut = RenderComponent<ModuleLogsDialog>(ComponentParameter.CreateParameter("deviceId", deviceId), ComponentParameter.CreateParameter("edgeModule", edgeModule)); | ||
|
||
// Assert | ||
_ = cut.Instance.deviceId.Should().Be(deviceId); | ||
_ = cut.Instance.edgeModule.Should().Be(edgeModule); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.