Skip to content

Commit 3313d12

Browse files
authored
Merge pull request #8 from CorefluxCommunity/api_cleanUp
Api clean up
2 parents 8cf331c + 35913f5 commit 3313d12

19 files changed

+510
-217
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Coreflux.API;
2+
using Coreflux.API.DataModels;
3+
using CorefluxCSharpAPI.API.Services.Interfaces;
4+
using Moq;
5+
using System;
6+
using Xunit;
7+
8+
namespace CorefluxCSharpAPI.API.Tests
9+
{
10+
public class Client_GetInstances_Tests
11+
{
12+
[Fact(DisplayName = "No Instances Available")]
13+
[Trait("GetInstances", "Test the operations of start/stop and obtain instances")]
14+
public void NoInstancesAvailable()
15+
{
16+
// Act
17+
var communicationServiceMock = new Mock<ICommunicationService>();
18+
communicationServiceMock.Setup(x => x.GetInformation(It.IsAny<string>())).Returns(string.Empty);
19+
20+
// Arrange
21+
Client client = new Client("localhost", communicationServiceMock.Object);
22+
AppInstance[] apps = client.GetInstances();
23+
24+
// Assert
25+
Assert.Null(apps);
26+
}
27+
28+
[Fact(DisplayName = "Instances Available")]
29+
[Trait("GetInstances", "Test the operations of start/stop and obtain instances")]
30+
public void InstancesAvailable()
31+
{
32+
// Act
33+
var communicationServiceMock = new Mock<ICommunicationService>();
34+
communicationServiceMock.Setup(x => x.GetInformation(It.IsAny<string>()))
35+
.Returns("[{\"app\":{\"architecture\":\"win32\",\"avaibleSlots\":2," +
36+
"\"code\":\"coreflux_broker_full\",\"codeParameterName\":\"InstanceID\",\"defaultConfig\"" +
37+
":[{\"hint\":null,\"label\":\"BindtoIP\",\"name\":\"ipBind\",\"optional\":false,\"type\":{\"Value\":\"String\"}," +
38+
"\"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).\"" +
39+
",\"label\":\"TCPPort\",\"name\":\"TcpPort\",\"optional\":false,\"type\":{\"Value\":\"Int\"}," +
40+
"\"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])$\"," +
41+
"\"value\":\"1883\"},{\"hint\":null,\"label\":\"Clienttimeout(ms)\",\"name\":\"ClientTimeoutMS\"," +
42+
"\"optional\":false,\"type\":{\"Value\":\"Int\"},\"validatorRegEx\":\"^\\\\d+$\",\"value\":\"5000\"}," +
43+
"{\"hint\":\"Messageswillbequeuedifclientdisconnects.\",\"label\":\"Persistentsessions\",\"name\":\"PersistentSessions\",\"optional\":false,\"type\":{\"Value\":\"Bool\"}" +
44+
",\"validatorRegEx\":\"^(?:true)|(?:false)$\",\"value\":\"True\"},{\"hint\":\"Numberofdisconnectionstoremember.\",\"label\":\"Connectionbacklog\",\"name\":\"ConnectionBacklog\",\"optional\":false,\"type\":{\"Value\":\"Int\"}" +
45+
",\"validatorRegEx\":\"^\\\\d+$\",\"value\":\"1000\"},{\"hint\":\"Numberofmessagestobequeued.\",\"label\":\"Maximumpendingmessages\",\"name\":\"MaxPendingMessages\",\"optional\":false,\"type\":{\"Value\":\"Int\"}" +
46+
",\"validatorRegEx\":\"^\\\\d+$\",\"value\":\"5000\"},{\"hint\":null,\"label\":\"InstanceID\",\"name\":\"InstanceID\",\"optional\":true,\"type\":{\"Value\":\"String\"},\"validatorRegEx\":\"^(?:\\\\w|\\\\d)+$\",\"value\":null}]" +
47+
",\"description\":\"ThisappallowyoutocentralizeallyourdataintoaMQTTserver.\",\"executableFileName\":\"CorefluxMQTTBroker.exe\",\"images\":[{\"Key\":\"square.md\",\"Value\":\"square.md.png\"}" +
48+
",{\"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\"}" +
49+
",{\"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\"}]}" +
50+
",{\"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\"}" +
51+
",{\"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}]");
52+
53+
// Arrange
54+
Client client = new Client("localhost", communicationServiceMock.Object);
55+
AppInstance[] apps = client.GetInstances();
56+
57+
// Assert
58+
Assert.NotEmpty(apps);
59+
Assert.Single(apps);
60+
}
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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

Comments
 (0)