Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/750 auto update copyright year #889

Merged
merged 3 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Check warning

Code scanning / CodeQL

Dereferenced variable may be null

Variable [result](1) may be null here because of [this](2) assignment.
_ = result.CopyrightYear.Should().Be(expectedCopyrightYear);

this.mockRepository.VerifyAll();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void MainLayoutShouldRenderCorrectly()
cut.WaitForAssertion(() => cut.FindComponent<Appbar>().Instance.Should().NotBeNull());
cut.WaitForAssertion(() => cut.FindComponent<MudDrawer>().Instance.Should().NotBeNull());
cut.WaitForAssertion(() => cut.FindComponent<NavMenu>().Instance.Should().NotBeNull());
cut.WaitForAssertion(() => cut.FindComponent<PortalFooter>().Instance.Should().NotBeNull());

_ = cut.Markup.Should().NotBeNullOrEmpty();
_ = cut.FindAll("div.mud-popover-provider").Count.Should().Be(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<PortalFooter>();

// Assert
cut.WaitForAssertion(() => cut.FindAll("p").Count.Should().Be(1));
cut.WaitForAssertion(() => cut.Find("p").TextContent.Should().Be(expectedCopyright));
}
}
}
4 changes: 1 addition & 3 deletions src/AzureIoTHub.Portal/Client/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
</MudMainContent>

<MudAppBar id="footer" Elevation="1" Style="top: auto; bottom: 0;" Dense="true">
<MudGrid Justify="Justify.Center">
<MudText Style="font-size:small">© 2021 Copyright:&nbsp; CGI France&nbsp;-&nbsp;@Portal.Version</MudText>
</MudGrid>
<PortalFooter />
</MudAppBar>
</MudLayout>

Expand Down
7 changes: 7 additions & 0 deletions src/AzureIoTHub.Portal/Client/Shared/PortalFooter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@using AzureIoTHub.Portal.Models.v10

@inject PortalSettings Portal

<MudGrid Justify="Justify.Center">
<MudText Style="font-size:small">© @Portal.CopyrightYear Copyright:&nbsp; CGI France&nbsp;-&nbsp;@Portal.Version</MudText>
</MudGrid>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +22,7 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10
public class SettingsController : ControllerBase
{
/// <summary>
/// The device client api indentity options.
/// The device client api identity options.
/// </summary>
private readonly ClientApiIndentityOptions configuration;

Expand Down Expand Up @@ -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)
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace AzureIoTHub.Portal.Models.v10
{
/// <summary>
/// Protal Settings.
/// Portal Settings.
/// </summary>
public class PortalSettings
{
Expand All @@ -22,5 +22,10 @@ public class PortalSettings
/// The poral name.
/// </summary>
public string PortalName { get; set; }

/// <summary>
/// Copyright Year
/// </summary>
public string CopyrightYear { get; set; }
}
}