diff --git a/src/AzureIoTHub.Portal.Server.Tests/Services/ConfigsServicesTests.cs b/src/AzureIoTHub.Portal.Server.Tests/Services/ConfigsServicesTests.cs new file mode 100644 index 000000000..0394674a7 --- /dev/null +++ b/src/AzureIoTHub.Portal.Server.Tests/Services/ConfigsServicesTests.cs @@ -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 mockRegistryManager; + + [SetUp] + public void SetUp() + { + this.mockRepository = new MockRepository(MockBehavior.Strict); + + this.mockRegistryManager = this.mockRepository.Create(); + } + + 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(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(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(); + } + } +} diff --git a/src/AzureIoTHub.Portal.Server.Tests/UnitTest1.cs b/src/AzureIoTHub.Portal.Server.Tests/UnitTest1.cs deleted file mode 100644 index 1579d9823..000000000 --- a/src/AzureIoTHub.Portal.Server.Tests/UnitTest1.cs +++ /dev/null @@ -1,18 +0,0 @@ -using NUnit.Framework; - -namespace AzureIoTHub.Portal.Server.Tests -{ - public class Tests - { - [SetUp] - public void Setup() - { - } - - [Test] - public void Test1() - { - Assert.Pass(); - } - } -} \ No newline at end of file