Skip to content

Commit e5e3231

Browse files
committed
Add tests for ConfigurationFactory
1 parent 5f7c2c1 commit e5e3231

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using AutoFixture.Xunit2;
2+
using FluentAssertions;
3+
using Moq;
4+
using RealTimeWeatherMonitoringApp.Infrastructure.Configuration;
5+
using RealTimeWeatherMonitoringApp.Infrastructure.Configuration.Condition;
6+
using RealTimeWeatherMonitoringApp.Infrastructure.Factory;
7+
using RealTimeWeatherMonitoringApp.Infrastructure.Interfaces;
8+
using RealTimeWeatherMonitoringTest.Common;
9+
using Xunit;
10+
11+
namespace RealTimeWeatherMonitoringTest.Infrastructure.Factory;
12+
13+
public class ConfigurationFactoryShould
14+
{
15+
private static string GetTestJsonConfiguration() =>
16+
"""
17+
{
18+
"TestBot": {
19+
"enabled": true,
20+
"conditions": [
21+
{
22+
"type": "humidity",
23+
"operator": "greaterThan",
24+
"value": 50
25+
}
26+
],
27+
"message": "Bot Message"
28+
}
29+
}
30+
""";
31+
32+
private static BotConfiguration GetTestBotConfiguration() => new(
33+
Name: "TestBot",
34+
Enabled: true,
35+
Message: "Bot Message",
36+
Conditions:
37+
[
38+
new ConditionConfiguration(
39+
Type: ConditionType.Humidity,
40+
Operator: ConditionOperator.GreaterThan,
41+
Value: 50)
42+
]);
43+
44+
[Theory, AutoMoqData]
45+
public void CreateBotConfigurations_NoFileReadingOnConstruction(
46+
[Frozen] Mock<IFileReader> fileReaderMock,
47+
ConfigurationFactory configurationFactory)
48+
{
49+
configurationFactory.Should().NotBeNull();
50+
fileReaderMock.VerifyNoOtherCalls();
51+
}
52+
53+
[Theory, AutoMoqData]
54+
public void CreateBotConfigurations_WhenInvoked_ReturnConfigurations(
55+
string configurationFilepath,
56+
Mock<IFileReader> fileReaderMock)
57+
{
58+
fileReaderMock
59+
.Setup(r => r.ReadAllText(configurationFilepath))
60+
.Returns(GetTestJsonConfiguration());
61+
62+
var configurationFactory = new ConfigurationFactory(configurationFilepath, fileReaderMock.Object);
63+
var configurations = configurationFactory.CreateBotConfigurations().ToList();
64+
65+
fileReaderMock.Verify(r => r.ReadAllText(configurationFilepath), Times.Once);
66+
configurations.Should().ContainSingle();
67+
configurations.First().Should().BeEquivalentTo(GetTestBotConfiguration());
68+
}
69+
}

0 commit comments

Comments
 (0)