Skip to content

Commit

Permalink
Add config service unit tests (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand authored Feb 9, 2022
1 parent 27bb934 commit 8481a9e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using AzureIoTHub.Portal.Server.Services;
using Microsoft.Azure.Devices;
using Moq;
using NUnit.Framework;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace AzureIoTHub.Portal.Server.Tests.Services
{
[TestFixture]
public class ConfigsServicesTests
{
private MockRepository mockRepository;

private Mock<RegistryManager> mockRegistryManager;

[SetUp]
public void SetUp()
{
this.mockRepository = new MockRepository(MockBehavior.Strict);

this.mockRegistryManager = this.mockRepository.Create<RegistryManager>();
}

private ConfigsServices CreateConfigsServices()
{
return new ConfigsServices(this.mockRegistryManager.Object);
}

[Test]
public async Task GetAllConfigs_StateUnderTest_ExpectedBehavior()
{
// Arrange
var configsServices = this.CreateConfigsServices();
this.mockRegistryManager.Setup(c => c.GetConfigurationsAsync(It.Is<int>(x => x == 0)))
.ReturnsAsync(new[]
{
new Configuration("aaa"),
new Configuration("bbb")
});

// Act
var result = await configsServices.GetAllConfigs();

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(2, result.Count());
Assert.AreEqual("aaa", result.First().Id);
this.mockRepository.VerifyAll();
}

[Test]
public async Task GetConfigItem_StateUnderTest_ExpectedBehavior()
{
// Arrange
var configsServices = this.CreateConfigsServices();
string id = "aaa";
this.mockRegistryManager.Setup(c => c.GetConfigurationAsync(It.Is<string>(x => x == id)))
.ReturnsAsync(new Configuration(id));

// Act
var result = await configsServices.GetConfigItem(id);

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(id, result.Id);
this.mockRepository.VerifyAll();
}
}
}
18 changes: 0 additions & 18 deletions src/AzureIoTHub.Portal.Server.Tests/UnitTest1.cs

This file was deleted.

0 comments on commit 8481a9e

Please sign in to comment.