diff --git a/src/IoTHub.Portal.Client/Dialogs/Planning/DeletePlanningDialog.razor b/src/IoTHub.Portal.Client/Dialogs/Planning/DeletePlanningDialog.razor index 39973d46c..527005418 100644 --- a/src/IoTHub.Portal.Client/Dialogs/Planning/DeletePlanningDialog.razor +++ b/src/IoTHub.Portal.Client/Dialogs/Planning/DeletePlanningDialog.razor @@ -16,7 +16,7 @@ - Cancel + Cancel Delete @@ -60,9 +60,9 @@ private async Task DeletePlanningOnLayer(string planningId) { - foreach (var layer in Layers.Where(layer => layer.Planning == planningId)) + foreach (var layerId in Layers.Where(layer => layer.Planning == planningId).Select(layer => layer.Id)) { - var updatedLayer = FindLayer(layer.Id); + var updatedLayer = FindLayer(layerId); updatedLayer.Planning = null; await LayerClientService.UpdateLayer(updatedLayer); } diff --git a/src/IoTHub.Portal.Infrastructure/Jobs/SendPlanningCommandJob.cs b/src/IoTHub.Portal.Infrastructure/Jobs/SendPlanningCommandJob.cs index c90e22ab0..b7c6059ce 100644 --- a/src/IoTHub.Portal.Infrastructure/Jobs/SendPlanningCommandJob.cs +++ b/src/IoTHub.Portal.Infrastructure/Jobs/SendPlanningCommandJob.cs @@ -125,9 +125,9 @@ public async Task UpdateAPI() public void UpdateDatabase() { - foreach (var device in this.devices.Data) + foreach (var device in this.devices.Data.Where(d => !string.IsNullOrWhiteSpace(d.LayerId))) { - if (!string.IsNullOrWhiteSpace(device.LayerId)) AddNewDevice(device); + AddNewDevice(device); } } @@ -162,10 +162,10 @@ public void AddCommand(PlanningCommand planningCommand) addPlanningSchedule(planningData, planningCommand); - foreach (var schedule in schedules) + foreach (var schedule in schedules.Where(s => s.PlanningId == planningCommand.planningId)) { // Add schedules to the planning - if (schedule.PlanningId == planningCommand.planningId) addSchedule(schedule, planningCommand); + addSchedule(schedule, planningCommand); } } } @@ -185,13 +185,10 @@ public void addPlanningSchedule(PlanningDto planningData, PlanningCommand planni { if (planningData != null) { - foreach (var key in planning.commands.Keys) + foreach (var key in planning.commands.Keys.Where(k => (planningData.DayOff & k) == planningData.DayOff)) { - if ((planningData.DayOff & key) == planningData.DayOff) - { - var newPayload = new PayloadCommand(getTimeSpan("0:00"), getTimeSpan("24:00"), planningData.CommandId); - planning.commands[key].Add(newPayload); - } + var newPayload = new PayloadCommand(getTimeSpan("0:00"), getTimeSpan("24:00"), planningData.CommandId); + planning.commands[key].Add(newPayload); } } } diff --git a/src/IoTHub.Portal.Tests.Unit/Client/Components/Planning/EditPlanningTest.cs b/src/IoTHub.Portal.Tests.Unit/Client/Components/Planning/EditPlanningTest.cs index 36149c547..f70ed0df7 100644 --- a/src/IoTHub.Portal.Tests.Unit/Client/Components/Planning/EditPlanningTest.cs +++ b/src/IoTHub.Portal.Tests.Unit/Client/Components/Planning/EditPlanningTest.cs @@ -563,14 +563,6 @@ public void ClickOnDeleteShouldDisplayConfirmationDialogAndRedirectIfConfirmed() var mockScheduleList = Fixture.CreateMany(2).ToList(); - var deviceModels = Fixture.CreateMany(2).ToList(); - - var expectedPaginatedDeviceModels = new PaginationResult() - { - Items = mockDeviceModel.ToList(), - TotalItems = mockDeviceModel.Count - }; - _ = this.mockLayerClientService.Setup(service => service.GetLayers()) .ReturnsAsync(new List diff --git a/src/IoTHub.Portal.Tests.Unit/Client/Dialogs/Layer/LinkDeviceLayerDialogTest.cs b/src/IoTHub.Portal.Tests.Unit/Client/Dialogs/Layer/LinkDeviceLayerDialogTest.cs index eb3ba89a3..14cfb8164 100644 --- a/src/IoTHub.Portal.Tests.Unit/Client/Dialogs/Layer/LinkDeviceLayerDialogTest.cs +++ b/src/IoTHub.Portal.Tests.Unit/Client/Dialogs/Layer/LinkDeviceLayerDialogTest.cs @@ -33,7 +33,6 @@ public override void Setup() public async Task LinkDeviceLayerDialog_Search_RendersCorrectlyAsync() { // Arrange - var searchedDevices = Fixture.CreateMany>(3).ToList(); var expectedLayerDto = Fixture.Create(); _ = this.mockDeviceClientService.Setup(service => @@ -71,7 +70,6 @@ public async Task LinkDeviceLayerDialog_Search_RendersCorrectlyAsync() public async Task LinkDeviceLayerDialog_Search_ShouldDisplayDevicesAsync() { // Arrange - var searchedDevices = Fixture.CreateMany>(3).ToList(); var expectedLayerDto = Fixture.Create(); var mockDeviceModel = new DeviceModelDto @@ -127,7 +125,6 @@ public async Task LinkDeviceLayerDialog_Search_ShouldDisplayDevicesAsync() public async Task LinkDeviceLayerDialog_Save_UpdatesDevices() { // Arrange - var searchedDevices = Fixture.CreateMany>(3).ToList(); var expectedLayerDto = Fixture.Create(); var mockDeviceModel = new DeviceModelDto diff --git a/src/IoTHub.Portal.Tests.Unit/Client/Dialogs/Planning/DeletePlanningDialogTest.cs b/src/IoTHub.Portal.Tests.Unit/Client/Dialogs/Planning/DeletePlanningDialogTest.cs index cd54c36f3..dd816a4fb 100644 --- a/src/IoTHub.Portal.Tests.Unit/Client/Dialogs/Planning/DeletePlanningDialogTest.cs +++ b/src/IoTHub.Portal.Tests.Unit/Client/Dialogs/Planning/DeletePlanningDialogTest.cs @@ -7,6 +7,7 @@ namespace IoTHub.Portal.Tests.Unit.Client.Dialogs.Planning using System.Collections.Generic; using System.Threading.Tasks; using IoTHub.Portal.Client.Dialogs.Planning; + using MudBlazor; [TestFixture] public class DeletePlanningDialogTest : BlazorUnitTest @@ -54,5 +55,38 @@ public async Task DeletePlanning_PlanningDeleted() // Assert cut.WaitForAssertion(() => MockRepository.VerifyAll()); } + + [Test] + public async Task OnClickOnCancelShouldCancelDialog2() + { + // Arrange + var planningId = Guid.NewGuid().ToString(); + var planningName = Guid.NewGuid().ToString(); + + _ = this.mockLayerClientService.Setup(service => service.GetLayers()) + .ReturnsAsync(new List()); + + var cut = RenderComponent(); + var dialogService = Services.GetService() as DialogService; + + var parameters = new DialogParameters + { + {"planningID", planningId}, + {"planningName", planningName} + }; + + IDialogReference dialogReference = null; + + _ = await cut.InvokeAsync(() => dialogReference = dialogService?.Show(string.Empty, parameters)); + cut.WaitForAssertion(() => cut.Find("#cancel-delete-planning")); + + // Act + cut.Find("#cancel-delete-planning").Click(); + var result = await dialogReference.Result; + + // Assert + _ = result.Canceled.Should().BeTrue(); + cut.WaitForAssertion(() => MockRepository.VerifyAll()); + } } }