Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand committed Feb 9, 2022
1 parent 6b677ce commit 7657883
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(x => x == gateway.DeviceId),
It.Is<bool>(x => x),
It.Is<Twin>(x => x.DeviceId == gateway.DeviceId),
It.Is<DeviceStatus>(x => x == DeviceStatus.Enabled)))
.ReturnsAsync(mockResult);

this.mockLogger.Setup(x => x.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<It.IsAnyType>(), It.IsAny<Exception>(), It.IsAny<Func<It.IsAnyType, Exception, string>>()));

// Act
var result = await gatewaysController.CreateGatewayAsync(gateway);

// Assert
Assert.IsNotNull(result);
Assert.IsAssignableFrom<OkObjectResult>(result);
var okObjectResult = result as ObjectResult;
Assert.IsNotNull(okObjectResult);
Assert.AreEqual(200, okObjectResult.StatusCode);
Assert.IsNotNull(okObjectResult.Value);
Assert.IsAssignableFrom<BulkRegistryOperationResult>(okObjectResult.Value);
Assert.AreEqual(mockResult, okObjectResult.Value);
}

[Test]
Expand Down

0 comments on commit 7657883

Please sign in to comment.