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

Fix/1140 edge model commands not saved #1148

Merged
merged 13 commits into from
Sep 1, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -105,49 +105,5 @@ public async Task ClickOnSubmitShouldUpdateModuleValues()
cut.WaitForAssertion(() => module.ModuleName.Should().Be("newModuleNameValue"));
cut.WaitForAssertion(() => module.ImageURI.Should().Be("newModuleImageUriValue"));
}

[Test]
public async Task ClickOnCancelShouldNotChangeModuleValues()
{
//Arrange
var moduleName = Guid.NewGuid().ToString();
var moduleVersion = Guid.NewGuid().ToString();
var moduleImageUri = Guid.NewGuid().ToString();

var module = new IoTEdgeModule()
{
ModuleName = moduleName,
Version = moduleVersion,
Status = "running",
ImageURI = moduleImageUri,
EnvironmentVariables = new List<IoTEdgeModuleEnvironmentVariable>(),
ModuleIdentityTwinSettings = new List<IoTEdgeModuleTwinSetting>(),
Commands = new List<IoTEdgeModuleCommand>()
};

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

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

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

cut.WaitForAssertion(() => cut.Find("div.mud-dialog-container").Should().NotBeNull());

cut.WaitForAssertion(() => cut.Find($"#{nameof(IoTEdgeModule.ModuleName)}").Change("newModuleNameValue"));
cut.WaitForAssertion(() => cut.Find($"#{nameof(IoTEdgeModule.ImageURI)}").Change("newModuleImageUriValue"));

var cancelButton = cut.WaitForElement("#CancelButton");
cancelButton.Click();

cut.WaitForAssertion(() => module.ModuleName.Should().Be(moduleName));
cut.WaitForAssertion(() => module.ImageURI.Should().Be(moduleImageUri));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,19 @@ public void GetDeviceTemplatesShouldThrowInternalServerErrorExceptionWhenAnIssue
// Assert
_ = act.Should().Throw<InternalServerErrorException>();
}

[Test]
public void GetEdgeModuleCommandsShouldThrowInternalServerErrorExceptionWhenAnIssueOccurs()
{
// Arrange
var connectionString = Guid.NewGuid().ToString();
var tableClientFactory = new TableClientFactory(connectionString);

// Act
var act = () => tableClientFactory.GetEdgeModuleCommands();

// Assert
_ = act.Should().Throw<InternalServerErrorException>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ namespace AzureIoTHub.Portal.Tests.Unit.Server.Mappers
{
using System;
using System.Collections.Generic;
using System.Linq;
using Azure.Data.Tables;
using AzureIoTHub.Portal.Models.v10;
using AzureIoTHub.Portal.Server.Entities;
using AzureIoTHub.Portal.Server.Managers;
using AzureIoTHub.Portal.Server.Mappers;
using Moq;
Expand Down Expand Up @@ -81,16 +83,32 @@ public void CreateEdgeDeviceModelShouldReturnIoTEdgeModelObject()
["Description"] = "description_test",
};

var modules = new List<IoTEdgeModule>(){ new IoTEdgeModule()};
var modules = new List<IoTEdgeModule>()
{
new IoTEdgeModule
{
ModuleName = "module"
}
};
var commands = new List<EdgeModuleCommand>()
{
new EdgeModuleCommand
{
PartitionKey = partitionKey,
Name = "Test",
RowKey = modules.First().ModuleName + "-" + "Test",
}
};

// Act
var result = edgeModelMapper.CreateEdgeDeviceModel(entity, modules);
var result = edgeModelMapper.CreateEdgeDeviceModel(entity, modules, commands);

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(rowKey, result.ModelId);
Assert.AreEqual("test-name", result.Name);
Assert.AreEqual(1, result.EdgeModules.Count);
Assert.AreEqual(1, result.EdgeModules.First().Commands.Count);

this.mockRepository.VerifyAll();
}
Expand Down
Loading