public OnWebsocketMessageReceived(ITestOutputHelper output) : base(output) { this.firstMsbClient = new MsbClient(TestConfiguration.MsbWebsocketInterfaceUrl); this.secondMsbClient = new MsbClient(TestConfiguration.MsbWebsocketInterfaceUrl); this.testSmartObject = new SmartObject("55d9de0f-618e-4051-99c1-76d7f8d92876", "Name", "Description", "0cd8e806-aaf8-4d97-b399-baaa1535c1ae"); }
public MsbClientSample() { this.myMsbClient = new MsbClient(MsbWebsocketInterfaceUrl); // SSL properties this.myMsbClient.AllowSslCertificateChainErrors = true; this.myMsbClient.AllowSslCertificateNameMismatch = true; this.myMsbClient.AllowSslUnstrustedCertificate = true; // Reconnect properties this.myMsbClient.AutoReconnect = true; this.myMsbClient.AutoReconnectIntervalInMilliseconds = 30000; // Sample this.GenerateServiceFromApplicationPropertiesFile(); this.AddEventWithPrimtiveTypeToSelfDescription(); this.AddEventWithComplexTypeToSelfDescription(); this.AddFunctionToSelfDescription(); this.AddFunctionHandlerToSelfDescription(); this.AddConfigurationParametersToSelfDescription(); this.GetConfigurationParmaeters(); this.ConnectClient(); this.RegisterService(); this.PublishEvent(); }
public EventHandling(ITestOutputHelper output) : base(output) { this.mockWebsocketInterface = new MockWebsocketInterface(); this.mockWebsocketInterface.Start(); this.testMsbClient = new MsbClient(this.mockWebsocketInterface.URL); }
public void ConstructorWithSingleArguments_wss() { string expectedMsbUrl = "wss://localhost:8085/"; MsbClient testMsbClient = new MsbClient("localhost", 8085, true, string.Empty); Assert.Equal(expectedMsbUrl, testMsbClient.MsbUrl); Assert.True(testMsbClient.IsSslEnabled); }
public static void AllInOneSample() { const string MsbWebsocketInterfaceUrl = "ws://ws.msb.ipa.cell.vfk.fraunhofer.de"; const string MyMsbSmartObjectUuid = "5607fd6f-50ae-44e7-bd6a-9416fbb25d43"; const string MyMsbSmartObjectName = "C# Sample SmartObject"; const string MyMsbSmartObjectDescription = "Description of my C# sample SmartObject"; const string MyMsbSmartObjectToken = "30e47482-c140-49a9-a79f-6f2396d8e0ab"; const string MyMsbApplicationUuid = "f69067bc-6e8c-4479-a358-8a56f7b7a54d"; const string MyMsbApplicationName = "C# Sample Application"; const string MyMsbApplicationDescription = "Description of my C# sample Application"; const string MyMsbApplicationToken = "5b6b273b-18ff-420b-bbff-5f40288c18f9"; // Create a new MsbClient which allows SmartObjects and Applications to communicate with the MSB MsbClient myMsbClient = new MsbClient(MsbWebsocketInterfaceUrl); // Create the self description of a sample SmartObject and a sample Application SmartObject myMsbSmartObject = new SmartObject(MyMsbSmartObjectUuid, MyMsbSmartObjectName, MyMsbApplicationDescription, MyMsbSmartObjectToken); Application myMsbApplication = new Application(MyMsbApplicationUuid, MyMsbApplicationName, MyMsbSmartObjectDescription, MyMsbApplicationToken); // Add configuration parameters myMsbSmartObject.AddConfigurationParameter("sampleParameter1", new ConfigurationParameterValue(1337)); myMsbSmartObject.AddConfigurationParameter("sampleParameter2", new ConfigurationParameterValue("SampleValue")); // Add events Event simpleEvent = new Event("SimpleEventId", "Name of simple event", "Event with simple data format", typeof(string)); Event flatEvent = new Event("FlatEventId", "Name of flat event", "Event with flat data format", typeof(Events.SimpleEvent)); Event complexEvent = new Event("ComplexEventId", "Name of complex event", "Event with nested data format", typeof(Events.ComplexEvent)); Event sendInts = new Event("SendIntsId", "Send Ints", "sends two integer values", typeof(IntegerValues)); myMsbSmartObject.AddEvent(simpleEvent); myMsbSmartObject.AddEvent(flatEvent); myMsbSmartObject.AddEvent(complexEvent); myMsbSmartObject.AddEvent(sendInts); myMsbApplication.AddEvent(simpleEvent); myMsbApplication.AddEvent(flatEvent); myMsbApplication.AddEvent(complexEvent); myMsbApplication.AddEvent(sendInts); // Add functions SampleFunctionHandler simpleFunctions = new SampleFunctionHandler(); myMsbSmartObject.AddFunctionHandler(simpleFunctions); // Connect to the MSB and register the sample SmartObject and sample Application via the MsbClient myMsbClient.ConnectAsync().Wait(); myMsbClient.RegisterAsync(myMsbSmartObject).Wait(); myMsbClient.RegisterAsync(myMsbApplication).Wait(); // Publish events while (true) { } }
public void ConstructorWithUrl_wss() { string expectedMsbUrl = "wss://localhost:8085"; MsbClient testMsbClient = new MsbClient(expectedMsbUrl); Assert.Equal(expectedMsbUrl, testMsbClient.MsbUrl); Assert.True(testMsbClient.IsSslEnabled); }
public void ConstructorWithUrl_http() { string expectedMsbUrl = "http://localhost:8085"; MsbClient testMsbClient = new MsbClient(expectedMsbUrl); Assert.Equal(expectedMsbUrl.Replace("http://", "ws://"), testMsbClient.MsbUrl); Assert.False(testMsbClient.IsSslEnabled); }
public void IntervalLowerThenMiniumInterval() { int expectedAutoReconnectIntervalInMiliseconds = 10; MsbClient testMsbClient = new MsbClient("http://localhost:8085"); testMsbClient.AutoReconnectIntervalInMilliseconds = expectedAutoReconnectIntervalInMiliseconds; Assert.Equal(MsbClient.MinAutoReconnectIntervalInMilliseconds, testMsbClient.AutoReconnectIntervalInMilliseconds); }
public void CheckProperty() { int expectedHeartbeatIntervalInMilliseconds = 30000; MsbClient testMsbClient = new MsbClient("http://localhost:8085"); testMsbClient.HeatbeatIntervalInMilliseconds = expectedHeartbeatIntervalInMilliseconds; Assert.Equal(expectedHeartbeatIntervalInMilliseconds, testMsbClient.HeatbeatIntervalInMilliseconds); }
public void ConnectionFailed_HostNotAvailable() { MsbClient clientToNowhere = new MsbClient("ws://NotExistingHost:12345"); var raisedEvent = Assert.RaisesAnyAsync <EventArgs>( h => clientToNowhere.ConnectionFailed += h, h => clientToNowhere.ConnectionFailed -= h, () => Task.Run(() => { Assert.False(clientToNowhere.ConnectAsync().Result); })).Result; Assert.IsType <EventArgs>(raisedEvent.Arguments); }
public void NoResponseEventShouldBeSendForFunctionCall() { var mockWebsocketInterface = new MockWebsocketInterface(); mockWebsocketInterface.Start(); var testMsbClient = new MsbClient(mockWebsocketInterface.URL); var testSmartObject = new SmartObject(Guid.NewGuid().ToString(), "Name", "Description", Guid.NewGuid().ToString()); var responseEventWhichShouldNotBeSend = new Event("ResponseEventWhichShouldNotBeSend", string.Empty, string.Empty, new DataFormat()); testSmartObject.AddEvent(responseEventWhichShouldNotBeSend); var testFunction = new Function(this.GetType().GetRuntimeMethod("NoResponseEventShouldBeSendForFunctionCallMsbFunction", new Type[] { typeof(FunctionCallInfo) }), this); testSmartObject.AddFunction(testFunction); Assert.True(testMsbClient.ConnectAsync().Result); Assert.True(testMsbClient.RegisterAsync(testSmartObject).Result); string functionCallJson = $@"{MessageType.FUNCTION_CALLBACK} {{ ""uuid"" : ""{testSmartObject.Uuid}"", ""correlationId"" : ""{Guid.NewGuid().ToString()}"", ""functionId"" : ""NoResponseEventShouldBeSendForFunctionCallMsbFunction"", ""functionParameters"" : {{ }} }}"; try { var raisedEvent = Assert.RaisesAnyAsync <EventArgs>( h => testMsbClient.EventPublished += h, h => testMsbClient.EventPublished -= h, () => Task.Run(() => { mockWebsocketInterface.SendMessageOfType(functionCallJson); Thread.Sleep(100); })).Result; } catch (AggregateException e) { Assert.Contains("No event was raised", e.InnerException.Message); } }
public void PrimtiveFunctionParameterConversion_Integers() { var mockWebsocketInterface = new MockWebsocketInterface(); mockWebsocketInterface.Start(); var testMsbClient = new MsbClient(mockWebsocketInterface.URL); var testSmartObject = new SmartObject(Guid.NewGuid().ToString(), "Name", "Description", Guid.NewGuid().ToString()); var testFunction = new Function(this.GetType().GetRuntimeMethod("TestFunction", new Type[] { typeof(int), typeof(FunctionCallInfo) }), this); testSmartObject.AddFunction(testFunction); Assert.True(testMsbClient.ConnectAsync().Result); Assert.True(testMsbClient.RegisterAsync(testSmartObject).Result); string functionCallJson = $@"{MessageType.FUNCTION_CALLBACK} {{ ""uuid"" : ""{testSmartObject.Uuid}"", ""correlationId"" : ""{Guid.NewGuid().ToString()}"", ""functionId"" : ""TestFunction"", ""functionParameters"" : {{ ""testParameter"" : 1234 }} }}"; mockWebsocketInterface.SendMessageOfType(functionCallJson); var maxPollTries = 10; for (int i = 0; i < maxPollTries; i++) { if (this.testFunctionCallReceived) { break; } else { Thread.Sleep(50); } } Assert.True(this.testFunctionCallReceived); }
public void ConnectToNowhere() { MsbClient testMsbClient = new MsbClient("ws://localhost:50505"); Assert.False(testMsbClient.ConnectAsync().Result); }
public static void AllInOneSample() { const string MsbWebsocketInterfaceUrl = "ws://localhost:8085"; const string MyMsbSmartObjectUuid = "1a17b5e3-3a6a-4e62-97b0-82cfdd1cc818"; const string MyMsbSmartObjectName = "C# Sample SmartObject"; const string MyMsbSmartObjectDescription = "Description of my C# sample SmartObject"; const string MyMsbSmartObjectToken = "30e47482-c140-49a9-a79f-6f2396d8e0ab"; const string MyMsbApplicationUuid = "46441dc8-c3ab-4c93-9632-d1f356afb8ca"; const string MyMsbApplicationName = "C# Sample Application"; const string MyMsbApplicationDescription = "Description of my C# sample Application"; const string MyMsbApplicationToken = "5b6b273b-18ff-420b-bbff-5f40288c18f9"; // Create a new MsbClient which allows SmartObjects and Applications to communicate with the MSB MsbClient myMsbClient = new MsbClient(MsbWebsocketInterfaceUrl); // Create the self description of a sample SmartObject and a sample Application SmartObject myMsbSmartObject = new SmartObject(MyMsbSmartObjectUuid, MyMsbSmartObjectName, MyMsbApplicationDescription, MyMsbSmartObjectToken); Application myMsbApplication = new Application(MyMsbApplicationUuid, MyMsbApplicationName, MyMsbSmartObjectDescription, MyMsbApplicationToken); // Add configuration parameters myMsbSmartObject.AddConfigurationParameter("sampleParameter1", new ConfigurationParameterValue(1337)); myMsbSmartObject.AddConfigurationParameter("sampleParameter2", new ConfigurationParameterValue("SampleValue")); // Add events Event simpleEvent = new Event("SimpleEventId", "Name of simple event", "Event with simple data format", typeof(string)); Event flatEvent = new Event("FlatEventId", "Name of flat event", "Event with flat data format", typeof(Events.SimpleEvent)); Event complexEvent = new Event("ComplexEventId", "Name of complex event", "Event with nested data format", typeof(Events.ComplexEvent)); myMsbSmartObject.AddEvent(simpleEvent); myMsbSmartObject.AddEvent(flatEvent); myMsbSmartObject.AddEvent(complexEvent); myMsbApplication.AddEvent(simpleEvent); myMsbApplication.AddEvent(flatEvent); myMsbApplication.AddEvent(complexEvent); // Add functions SampleFunctionHandler simpleFunctions = new SampleFunctionHandler(); myMsbSmartObject.AddFunctionHandler(simpleFunctions); // Connect to the MSB and register the sample SmartObject and sample Application via the MsbClient myMsbClient.ConnectAsync().Wait(); myMsbClient.RegisterAsync(myMsbSmartObject).Wait(); myMsbClient.RegisterAsync(myMsbApplication).Wait(); // Publish events while (true) { EventData eventData_SimpleEvent = new EventDataBuilder(simpleEvent).SetValue("TestString").Build(); myMsbClient.PublishAsync(myMsbSmartObject, eventData_SimpleEvent).Wait(); EventData eventData_FlatEvent = new EventDataBuilder(flatEvent).SetValue(new Events.SimpleEvent()).Build(); myMsbClient.PublishAsync(myMsbSmartObject, eventData_FlatEvent).Wait(); EventData eventData_ComplexEvent = new EventDataBuilder(complexEvent).SetValue(new Events.ComplexEvent()).Build(); myMsbClient.PublishAsync(myMsbSmartObject, eventData_ComplexEvent).Wait(); Thread.Sleep(3000); } }