1+ using AutoFixture . Xunit2 ;
2+ using FluentAssertions ;
3+ using Moq ;
4+ using RealTimeWeatherMonitoringApp . Domain . Models ;
5+ using RealTimeWeatherMonitoringApp . Infrastructure . Configuration ;
6+ using RealTimeWeatherMonitoringApp . Infrastructure . Interfaces . Factory ;
7+ using RealTimeWeatherMonitoringApp . Infrastructure . Service ;
8+ using RealTimeWeatherMonitoringTest . Common ;
9+ using RealTimeWeatherMonitoringTest . Domain . Models ;
10+ using Xunit ;
11+
12+ namespace RealTimeWeatherMonitoringTest . Infrastructure . Service ;
13+
14+ public class BotInitializerShould
15+ {
16+ [ Theory , AutoMoqData ]
17+ public void InitializeAndGetAllBots_NoInitializationAtConstruction (
18+ [ Frozen ] Mock < IConfigurationFactory > configurationFactoryMock ,
19+ [ Frozen ] Mock < IBotFactory < TestData > > botFactoryMock ,
20+ BotInitializer < TestData > botInitializer )
21+ {
22+ botInitializer . Should ( ) . NotBeNull ( ) ;
23+ configurationFactoryMock . VerifyNoOtherCalls ( ) ;
24+ botFactoryMock . VerifyNoOtherCalls ( ) ;
25+ }
26+
27+ [ Theory , AutoMoqData ]
28+ public void InitializeAndGetAllBots_ReturnAllBots (
29+ List < ( BotConfiguration configuration , Bot < TestData > bot ) > configurationBotPairs ,
30+ [ Frozen ] Mock < IConfigurationFactory > configurationFactoryMock ,
31+ [ Frozen ] Mock < IBotFactory < TestData > > botFactoryMock ,
32+ BotInitializer < TestData > botInitializer )
33+ {
34+ configurationFactoryMock
35+ . Setup ( f => f . CreateBotConfigurations ( ) )
36+ . Returns ( configurationBotPairs . Select ( cb => cb . configuration ) ) ;
37+
38+ foreach ( var cb in configurationBotPairs )
39+ botFactoryMock
40+ . Setup ( f => f . CreateBot ( cb . configuration ) )
41+ . Returns ( cb . bot ) ;
42+
43+ var bots = botInitializer . InitializeAndGetAllBots ( ) ;
44+
45+ bots . Should ( ) . BeEquivalentTo ( configurationBotPairs . Select ( cb => cb . bot ) ) ;
46+ configurationFactoryMock . Verify ( f => f . CreateBotConfigurations ( ) , Times . Once ) ;
47+ foreach ( var cb in configurationBotPairs )
48+ botFactoryMock . Verify ( f => f . CreateBot ( cb . configuration ) , Times . Once ) ;
49+ }
50+ }
0 commit comments