From 5f7ba5c0c5c55bc39c37791db466bc66e193643e Mon Sep 17 00:00:00 2001 From: Kevin BEAUGRAND <9513635+kbeaugrand@users.noreply.github.com> Date: Wed, 9 Feb 2022 11:19:25 +0100 Subject: [PATCH] Add unit tests (#221) --- .../Controllers/GatewaysControllerTests.cs | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/AzureIoTHub.Portal.Server.Tests/Controllers/GatewaysControllerTests.cs b/src/AzureIoTHub.Portal.Server.Tests/Controllers/GatewaysControllerTests.cs index 034a4892e..73aab4d32 100644 --- a/src/AzureIoTHub.Portal.Server.Tests/Controllers/GatewaysControllerTests.cs +++ b/src/AzureIoTHub.Portal.Server.Tests/Controllers/GatewaysControllerTests.cs @@ -118,8 +118,39 @@ public async Task GetSymmetricKey_StateUnderTest_ExpectedBehavior() [Test] public async Task CreateGatewayAsync_StateUnderTest_ExpectedBehavior() { - await Task.CompletedTask; - Assert.Inconclusive(); + // Arrange + var gatewaysController = this.CreateGatewaysController(); + var gateway = new Gateway() + { + DeviceId = "aaa", + Type = "lora" + }; + var mockResult = new BulkRegistryOperationResult + { + IsSuccessful = true + }; + + this.mockDeviceService.Setup(c => c.CreateDeviceWithTwin( + It.Is(x => x == gateway.DeviceId), + It.Is(x => x), + It.Is(x => x.DeviceId == gateway.DeviceId), + It.Is(x => x == DeviceStatus.Enabled))) + .ReturnsAsync(mockResult); + + this.mockLogger.Setup(x => x.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())); + + // Act + var result = await gatewaysController.CreateGatewayAsync(gateway); + + // Assert + Assert.IsNotNull(result); + Assert.IsAssignableFrom(result); + var okObjectResult = result as ObjectResult; + Assert.IsNotNull(okObjectResult); + Assert.AreEqual(200, okObjectResult.StatusCode); + Assert.IsNotNull(okObjectResult.Value); + Assert.IsAssignableFrom(okObjectResult.Value); + Assert.AreEqual(mockResult, okObjectResult.Value); } [Test]