private void RegisterGateway() { const string MyMsbGatewayUuid = "baf642fa-d3c8-40bf-9c63-780ccd50bf24"; const string MyMsbGatewayName = "C# Sample Gateway"; const string MyMsbGatewayDescription = "Description of my C# sample Gateway"; const string MyMsbGatewayToken = "41da7f7c-a119-4279-b45b-8caad5157016"; const string MyMsbGatewaySubserviceUuid = "b8132e26-1ac9-11eb-adc1-0242ac120002"; const string MyMsbGatewaySubserviceName = "C# Sample Gateway Subservice"; const string MyMsbGatewaySubserviceDescription = "Description of my C# sample Gateway Subservice"; const string MyMsbGatewaySubserviceToken = "bb516bc0-1ac9-11eb-adc1-0242ac120002"; Gateway myMsbGateway = new Gateway(MyMsbGatewayUuid, MyMsbGatewayName, MyMsbGatewayDescription, MyMsbGatewayToken); SmartObject myMsbGatewaySubservice = new SmartObject(MyMsbGatewaySubserviceUuid, MyMsbGatewaySubserviceName, MyMsbGatewaySubserviceDescription, MyMsbGatewaySubserviceToken); myMsbGateway.AddService(myMsbGatewaySubservice); var simpleEvent = new Event("SimpleStringEvent", "Simple String Event", "Description of Simple String Event", typeof(string)); myMsbGatewaySubservice.AddEvent(simpleEvent); MethodInfo methodInfo = this.GetType().GetRuntimeMethod("SampleMsbFunction", new Type[] { typeof(string), typeof(int), typeof(FunctionCallInfo) }); Function sampleMsbFunction = new Function(methodInfo, this); myMsbGatewaySubservice.AddFunction(sampleMsbFunction); this.myMsbClient.RegisterAsync(myMsbGatewaySubservice).Wait(); EventData newEventData = new EventData(simpleEvent); newEventData.Value = "TestString"; this.myMsbClient.PublishAsync(myMsbGatewaySubservice, newEventData).Wait(); }
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); }