Skip to content

Commit

Permalink
Rename unit test project #1018
Browse files Browse the repository at this point in the history
  • Loading branch information
hocinehacherouf committed Aug 9, 2022
1 parent abf776a commit 3334d8c
Show file tree
Hide file tree
Showing 131 changed files with 97 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<Folder Include="Factories\" />
<Folder Include="Handlers\" />
<Folder Include="Mocks\" />
<Folder Include="Constants\" />
<Folder Include="Client\Constants\" />
<Folder Include="Pages\Ideas\" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// 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.Constants
namespace AzureIoTHub.Portal.Server.Tests.Unit.Client.Constants
{
using Client.Constants;
using AzureIoTHub.Portal.Client.Constants;
using FluentAssertions;
using NUnit.Framework;

Expand Down
186 changes: 93 additions & 93 deletions ...es/Devices/ConnectionStringDialogTests.cs → ...es/Devices/ConnectionStringDialogTests.cs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
// 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.Devices
{
using System;
using System.Threading.Tasks;
using Bunit;
using Client.Exceptions;
using Client.Models;
using Client.Pages.Devices;
using Client.Services;
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Models.v10;
using Moq;
using MudBlazor;
using NUnit.Framework;

[TestFixture]
public class ConnectionStringDialogTests : BlazorUnitTest
{
private Mock<IDeviceClientService> mockDeviceClientService;

public override void Setup()
{
base.Setup();

this.mockDeviceClientService = MockRepository.Create<IDeviceClientService>();

_ = Services.AddSingleton(this.mockDeviceClientService.Object);
_ = Services.AddSingleton<ClipboardService>();
}

[Test]
public async Task ConnectionStringDialogMustBeRenderedOnShow()
{
// Arrange
var deviceId = Guid.NewGuid().ToString();

_ = this.mockDeviceClientService.Setup(service => service.GetEnrollmentCredentials(deviceId))
.ReturnsAsync(new EnrollmentCredentials());

var cut = RenderComponent<MudDialogProvider>();
var service = Services.GetService<IDialogService>() as DialogService;

var parameters = new DialogParameters
{
{
"deviceId", deviceId
}
};

// Act
await cut.InvokeAsync(() => service?.Show<ConnectionStringDialog>(string.Empty, parameters));

// Assert
cut.WaitForAssertion(() => cut.Find("div.mud-dialog-container").Should().NotBeNull());
cut.WaitForAssertion(() => MockRepository.VerifyAll());
}

[Test]
public async Task OnInitializedAsyncShouldProcessProblemDetailsExceptionWhenIssueOccursOnGettingCredentials()
{
// Arrange
var deviceId = Guid.NewGuid().ToString();

_ = this.mockDeviceClientService.Setup(service => service.GetEnrollmentCredentials(deviceId))
.ThrowsAsync(new ProblemDetailsException(new ProblemDetailsWithExceptionDetails()));

var cut = RenderComponent<MudDialogProvider>();
var service = Services.GetService<IDialogService>() as DialogService;

var parameters = new DialogParameters
{
{
"deviceId", deviceId
}
};

IDialogReference dialogReference = null;

// Act
await cut.InvokeAsync(() => dialogReference = service?.Show<ConnectionStringDialog>(string.Empty, parameters));

var result = await dialogReference.Result;

// Assert
cut.WaitForAssertion(() => result.Cancelled.Should().BeFalse());
cut.WaitForAssertion(() => MockRepository.VerifyAll());
}
}
}
// 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.Devices
{
using System;
using System.Threading.Tasks;
using Bunit;
using Client.Exceptions;
using Client.Models;
using Client.Pages.Devices;
using Client.Services;
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Models.v10;
using Moq;
using MudBlazor;
using NUnit.Framework;

[TestFixture]
public class ConnectionStringDialogTests : BlazorUnitTest
{
private Mock<IDeviceClientService> mockDeviceClientService;

public override void Setup()
{
base.Setup();

this.mockDeviceClientService = MockRepository.Create<IDeviceClientService>();

_ = Services.AddSingleton(this.mockDeviceClientService.Object);
_ = Services.AddSingleton<ClipboardService>();
}

[Test]
public async Task ConnectionStringDialogMustBeRenderedOnShow()
{
// Arrange
var deviceId = Guid.NewGuid().ToString();

_ = this.mockDeviceClientService.Setup(service => service.GetEnrollmentCredentials(deviceId))
.ReturnsAsync(new EnrollmentCredentials());

var cut = RenderComponent<MudDialogProvider>();
var service = Services.GetService<IDialogService>() as DialogService;

var parameters = new DialogParameters
{
{
"deviceId", deviceId
}
};

// Act
await cut.InvokeAsync(() => service?.Show<ConnectionStringDialog>(string.Empty, parameters));

// Assert
cut.WaitForAssertion(() => cut.Find("div.mud-dialog-container").Should().NotBeNull());
cut.WaitForAssertion(() => MockRepository.VerifyAll());
}

[Test]
public async Task OnInitializedAsyncShouldProcessProblemDetailsExceptionWhenIssueOccursOnGettingCredentials()
{
// Arrange
var deviceId = Guid.NewGuid().ToString();

_ = this.mockDeviceClientService.Setup(service => service.GetEnrollmentCredentials(deviceId))
.ThrowsAsync(new ProblemDetailsException(new ProblemDetailsWithExceptionDetails()));

var cut = RenderComponent<MudDialogProvider>();
var service = Services.GetService<IDialogService>() as DialogService;

var parameters = new DialogParameters
{
{
"deviceId", deviceId
}
};

IDialogReference dialogReference = null;

// Act
await cut.InvokeAsync(() => dialogReference = service?.Show<ConnectionStringDialog>(string.Empty, parameters));

var result = await dialogReference.Result;

// Assert
cut.WaitForAssertion(() => result.Cancelled.Should().BeFalse());
cut.WaitForAssertion(() => MockRepository.VerifyAll());
}
}
}
2 changes: 1 addition & 1 deletion src/AzureIoTHub.Portal.sln
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
..\.github\workflows\publish.yml = ..\.github\workflows\publish.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureIoTHub.Portal.Server.Tests.Unit", "AzureIoTHub.Portal.Server.Tests.Unit\AzureIoTHub.Portal.Server.Tests.Unit.csproj", "{51FD5B90-B422-47BF-83F2-516520CFB124}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureIoTHub.Portal.Tests.Unit", "AzureIoTHub.Portal.Tests.Unit\AzureIoTHub.Portal.Tests.Unit.csproj", "{51FD5B90-B422-47BF-83F2-516520CFB124}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{3F7A2982-4F0B-45F9-9FCA-923D5A7A1511}"
ProjectSection(SolutionItems) = preProject
Expand Down

0 comments on commit 3334d8c

Please sign in to comment.