From 76578838b0a63ae6827bf5e597fdbfa38370ee6f Mon Sep 17 00:00:00 2001 From: "Beaugrand, Kevin" Date: Wed, 9 Feb 2022 10:50:58 +0100 Subject: [PATCH] Add unit tests --- .../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]