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

Review after code scanning #3259

Open
wants to merge 1 commit into
base: main-vnext
Choose a base branch
from
Open
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 @@ -16,7 +16,7 @@
</MudGrid>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton id="cancel-delete-planning" OnClick="Cancel">Cancel</MudButton>
<MudButton id="delete-planning" Color="Color.Primary" OnClick="DeletePlanning">Delete</MudButton>
</DialogActions>
</MudDialog>
Expand Down Expand Up @@ -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);

Check warning on line 65 in src/IoTHub.Portal.Client/Dialogs/Planning/DeletePlanningDialog.razor

View check run for this annotation

Codecov / codecov/patch

src/IoTHub.Portal.Client/Dialogs/Planning/DeletePlanningDialog.razor#L65

Added line #L65 was not covered by tests
updatedLayer.Planning = null;
await LayerClientService.UpdateLayer(updatedLayer);
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Select Note

This foreach loop immediately
maps its iteration variable to another variable
- consider mapping the sequence explicitly using '.Select(...)'.
Expand Down
17 changes: 7 additions & 10 deletions src/IoTHub.Portal.Infrastructure/Jobs/SendPlanningCommandJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,14 +563,6 @@ public void ClickOnDeleteShouldDisplayConfirmationDialogAndRedirectIfConfirmed()

var mockScheduleList = Fixture.CreateMany<ScheduleDto>(2).ToList();

var deviceModels = Fixture.CreateMany<DeviceModelDto>(2).ToList();

var expectedPaginatedDeviceModels = new PaginationResult<DeviceModelDto>()
{
Items = mockDeviceModel.ToList(),
TotalItems = mockDeviceModel.Count
};

_ = this.mockLayerClientService.Setup(service =>
service.GetLayers())
.ReturnsAsync(new List<LayerDto>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public override void Setup()
public async Task LinkDeviceLayerDialog_Search_RendersCorrectlyAsync()
{
// Arrange
var searchedDevices = Fixture.CreateMany<TableData<DeviceListItem>>(3).ToList();
var expectedLayerDto = Fixture.Create<LayerDto>();

_ = this.mockDeviceClientService.Setup(service =>
Expand Down Expand Up @@ -71,7 +70,6 @@ public async Task LinkDeviceLayerDialog_Search_RendersCorrectlyAsync()
public async Task LinkDeviceLayerDialog_Search_ShouldDisplayDevicesAsync()
{
// Arrange
var searchedDevices = Fixture.CreateMany<TableData<DeviceListItem>>(3).ToList();
var expectedLayerDto = Fixture.Create<LayerDto>();

var mockDeviceModel = new DeviceModelDto
Expand Down Expand Up @@ -127,7 +125,6 @@ public async Task LinkDeviceLayerDialog_Search_ShouldDisplayDevicesAsync()
public async Task LinkDeviceLayerDialog_Save_UpdatesDevices()
{
// Arrange
var searchedDevices = Fixture.CreateMany<TableData<DeviceListItem>>(3).ToList();
var expectedLayerDto = Fixture.Create<LayerDto>();

var mockDeviceModel = new DeviceModelDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<LayerDto>());

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

var parameters = new DialogParameters
{
{"planningID", planningId},
{"planningName", planningName}
};

IDialogReference dialogReference = null;

_ = await cut.InvokeAsync(() => dialogReference = dialogService?.Show<DeletePlanningDialog>(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());
}
}
}
Loading