1+ using Coreflux . API ;
2+ using CorefluxCSharpAPI . API . Services . Interfaces ;
3+ using Moq ;
4+ using System ;
5+ using Xunit ;
6+
7+ namespace CorefluxCSharpAPI . API . Tests
8+ {
9+ public class Client_StartInstance_Tests
10+ {
11+ [ Fact ( DisplayName = "Start Instance. Instance not found" ) ]
12+ [ Trait ( "StartInstance" , "Test the operations of start/stop and obtain instances" ) ]
13+ public void InstanceNotFound ( )
14+ {
15+ // Act
16+ var communicationServiceMock = new Mock < ICommunicationService > ( ) ;
17+ communicationServiceMock . Setup ( x => x . GetInformation ( It . IsAny < string > ( ) ) ) . Returns ( string . Empty ) ;
18+
19+ // Arrange
20+ Client client = new Client ( "localhost" , communicationServiceMock . Object ) ;
21+ bool state = client . StartInstance ( It . IsAny < string > ( ) ) ;
22+
23+ // Assert
24+ Assert . False ( state ) ;
25+ }
26+
27+ [ Fact ( DisplayName = "Start Instance. Instance failed to start found" ) ]
28+ [ Trait ( "StartInstance" , "Test the operations of start/stop and obtain instances" ) ]
29+ public void InstanceFailedToStart ( )
30+ {
31+ // Act
32+ var communicationServiceMock = new Mock < ICommunicationService > ( ) ;
33+ communicationServiceMock . Setup ( x => x . GetInformation ( It . IsAny < string > ( ) ) )
34+ . Returns ( "[{\" app\" :{\" architecture\" :\" win32\" ,\" avaibleSlots\" :2," +
35+ "\" code\" :\" coreflux_broker_full\" ,\" codeParameterName\" :\" InstanceID\" ,\" defaultConfig\" " +
36+ ":[{\" hint\" :null,\" label\" :\" BindtoIP\" ,\" name\" :\" ipBind\" ,\" optional\" :false,\" type\" :{\" Value\" :\" String\" }," +
37+ "\" validatorRegEx\" :\" ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\ \\ .){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$\" ,\" value\" :\" 0.0.0.0\" },{\" hint\" :\" Thisfieldonlyallownumbersbetween(1-65535).\" " +
38+ ",\" label\" :\" TCPPort\" ,\" name\" :\" TcpPort\" ,\" optional\" :false,\" type\" :{\" Value\" :\" Int\" }," +
39+ "\" validatorRegEx\" :\" ^(?:[1-9]|[1-5]?[0-9]{2,4}|6[1-4][0-9]{3}|65[1-4][0-9]{2}|655[1-2][0-9]|6553[1-5])$\" ," +
40+ "\" value\" :\" 1883\" },{\" hint\" :null,\" label\" :\" Clienttimeout(ms)\" ,\" name\" :\" ClientTimeoutMS\" ," +
41+ "\" optional\" :false,\" type\" :{\" Value\" :\" Int\" },\" validatorRegEx\" :\" ^\\ \\ d+$\" ,\" value\" :\" 5000\" }," +
42+ "{\" hint\" :\" Messageswillbequeuedifclientdisconnects.\" ,\" label\" :\" Persistentsessions\" ,\" name\" :\" PersistentSessions\" ,\" optional\" :false,\" type\" :{\" Value\" :\" Bool\" }" +
43+ ",\" validatorRegEx\" :\" ^(?:true)|(?:false)$\" ,\" value\" :\" True\" },{\" hint\" :\" Numberofdisconnectionstoremember.\" ,\" label\" :\" Connectionbacklog\" ,\" name\" :\" ConnectionBacklog\" ,\" optional\" :false,\" type\" :{\" Value\" :\" Int\" }" +
44+ ",\" validatorRegEx\" :\" ^\\ \\ d+$\" ,\" value\" :\" 1000\" },{\" hint\" :\" Numberofmessagestobequeued.\" ,\" label\" :\" Maximumpendingmessages\" ,\" name\" :\" MaxPendingMessages\" ,\" optional\" :false,\" type\" :{\" Value\" :\" Int\" }" +
45+ ",\" validatorRegEx\" :\" ^\\ \\ d+$\" ,\" value\" :\" 5000\" },{\" hint\" :null,\" label\" :\" InstanceID\" ,\" name\" :\" InstanceID\" ,\" optional\" :true,\" type\" :{\" Value\" :\" String\" },\" validatorRegEx\" :\" ^(?:\\ \\ w|\\ \\ d)+$\" ,\" value\" :null}]" +
46+ ",\" description\" :\" ThisappallowyoutocentralizeallyourdataintoaMQTTserver.\" ,\" executableFileName\" :\" CorefluxMQTTBroker.exe\" ,\" images\" :[{\" Key\" :\" square.md\" ,\" Value\" :\" square.md.png\" }" +
47+ ",{\" Key\" :\" logo.md\" ,\" Value\" :\" icon.md.png\" }],\" key\" :\" coreflux_broker\" ,\" name\" :\" MQTTBroker\" ,\" official\" :true,\" order\" :0,\" priority\" :2147483647,\" socialMedia\" :[{\" Key\" :\" en-US\" ,\" Value\" :[{\" Key\" :\" manual\" ,\" Value\" :\" https:\\ /\\ /medium.com\\ /coreflux-blog\\ /mqtt-broker-asset-coreflux-511acecac3f7\" }" +
48+ ",{\" Key\" :\" medium\" ,\" Value\" :\" https:\\ /\\ /medium.com\\ /coreflux-blog\\ /practical-iot-fun-ctionality-at-the-office-with-coreflux-mqtt-unity-59982d90f6fa\" },{\" Key\" :\" topup\" ,\" Value\" :\" https:\\ /\\ /buy.stripe.com\\ /eVacOt4pI6t4eTC004\" },{\" Key\" :\" youtube\" ,\" Value\" :\" https:\\ /\\ /www.youtube.com\\ /watch?v=5eVhCcnbMMs\" }]}" +
49+ ",{\" Key\" :\" pt-PT\" ,\" Value\" :[{\" Key\" :\" manual\" ,\" Value\" :\" https:\\ /\\ /coreflux.org\\ /\" },{\" Key\" :\" medium\" ,\" Value\" :\" https:\\ /\\ /medium.com\\ /coreflux-blog\\ /mqtt-broker-asset-coreflux-511acecac3f7\" },{\" Key\" :\" topup\" ,\" Value\" :\" https:\\ /\\ /buy.stripe.com\\ /eVacOt4pI6t4eTC004\" }" +
50+ ",{\" Key\" :\" youtube\" ,\" Value\" :\" https:\\ /\\ /www.youtube.com\\ /watch?v=5eVhCcnbMMs\" }]}],\" usedSlots\" :2},\" code\" :\" 9OPd\" ,\" companyID\" :\" -NAiOHHU3uSq_CauJyf3\" ,\" modelTrial\" :false,\" name\" :\" Coreflux.MQTT.Broker_9OPd\" ,\" status\" :1}]" ) ;
51+
52+ communicationServiceMock . Setup ( x => x . PostInformation ( It . IsAny < string > ( ) ) ) . Returns ( "{\" errorMessages\" :[\" Error!\" ],\" errors\" :{}}" ) ;
53+
54+ // Arrange
55+ Client client = new Client ( "localhost" , communicationServiceMock . Object ) ;
56+
57+ // Assert
58+ Assert . Throws < Exception > ( ( ) => client . StartInstance ( "9OPd" ) ) ;
59+ }
60+
61+
62+ [ Fact ( DisplayName = "Start Instance. Instance found" ) ]
63+ [ Trait ( "StartInstance" , "Test the operations of start/stop and obtain instances" ) ]
64+ public void InstanceStarted ( )
65+ {
66+ // Act
67+ var communicationServiceMock = new Mock < ICommunicationService > ( ) ;
68+ communicationServiceMock . Setup ( x => x . GetInformation ( It . IsAny < string > ( ) ) )
69+ . Returns ( "[{\" app\" :{\" architecture\" :\" win32\" ,\" avaibleSlots\" :2," +
70+ "\" code\" :\" coreflux_broker_full\" ,\" codeParameterName\" :\" InstanceID\" ,\" defaultConfig\" " +
71+ ":[{\" hint\" :null,\" label\" :\" BindtoIP\" ,\" name\" :\" ipBind\" ,\" optional\" :false,\" type\" :{\" Value\" :\" String\" }," +
72+ "\" validatorRegEx\" :\" ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\ \\ .){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$\" ,\" value\" :\" 0.0.0.0\" },{\" hint\" :\" Thisfieldonlyallownumbersbetween(1-65535).\" " +
73+ ",\" label\" :\" TCPPort\" ,\" name\" :\" TcpPort\" ,\" optional\" :false,\" type\" :{\" Value\" :\" Int\" }," +
74+ "\" validatorRegEx\" :\" ^(?:[1-9]|[1-5]?[0-9]{2,4}|6[1-4][0-9]{3}|65[1-4][0-9]{2}|655[1-2][0-9]|6553[1-5])$\" ," +
75+ "\" value\" :\" 1883\" },{\" hint\" :null,\" label\" :\" Clienttimeout(ms)\" ,\" name\" :\" ClientTimeoutMS\" ," +
76+ "\" optional\" :false,\" type\" :{\" Value\" :\" Int\" },\" validatorRegEx\" :\" ^\\ \\ d+$\" ,\" value\" :\" 5000\" }," +
77+ "{\" hint\" :\" Messageswillbequeuedifclientdisconnects.\" ,\" label\" :\" Persistentsessions\" ,\" name\" :\" PersistentSessions\" ,\" optional\" :false,\" type\" :{\" Value\" :\" Bool\" }" +
78+ ",\" validatorRegEx\" :\" ^(?:true)|(?:false)$\" ,\" value\" :\" True\" },{\" hint\" :\" Numberofdisconnectionstoremember.\" ,\" label\" :\" Connectionbacklog\" ,\" name\" :\" ConnectionBacklog\" ,\" optional\" :false,\" type\" :{\" Value\" :\" Int\" }" +
79+ ",\" validatorRegEx\" :\" ^\\ \\ d+$\" ,\" value\" :\" 1000\" },{\" hint\" :\" Numberofmessagestobequeued.\" ,\" label\" :\" Maximumpendingmessages\" ,\" name\" :\" MaxPendingMessages\" ,\" optional\" :false,\" type\" :{\" Value\" :\" Int\" }" +
80+ ",\" validatorRegEx\" :\" ^\\ \\ d+$\" ,\" value\" :\" 5000\" },{\" hint\" :null,\" label\" :\" InstanceID\" ,\" name\" :\" InstanceID\" ,\" optional\" :true,\" type\" :{\" Value\" :\" String\" },\" validatorRegEx\" :\" ^(?:\\ \\ w|\\ \\ d)+$\" ,\" value\" :null}]" +
81+ ",\" description\" :\" ThisappallowyoutocentralizeallyourdataintoaMQTTserver.\" ,\" executableFileName\" :\" CorefluxMQTTBroker.exe\" ,\" images\" :[{\" Key\" :\" square.md\" ,\" Value\" :\" square.md.png\" }" +
82+ ",{\" Key\" :\" logo.md\" ,\" Value\" :\" icon.md.png\" }],\" key\" :\" coreflux_broker\" ,\" name\" :\" MQTTBroker\" ,\" official\" :true,\" order\" :0,\" priority\" :2147483647,\" socialMedia\" :[{\" Key\" :\" en-US\" ,\" Value\" :[{\" Key\" :\" manual\" ,\" Value\" :\" https:\\ /\\ /medium.com\\ /coreflux-blog\\ /mqtt-broker-asset-coreflux-511acecac3f7\" }" +
83+ ",{\" Key\" :\" medium\" ,\" Value\" :\" https:\\ /\\ /medium.com\\ /coreflux-blog\\ /practical-iot-fun-ctionality-at-the-office-with-coreflux-mqtt-unity-59982d90f6fa\" },{\" Key\" :\" topup\" ,\" Value\" :\" https:\\ /\\ /buy.stripe.com\\ /eVacOt4pI6t4eTC004\" },{\" Key\" :\" youtube\" ,\" Value\" :\" https:\\ /\\ /www.youtube.com\\ /watch?v=5eVhCcnbMMs\" }]}" +
84+ ",{\" Key\" :\" pt-PT\" ,\" Value\" :[{\" Key\" :\" manual\" ,\" Value\" :\" https:\\ /\\ /coreflux.org\\ /\" },{\" Key\" :\" medium\" ,\" Value\" :\" https:\\ /\\ /medium.com\\ /coreflux-blog\\ /mqtt-broker-asset-coreflux-511acecac3f7\" },{\" Key\" :\" topup\" ,\" Value\" :\" https:\\ /\\ /buy.stripe.com\\ /eVacOt4pI6t4eTC004\" }" +
85+ ",{\" Key\" :\" youtube\" ,\" Value\" :\" https:\\ /\\ /www.youtube.com\\ /watch?v=5eVhCcnbMMs\" }]}],\" usedSlots\" :2},\" code\" :\" 9OPd\" ,\" companyID\" :\" -NAiOHHU3uSq_CauJyf3\" ,\" modelTrial\" :false,\" name\" :\" Coreflux.MQTT.Broker_9OPd\" ,\" status\" :1}]" ) ;
86+
87+ communicationServiceMock . Setup ( x => x . PostInformation ( It . IsAny < string > ( ) ) ) . Returns ( string . Empty ) ;
88+
89+ // Arrange
90+ Client client = new Client ( "localhost" , communicationServiceMock . Object ) ;
91+ bool state = client . StartInstance ( "9OPd" ) ;
92+
93+ // Assert
94+ Assert . True ( state ) ;
95+ }
96+ }
97+ }
0 commit comments