-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config service unit tests (#223)
- Loading branch information
1 parent
27bb934
commit 8481a9e
Showing
2 changed files
with
71 additions
and
18 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/AzureIoTHub.Portal.Server.Tests/Services/ConfigsServicesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.