From 2f04d15817654b70d551b5c2531928fa8970a1a6 Mon Sep 17 00:00:00 2001 From: Hocine Hacherouf Date: Wed, 29 Jun 2022 19:25:57 +0200 Subject: [PATCH 1/3] Add copyright year on portal settings #750 --- .../v1.0/SettingsControllerTest.cs | 38 ++++++++++++++++++- .../Controllers/v1.0/SettingsController.cs | 8 ++-- .../Shared/Models/v1.0/PortalSettings.cs | 7 +++- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/AzureIoTHub.Portal.Server.Tests.Unit/Controllers/v1.0/SettingsControllerTest.cs b/src/AzureIoTHub.Portal.Server.Tests.Unit/Controllers/v1.0/SettingsControllerTest.cs index 37007357c..11286bc68 100644 --- a/src/AzureIoTHub.Portal.Server.Tests.Unit/Controllers/v1.0/SettingsControllerTest.cs +++ b/src/AzureIoTHub.Portal.Server.Tests.Unit/Controllers/v1.0/SettingsControllerTest.cs @@ -4,9 +4,11 @@ namespace AzureIoTHub.Portal.Server.Tests.Unit.Controllers.V10 { using System; + using System.Globalization; using AzureIoTHub.Portal.Server.Controllers.V10; - using AzureIoTHub.Portal.Server.Identity; - using AzureIoTHub.Portal.Models.v10; + using FluentAssertions; + using Identity; + using Models.v10; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Moq; @@ -102,5 +104,37 @@ public void GetLoRaActivationSettingShouldReturnTrueToString() this.mockRepository.VerifyAll(); } + + [Test] + public void CopyrightYearShouldBeEqualsToCurrentYear() + { + // Arrange + var expectedCopyrightYear = DateTime.Now.Year.ToString(CultureInfo.InvariantCulture); + + const bool loraFeatureStatus = true; + + _ = this.mockConfiguration.SetupGet(c => c.Value).Returns(value: null); + + _ = this.mockConfigHandler + .SetupGet(c => c.IsLoRaEnabled) + .Returns(loraFeatureStatus); + + _ = this.mockConfigHandler + .SetupGet(c => c.PortalName) + .Returns(string.Empty); + + var controller = CreateController(); + + // Act + var response = controller.GetPortalSetting(); + var objectResult = response as ObjectResult; + var result = objectResult?.Value as PortalSettings; + + // Assert + _ = result.Should().NotBeNull(); + _ = result.CopyrightYear.Should().Be(expectedCopyrightYear); + + this.mockRepository.VerifyAll(); + } } } diff --git a/src/AzureIoTHub.Portal/Server/Controllers/v1.0/SettingsController.cs b/src/AzureIoTHub.Portal/Server/Controllers/v1.0/SettingsController.cs index 0d9f0c92c..b082fb75b 100644 --- a/src/AzureIoTHub.Portal/Server/Controllers/v1.0/SettingsController.cs +++ b/src/AzureIoTHub.Portal/Server/Controllers/v1.0/SettingsController.cs @@ -4,8 +4,9 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10 { using System; + using System.Globalization; using System.Reflection; - using AzureIoTHub.Portal.Server.Identity; + using Identity; using AzureIoTHub.Portal.Models.v10; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -21,7 +22,7 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10 public class SettingsController : ControllerBase { /// - /// The device client api indentity options. + /// The device client api identity options. /// private readonly ClientApiIndentityOptions configuration; @@ -67,7 +68,8 @@ public IActionResult GetPortalSetting() { IsLoRaSupported = this.configHandler.IsLoRaEnabled, PortalName = this.configHandler.PortalName ?? "Azure IoT Hub Portal", - Version = Assembly.GetExecutingAssembly().GetName().Version.ToString() + Version = Assembly.GetExecutingAssembly().GetName().Version?.ToString(), + CopyrightYear = DateTime.Now.Year.ToString(CultureInfo.InvariantCulture) }); } } diff --git a/src/AzureIoTHub.Portal/Shared/Models/v1.0/PortalSettings.cs b/src/AzureIoTHub.Portal/Shared/Models/v1.0/PortalSettings.cs index 10c7f9455..bb01fee71 100644 --- a/src/AzureIoTHub.Portal/Shared/Models/v1.0/PortalSettings.cs +++ b/src/AzureIoTHub.Portal/Shared/Models/v1.0/PortalSettings.cs @@ -4,7 +4,7 @@ namespace AzureIoTHub.Portal.Models.v10 { /// - /// Protal Settings. + /// Portal Settings. /// public class PortalSettings { @@ -22,5 +22,10 @@ public class PortalSettings /// The poral name. /// public string PortalName { get; set; } + + /// + /// Copyright Year + /// + public string CopyrightYear { get; set; } } } From b68ecb96063574afe0fa03ca281e909ab775661b Mon Sep 17 00:00:00 2001 From: Hocine Hacherouf Date: Wed, 29 Jun 2022 19:26:48 +0200 Subject: [PATCH 2/3] Move footer to a separated component + Add copyright year #750 --- .../Pages/Shared/PortalFooterTests.cs | 38 +++++++++++++++++++ .../Client/Shared/MainLayout.razor | 4 +- .../Client/Shared/PortalFooter.razor | 7 ++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/Shared/PortalFooterTests.cs create mode 100644 src/AzureIoTHub.Portal/Client/Shared/PortalFooter.razor diff --git a/src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/Shared/PortalFooterTests.cs b/src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/Shared/PortalFooterTests.cs new file mode 100644 index 000000000..a6f668f14 --- /dev/null +++ b/src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/Shared/PortalFooterTests.cs @@ -0,0 +1,38 @@ +// 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.Shared +{ + using Bunit; + using Client.Shared; + using FluentAssertions; + using Microsoft.Extensions.DependencyInjection; + using Models.v10; + using NUnit.Framework; + + [TestFixture] + public class PortalFooterTests : BlazorUnitTest + { + [Test] + public void PortalFooterShouldRenderCopyrightYearAndVersion() + { + // Arrange + var portalSettings = new PortalSettings + { + CopyrightYear = "9999", + Version = "1.2.3" + }; + + _ = Services.AddSingleton(portalSettings); + + var expectedCopyright = $"© {portalSettings.CopyrightYear} Copyright:  CGI France - {portalSettings.Version}"; + + // Act + var cut = RenderComponent(); + + // Assert + cut.WaitForAssertion(() => cut.FindAll("p").Count.Should().Be(1)); + cut.WaitForAssertion(() => cut.Find("p").TextContent.Should().Be(expectedCopyright)); + } + } +} diff --git a/src/AzureIoTHub.Portal/Client/Shared/MainLayout.razor b/src/AzureIoTHub.Portal/Client/Shared/MainLayout.razor index 38c1841cd..72046b1f9 100644 --- a/src/AzureIoTHub.Portal/Client/Shared/MainLayout.razor +++ b/src/AzureIoTHub.Portal/Client/Shared/MainLayout.razor @@ -31,9 +31,7 @@ - - © 2021 Copyright:  CGI France - @Portal.Version - + diff --git a/src/AzureIoTHub.Portal/Client/Shared/PortalFooter.razor b/src/AzureIoTHub.Portal/Client/Shared/PortalFooter.razor new file mode 100644 index 000000000..a2a5432bc --- /dev/null +++ b/src/AzureIoTHub.Portal/Client/Shared/PortalFooter.razor @@ -0,0 +1,7 @@ +@using AzureIoTHub.Portal.Models.v10 + +@inject PortalSettings Portal + + + © @Portal.CopyrightYear Copyright:  CGI France - @Portal.Version + From afda467f7f99dc701117678ed471b304607aa511 Mon Sep 17 00:00:00 2001 From: Hocine Hacherouf Date: Wed, 29 Jun 2022 19:38:11 +0200 Subject: [PATCH 3/3] Update unit test MainLayoutShouldRenderCorrectly --- .../Pages/Shared/MainLayoutTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/Shared/MainLayoutTests.cs b/src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/Shared/MainLayoutTests.cs index f04d82351..5b4e127ed 100644 --- a/src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/Shared/MainLayoutTests.cs +++ b/src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/Shared/MainLayoutTests.cs @@ -54,6 +54,7 @@ public void MainLayoutShouldRenderCorrectly() cut.WaitForAssertion(() => cut.FindComponent().Instance.Should().NotBeNull()); cut.WaitForAssertion(() => cut.FindComponent().Instance.Should().NotBeNull()); cut.WaitForAssertion(() => cut.FindComponent().Instance.Should().NotBeNull()); + cut.WaitForAssertion(() => cut.FindComponent().Instance.Should().NotBeNull()); _ = cut.Markup.Should().NotBeNullOrEmpty(); _ = cut.FindAll("div.mud-popover-provider").Count.Should().Be(1);