Skip to content

Commit

Permalink
288 Fix IoT Edge configuration page (#289)
Browse files Browse the repository at this point in the history
* Fix Startup.cs
* IConfigService renamed to be similar to IDeviceService
* Fix gateway configurations metrics reported
* IConfigService renamed in Tests
  • Loading branch information
audserraCGI authored Feb 21, 2022
1 parent 7cc732a commit e16653a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AzureIoTHub.Portal.Server.Controllers.V10;
using AzureIoTHub.Portal.Server.Interfaces;
using AzureIoTHub.Portal.Server.Services;
using Microsoft.Azure.Devices;
using Moq;
Expand All @@ -17,14 +16,14 @@ public class EdgeConfigurationsControllerTests
{
private MockRepository mockRepository;

private Mock<IConfigs> mockConfigsServices;
private Mock<IConfigService> mockConfigsServices;

[SetUp]
public void SetUp()
{
this.mockRepository = new MockRepository(MockBehavior.Strict);

this.mockConfigsServices = this.mockRepository.Create<IConfigs>();
this.mockConfigsServices = this.mockRepository.Create<IConfigService>();
}

private EdgeConfigurationsController CreateEdgeConfigurationsController()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public void SetUp()
this.mockRegistryManager = this.mockRepository.Create<RegistryManager>();
}

private ConfigsServices CreateConfigsServices()
private ConfigService CreateConfigsServices()
{
return new ConfigsServices(this.mockRegistryManager.Object);
return new ConfigService(this.mockRegistryManager.Object);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10
using System.Linq;
using System.Threading.Tasks;
using AzureIoTHub.Portal.Server.Helpers;
using AzureIoTHub.Portal.Server.Interfaces;
using AzureIoTHub.Portal.Server.Services;
using AzureIoTHub.Portal.Shared.Models.V10;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -21,9 +21,9 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10
[ApiExplorerSettings(GroupName = "IoT Edge")]
public class EdgeConfigurationsController : ControllerBase
{
private readonly IConfigs configService;
private readonly IConfigService configService;

public EdgeConfigurationsController(IConfigs configService)
public EdgeConfigurationsController(IConfigService configService)
{
this.configService = configService;
}
Expand Down
6 changes: 3 additions & 3 deletions src/AzureIoTHub.Portal/Server/Helpers/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ public static class ConfigHelper
{
/// <summary>
/// Checks if the specific metric (targeted/applied/success/failure) exists within the device,
/// Returns the corresponding value if so, else returns -1 as an error code.
/// Returns the corresponding value if so, else returns 0.
/// </summary>
/// <param name="item">Configuration item to convert into a ConfigListItem.</param>
/// <param name="metricName">Metric to retrieve (targetedCount, appliedCount, reportedSuccessfulCount or reportedFailedCount). </param>
/// <returns>Corresponding metric value, or -1 if it doesn't exist.</returns>
/// <returns>Corresponding metric value, or 0 if it doesn't exist.</returns>
public static long RetrieveMetricValue(Configuration item, string metricName)
{
if (item.SystemMetrics.Results.TryGetValue(metricName, out long result))
{
return result;
}

return -1;
return 0;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ namespace AzureIoTHub.Portal.Server.Services
{
using System.Collections.Generic;
using System.Threading.Tasks;
using AzureIoTHub.Portal.Server.Interfaces;
using Microsoft.Azure.Devices;

public class ConfigsServices : IConfigs
public class ConfigService : IConfigService
{
private readonly RegistryManager registryManager;

public ConfigsServices(
public ConfigService(
RegistryManager registry)
{
this.registryManager = registry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// 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.Interfaces
{
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.Devices;
using Microsoft.Azure.Devices;
using System.Collections.Generic;
using System.Threading.Tasks;

public interface IConfigs
namespace AzureIoTHub.Portal.Server.Services
{
public interface IConfigService
{
Task<IEnumerable<Configuration>> GetAllConfigs();

Task<Configuration> GetConfigItem(string id);
}
}
}
2 changes: 1 addition & 1 deletion src/AzureIoTHub.Portal/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddTransient<IDeviceModelMapper<DeviceModel, DeviceModel>, DeviceModelMapper>();
services.AddTransient<IDeviceModelMapper<DeviceModel, LoRaDeviceModel>, LoRaDeviceModelMapper>();

services.AddTransient<ConfigsServices>();
services.AddTransient<IConfigService, ConfigService>();

services.AddMudServices();

Expand Down

0 comments on commit e16653a

Please sign in to comment.