1+ using AutoFixture . Xunit2 ;
2+ using FluentAssertions ;
3+ using Moq ;
4+ using RealTimeWeatherMonitoringApp . Domain . Interfaces ;
5+ using RealTimeWeatherMonitoringApp . Domain . Models ;
6+ using RealTimeWeatherMonitoringApp . Infrastructure . Configuration ;
7+ using RealTimeWeatherMonitoringApp . Infrastructure . Factory ;
8+ using RealTimeWeatherMonitoringApp . Infrastructure . Interfaces . Factory ;
9+ using RealTimeWeatherMonitoringTest . Common ;
10+ using RealTimeWeatherMonitoringTest . Domain . Models ;
11+ using Xunit ;
12+
13+ namespace RealTimeWeatherMonitoringTest . Infrastructure . Factory ;
14+
15+ public class BotFactoryShould
16+ {
17+ [ Theory , AutoMoqData ]
18+ public void CreateBot_MapConfigurationToBot (
19+ BotConfiguration configuration ,
20+ Mock < IEvaluator < TestData > > evaluatorStub ,
21+ [ Frozen ] Mock < IEvaluatorFactory < TestData > > evaluatorFactoryMock ,
22+ BotFactory < TestData > botFactory )
23+ {
24+ evaluatorFactoryMock
25+ . Setup ( f => f . CreateEvaluator ( It . IsAny < ConditionConfiguration > ( ) ) )
26+ . Returns ( evaluatorStub . Object ) ;
27+
28+ var bot = botFactory . CreateBot ( configuration ) ;
29+
30+ bot . Should ( ) . NotBeNull ( )
31+ . And . Match < Bot < TestData > > ( b =>
32+ b . Name == configuration . Name &&
33+ b . Enabled == configuration . Enabled &&
34+ b . Message == configuration . Message ) ;
35+ }
36+
37+ [ Theory , AutoMoqData ]
38+ public void CreateBot_ComposeAllConditions (
39+ BotConfiguration configuration ,
40+ Mock < IEvaluator < TestData > > evaluatorMock ,
41+ TestData data ,
42+ [ Frozen ] Mock < IEvaluatorFactory < TestData > > evaluatorFactoryMock ,
43+ BotFactory < TestData > botFactory )
44+ {
45+ evaluatorMock . Setup ( e => e . Evaluate ( data ) ) . Returns ( true ) ;
46+ evaluatorFactoryMock
47+ . Setup ( f => f . CreateEvaluator ( It . IsAny < ConditionConfiguration > ( ) ) )
48+ . Returns ( evaluatorMock . Object ) ;
49+
50+ var bot = botFactory . CreateBot ( configuration ) ;
51+ var result = bot . Evaluator . Evaluate ( data ) ;
52+
53+ result . Should ( ) . BeTrue ( ) ;
54+ evaluatorMock . Verify ( e => e . Evaluate ( data ) ,
55+ Times . Exactly ( configuration . Conditions . Count ( ) ) ) ;
56+ }
57+ }
0 commit comments