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

Avoid usage of Thread.Sleep : Devices #844

Merged
merged 9 commits into from
Jun 24, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private DeviceConfigurationsController CreateDeviceConfigurationsController()
public async Task GetConfigurationsStateUnderTestExpectedBehavior()
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();
_ = this.mockConfigService.Setup(c => c.GetDevicesConfigurations())
.ReturnsAsync(new List<Configuration>
{
Expand All @@ -75,7 +75,7 @@ public async Task GetConfigurationsStateUnderTestExpectedBehavior()
public async Task GetConfigurationStateUnderTestExpectedBehavior()
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();
var configurationId = Guid.NewGuid().ToString();
var modelId = Guid.NewGuid().ToString();

Expand Down Expand Up @@ -115,7 +115,7 @@ public async Task GetConfigurationStateUnderTestExpectedBehavior()
public async Task GetConfigurationShouldReturnProperlyTheProperties()
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();
var configurationId = Guid.NewGuid().ToString();
var modelId = Guid.NewGuid().ToString();

Expand Down Expand Up @@ -165,7 +165,7 @@ public async Task GetConfigurationShouldReturnProperlyTheProperties()
public async Task WhenTargetConditionMalFormedShouldReturnBadRequest(string targetCondition, string errorMessage)
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();
var configurationId = Guid.NewGuid().ToString();

_ = this.mockConfigService.Setup(c => c.GetConfigItem(configurationId))
Expand Down Expand Up @@ -193,7 +193,7 @@ public async Task WhenTargetConditionMalFormedShouldReturnBadRequest(string targ
public async Task CreateConfigStateUnderTestExpectedBehavior()
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();

var deviceConfig = new DeviceConfig
{
Expand All @@ -212,7 +212,7 @@ public async Task CreateConfigStateUnderTestExpectedBehavior()
var mockResponse = this.mockRepository.Create<Response>();

_ = this.mockDeviceModelPropertiesTableClient.Setup(c => c.Query<DeviceModelProperty>(
It.Is<string>(x => x == $"PartitionKey eq '{ deviceConfig.ModelId }'"),
It.Is<string>(x => x == $"PartitionKey eq '{deviceConfig.ModelId}'"),
It.IsAny<int?>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<CancellationToken>()))
Expand Down Expand Up @@ -242,7 +242,7 @@ public async Task CreateConfigStateUnderTestExpectedBehavior()
public async Task CreateConfigShouldThrowInternalServerErrorExceptionOnGettingDeviceModelProperties()
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();

var deviceConfig = new DeviceConfig
{
Expand Down Expand Up @@ -272,7 +272,7 @@ public async Task CreateConfigShouldThrowInternalServerErrorExceptionOnGettingDe
public async Task UpdateConfigStateUnderTestExpectedBehavior()
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();

var deviceConfig = new DeviceConfig
{
Expand All @@ -291,7 +291,7 @@ public async Task UpdateConfigStateUnderTestExpectedBehavior()
var mockResponse = this.mockRepository.Create<Response>();

_ = this.mockDeviceModelPropertiesTableClient.Setup(c => c.Query<DeviceModelProperty>(
It.Is<string>(x => x == $"PartitionKey eq '{ deviceConfig.ModelId }'"),
It.Is<string>(x => x == $"PartitionKey eq '{deviceConfig.ModelId}'"),
It.IsAny<int?>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<CancellationToken>()))
Expand Down Expand Up @@ -321,7 +321,7 @@ public async Task UpdateConfigStateUnderTestExpectedBehavior()
public async Task UpdateConfigShouldThrowInternalServerErrorExceptionOnGettingDeviceModelProperties()
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();

var deviceConfig = new DeviceConfig
{
Expand Down Expand Up @@ -351,7 +351,7 @@ public async Task UpdateConfigShouldThrowInternalServerErrorExceptionOnGettingDe
public async Task DeleteConfigStateUnderTestExpectedBehavior()
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();
var deviceConfigId = Guid.NewGuid().ToString();

_ = this.mockConfigService.Setup(c =>
Expand All @@ -370,7 +370,7 @@ await deviceConfigurationsController.DeleteConfig(
public async Task GetConfigurationMetricsStateUnderTestExpectedBehavior()
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();

var deviceConfig = new DeviceConfig
{
Expand Down Expand Up @@ -420,7 +420,7 @@ public async Task GetConfigurationMetricsStateUnderTestExpectedBehavior()
public async Task UpdateConfigShouldUpdatePropertyInValueType(DevicePropertyType propertyType, string propertyValue, object expected)
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();
var propertyName = Guid.NewGuid().ToString();

var deviceConfig = new DeviceConfig
Expand All @@ -446,7 +446,7 @@ public async Task UpdateConfigShouldUpdatePropertyInValueType(DevicePropertyType
var mockResponse = this.mockRepository.Create<Response>();

_ = this.mockDeviceModelPropertiesTableClient.Setup(c => c.Query<DeviceModelProperty>(
It.Is<string>(x => x == $"PartitionKey eq '{ deviceConfig.ModelId }'"),
It.Is<string>(x => x == $"PartitionKey eq '{deviceConfig.ModelId}'"),
It.IsAny<int?>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<CancellationToken>()))
Expand Down Expand Up @@ -491,7 +491,7 @@ public async Task UpdateConfigShouldUpdatePropertyInValueType(DevicePropertyType
public async Task CreateConfigShouldUpdatePropertyInValueType(DevicePropertyType propertyType, string propertyValue, object expected)
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();
var propertyName = Guid.NewGuid().ToString();

var deviceConfig = new DeviceConfig
Expand All @@ -517,7 +517,7 @@ public async Task CreateConfigShouldUpdatePropertyInValueType(DevicePropertyType
var mockResponse = this.mockRepository.Create<Response>();

_ = this.mockDeviceModelPropertiesTableClient.Setup(c => c.Query<DeviceModelProperty>(
It.Is<string>(x => x == $"PartitionKey eq '{ deviceConfig.ModelId }'"),
It.Is<string>(x => x == $"PartitionKey eq '{deviceConfig.ModelId}'"),
It.IsAny<int?>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<CancellationToken>()))
Expand Down Expand Up @@ -552,7 +552,7 @@ public async Task CreateConfigShouldUpdatePropertyInValueType(DevicePropertyType
public async Task WhenPropertyNotPresentInModelUpdateConfigShouldNotUpdateTheProperty()
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();
var propertyName = Guid.NewGuid().ToString();

var deviceConfig = new DeviceConfig
Expand All @@ -579,7 +579,7 @@ public async Task WhenPropertyNotPresentInModelUpdateConfigShouldNotUpdateThePro
var mockResponse = this.mockRepository.Create<Response>();

_ = this.mockDeviceModelPropertiesTableClient.Setup(c => c.Query<DeviceModelProperty>(
It.Is<string>(x => x == $"PartitionKey eq '{ deviceConfig.ModelId }'"),
It.Is<string>(x => x == $"PartitionKey eq '{deviceConfig.ModelId}'"),
It.IsAny<int?>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<CancellationToken>()))
Expand Down Expand Up @@ -615,7 +615,7 @@ public async Task WhenPropertyNotPresentInModelUpdateConfigShouldNotUpdateThePro
public async Task WhenPropertyNotPresentInModelCreateConfigShouldNotUpdateTheProperty()
{
// Arrange
var deviceConfigurationsController = this.CreateDeviceConfigurationsController();
var deviceConfigurationsController = CreateDeviceConfigurationsController();
var propertyName = Guid.NewGuid().ToString();

var deviceConfig = new DeviceConfig
Expand All @@ -642,7 +642,7 @@ public async Task WhenPropertyNotPresentInModelCreateConfigShouldNotUpdateThePro
var mockResponse = this.mockRepository.Create<Response>();

_ = this.mockDeviceModelPropertiesTableClient.Setup(c => c.Query<DeviceModelProperty>(
It.Is<string>(x => x == $"PartitionKey eq '{ deviceConfig.ModelId }'"),
It.Is<string>(x => x == $"PartitionKey eq '{deviceConfig.ModelId}'"),
It.IsAny<int?>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<CancellationToken>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task PostShouldCreateCommand()
.ReturnsAsync(mockResponse.Object);

_ = this.mockCommandsTableClient.Setup(c => c.Query<TableEntity>(
It.Is<string>(x => x == $"PartitionKey eq '{ entity.RowKey }'"),
It.Is<string>(x => x == $"PartitionKey eq '{entity.RowKey}'"),
It.IsAny<int?>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<CancellationToken>()))
Expand Down Expand Up @@ -323,7 +323,7 @@ public async Task GetShouldReturnDeviceModelCommands()
var mockResponse = this.mockRepository.Create<Response>();

_ = this.mockCommandsTableClient.Setup(c => c.Query<TableEntity>(
It.Is<string>(x => x == $"PartitionKey eq '{ deviceModelId }'"),
It.Is<string>(x => x == $"PartitionKey eq '{deviceModelId}'"),
It.IsAny<int?>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<CancellationToken>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task GetPropertiesStateUnderTestExpectedBehavior()
var mockResponse = this.mockRepository.Create<Response>();

_ = this.mockDeviceModelPropertiesTableClient.Setup(c => c.QueryAsync<DeviceModelProperty>(
It.Is<string>(x => x == $"PartitionKey eq '{ entity.RowKey }'"),
It.Is<string>(x => x == $"PartitionKey eq '{entity.RowKey}'"),
It.IsAny<int?>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<CancellationToken>()))
Expand Down Expand Up @@ -184,7 +184,7 @@ public async Task SetPropertiesStateUnderTestExpectedBehavior()
};

_ = this.mockDeviceModelPropertiesTableClient.Setup(c => c.QueryAsync<DeviceModelProperty>(
It.Is<string>(x => x == $"PartitionKey eq '{ entity.RowKey }'"),
It.Is<string>(x => x == $"PartitionKey eq '{entity.RowKey}'"),
It.IsAny<int?>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<CancellationToken>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void SettingsShouldGetValueFromAppSettings(string configKey, string confi
{
// Arrange
var expected = Guid.NewGuid().ToString();
var configHandler = this.CreateDevelopmentConfigHandler();
var configHandler = CreateDevelopmentConfigHandler();

_ = this.mockConfiguration.SetupGet(c => c[It.Is<string>(x => x == configKey)])
.Returns(expected);
Expand All @@ -72,7 +72,7 @@ public void SettingsShouldGetBoolFromAppSettings(string configKey, string config
{
// Arrange
var expected = false;
var productionConfigHandler = this.CreateDevelopmentConfigHandler();
var productionConfigHandler = CreateDevelopmentConfigHandler();

_ = this.mockConfiguration.SetupGet(c => c[It.Is<string>(x => x == configKey)])
.Returns(Convert.ToString(expected, CultureInfo.InvariantCulture));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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
namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.Configurations
{
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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
namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.Configurations
{
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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
namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.DeviceConfigurations
{
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.LoRaWan.Concentrator
namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.DeviceConfigurations
{
using System;
using System.Net.Http;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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
namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.DeviceConfigurations
{
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.DeviceConfigurations
using System;
using System.Collections.Generic;
using System.Net.Http;
using AzureIoTHub.Portal.Server.Tests.Unit.Extensions;
using AzureIoTHub.Portal.Server.Tests.Unit.Extensions;
using Bunit;
using Bunit.TestDoubles;
using Client.Exceptions;
Expand Down Expand Up @@ -113,7 +113,7 @@ public void ClickToItemShouldRedirectToConfigurationDetailsPage()
cut.WaitForAssertion(() => cut.Find("table tbody tr").Click());

// Assert
cut.WaitForAssertion(() => this.TestContext.Services.GetService<FakeNavigationManager>().Uri.Should().EndWith($"/device-configurations/{configurationId}"));
cut.WaitForAssertion(() => TestContext.Services.GetService<FakeNavigationManager>().Uri.Should().EndWith($"/device-configurations/{configurationId}"));
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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
namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.Devices
{
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -53,6 +53,7 @@ public void SetUp()
_ = this.testContext.JSInterop.SetupVoid("Blazor._internal.InputFile.init", _ => true);
_ = this.testContext.JSInterop.Setup<BoundingClientRect>("mudElementRef.getBoundingClientRect", _ => true);
_ = this.testContext.JSInterop.Setup<IEnumerable<BoundingClientRect>>("mudResizeObserver.connect", _ => true);
_ = this.testContext.JSInterop.SetupVoid("mudElementRef.saveFocus", _ => true);

this.mockHttpClient.AutoFlush = true;
}
Expand Down Expand Up @@ -86,8 +87,8 @@ public async Task ConnectionStringDialogMustBeRenderedOnShow()
await cut.InvokeAsync(() => service?.Show<ConnectionStringDialog>(string.Empty, parameters));

// Assert
_ = cut.Find("div.mud-dialog-container").Should().NotBeNull();
this.mockHttpClient.VerifyNoOutstandingExpectation();
cut.WaitForAssertion(() => cut.Find("div.mud-dialog-container").Should().NotBeNull());
cut.WaitForAssertion(() => this.mockHttpClient.VerifyNoOutstandingExpectation());
}

[Test]
Expand Down Expand Up @@ -117,8 +118,8 @@ public async Task OnInitializedAsyncShouldProcessProblemDetailsExceptionWhenIssu
var result = await dialogReference.Result;

// Assert
_ = result.Cancelled.Should().BeFalse();
this.mockHttpClient.VerifyNoOutstandingExpectation();
cut.WaitForAssertion(() => result.Cancelled.Should().BeFalse());
cut.WaitForAssertion(() => this.mockHttpClient.VerifyNoOutstandingExpectation());
}

public void Dispose()
Expand Down
Loading