Exemple #1
0
        public async Task CreateRESTSimulator()
        {
            var sim = GetSimulator(TransportTypes.RestHttp);

            sim.Simulator.Value.Anonymous = true;

            var runtime = new SimulatorRuntime(_runtimeServices.Object, _notifPublisher, _adminLogger, sim);

            var msg = new MessageTemplate()
            {
                Transport   = Core.Models.EntityHeader <TransportTypes> .Create(TransportTypes.RestHttp),
                PayloadType = Core.Models.EntityHeader <PaylodTypes> .Create(PaylodTypes.String),
                TextPayload = "abc123",
                EndPoint    = "www.software-logistics.com",
                Port        = 80,
                HttpVerb    = "GET"
            };

            var plan = new MessageTransmissionPlan()
            {
                Message = Core.Models.EntityHeader <MessageTemplate> .Create(msg)
            };


            var result = await runtime.SendAsync(plan);

            AssertSuccess(result);
        }
Exemple #2
0
        public async Task CreatAzureIoTHubSimulator()
        {
            var azIoTAccessKey = Environment.GetEnvironmentVariable("TEST_AZ_IOT_LISTENER_KEY");

            Assert.IsFalse(String.IsNullOrEmpty(azIoTAccessKey), "TEST_AZ_IOT_LISTENER_KEY");

            var azIoTAccountId = Environment.GetEnvironmentVariable("TEST_AZ_IOT_LISTENER_ACCOUNT_ID");

            Assert.IsFalse(String.IsNullOrEmpty(azIoTAccountId), "TEST_AZ_IOT_LISTENER_ACCOUNT_ID");

            var azIoTAccountPolicyName = Environment.GetEnvironmentVariable("TEST_AZ_IOT_LISTENER_POLICY_NAME");

            Assert.IsFalse(String.IsNullOrEmpty(azIoTAccountPolicyName), "TEST_AZ_IOT_LISTENER_POLICY_NAME");

            var ehCompatName = Environment.GetEnvironmentVariable("TEST_AZ_IOT_LISTENER_EH_COMPAT_NAME");

            Assert.IsFalse(String.IsNullOrEmpty(ehCompatName), "TEST_AZ_IOT_LISTENER_EH_COMPAT_NAME");

            var ehCompatEndPoint = Environment.GetEnvironmentVariable("TEST_AZ_IOT_LISTENER_EH_COMPAT_ENDPOINT");

            Assert.IsFalse(String.IsNullOrEmpty(ehCompatEndPoint), "TEST_AZ_IOT_LISTENER_EH_COMPAT_ENDPOINT");

            var azDeviceId = Environment.GetEnvironmentVariable("TEST_AZ_IOT_LISTENER_DEVICEID");

            Assert.IsFalse(String.IsNullOrEmpty(azDeviceId), "Missing TEST_AZ_IOT_LISTENER_DEVICEID");

            var sim = GetSimulator(TransportTypes.AzureIoTHub);

            sim.Simulator.Value.AccessKey     = azIoTAccessKey;
            sim.Simulator.Value.AccessKeyName = azIoTAccountPolicyName;

            var msg = new MessageTemplate()
            {
                Transport   = Core.Models.EntityHeader <TransportTypes> .Create(TransportTypes.RestHttp),
                PayloadType = Core.Models.EntityHeader <PaylodTypes> .Create(PaylodTypes.String),
                TextPayload = "abc123",
                EndPoint    = "www.software-logistics.com",
                Port        = 80,
                HttpVerb    = "GET"
            };


            var plan = new MessageTransmissionPlan()
            {
                Message = Core.Models.EntityHeader <MessageTemplate> .Create(msg)
            };

            var runtime = new SimulatorRuntime(_runtimeServices.Object, _notifPublisher, _adminLogger, sim);

            var result = await runtime.SendAsync(plan);

            AssertSuccess(result);
        }
Exemple #3
0
        public async Task CreateMQTTSimulator()
        {
            var testHostName = Environment.GetEnvironmentVariable("TEST_MQTT_HOST_NAME");

            Assert.IsFalse(String.IsNullOrEmpty(testHostName), "Missing environment variable TEST_MQTT_HOST_NAME");

            var testUserName = Environment.GetEnvironmentVariable("TEST_MQTT_USER_NAME");

            Assert.IsFalse(String.IsNullOrEmpty(testUserName), "Missing environment variable TEST_MQTT_USER_NAME");

            var testPwd = Environment.GetEnvironmentVariable("TEST_MQTT_PASSWORD");

            Assert.IsFalse(String.IsNullOrEmpty(testPwd), "Missing environment variable TEST_MQTT_PASSWORD");

            var sim = GetSimulator(TransportTypes.MQTT);

            sim.Simulator.Value.DefaultEndPoint = testHostName;
            sim.Simulator.Value.DefaultPort     = 1883;
            sim.Simulator.Value.UserName        = testUserName;
            sim.Simulator.Value.Password        = testPwd;

            var msg = new MessageTemplate()
            {
                PayloadType = Core.Models.EntityHeader <PaylodTypes> .Create(PaylodTypes.String),
                Topic       = "sendit",
                TextPayload = "abc123",
            };

            var runtime = new SimulatorRuntime(_runtimeServices.Object, _notifPublisher, _adminLogger, sim);

            var connectResult = await runtime.ConnectAsync();

            AssertSuccess(connectResult);

            var plan = new MessageTransmissionPlan()
            {
                Message = Core.Models.EntityHeader <MessageTemplate> .Create(msg)
            };

            var result = await runtime.SendAsync(plan);

            AssertSuccess(result);

            var disconnectResult = await runtime.DisconnectAsync();

            AssertSuccess(disconnectResult);
        }
Exemple #4
0
        public async Task CreateSBSimulator()
        {
            var sbTrasnamitterKey = Environment.GetEnvironmentVariable("TEST_SB_ACCESSKEY");

            Assert.IsFalse(String.IsNullOrEmpty(sbTrasnamitterKey));

            var accountId = System.Environment.GetEnvironmentVariable("TEST_SB_ACCOUNT_ID");

            Assert.IsFalse(String.IsNullOrEmpty(accountId), "TEST_SB_ACCOUNT_ID");

            var sbPolicyName = System.Environment.GetEnvironmentVariable("TEST_SB_POLICY_NAME");

            Assert.IsFalse(String.IsNullOrEmpty(sbPolicyName), "TEST_SB_POLICY_NAME");

            var sim = GetSimulator(TransportTypes.AzureServiceBus);

            var msg = new MessageTemplate()
            {
                Transport   = Core.Models.EntityHeader <TransportTypes> .Create(TransportTypes.RestHttp),
                PayloadType = Core.Models.EntityHeader <PaylodTypes> .Create(PaylodTypes.String),
                TextPayload = "abc123",
                EndPoint    = "www.software-logistics.com",
                Port        = 80,
                HttpVerb    = "GET"
            };


            var plan = new MessageTransmissionPlan()
            {
                Message = Core.Models.EntityHeader <MessageTemplate> .Create(msg)
            };

            var runtime = new SimulatorRuntime(_runtimeServices.Object, _notifPublisher, _adminLogger, sim);

            var result = await runtime.SendAsync(plan);

            AssertSuccess(result);
        }
        public void GeneratePointArray()
        {
            var runtime = new SimulatorRuntime(new Mock <ISimulatorRuntimeServices>().Object, new Mock <INotificationPublisher>().Object, new Mock <IAdminLogger>().Object, new Admin.Models.SimulatorInstance()
            {
                Simulator = new Core.Models.EntityHeader <Admin.Models.Simulator>()
                {
                    Value = new Admin.Models.Simulator()
                    {
                        SimulatorStates = new List <Admin.Models.SimulatorState>()
                        {
                            new Admin.Models.SimulatorState()
                            {
                                Key = "default", Name = "Default"
                            }
                        }
                    }
                }
            });

            var pointsToGenerate = 300;
            var intervalParam    = 2.0;
            var sensorIndex      = 5;
            var min = 5.5;
            var max = 25.5;

            var messageBytes = runtime.GetMessageBytes(new Admin.Models.MessageTransmissionPlan()
            {
                Message = Core.Models.EntityHeader <Admin.Models.MessageTemplate> .Create(new Admin.Models.MessageTemplate()
                {
                    PayloadType   = Core.Models.EntityHeader <Admin.Models.PaylodTypes> .Create(Admin.Models.PaylodTypes.PointArray),
                    BinaryPayload = $"pointCount={pointsToGenerate};sensorIndex={sensorIndex};interval={intervalParam};min={min};max={max}"
                })
            });

            var payloadSize = messageBytes.Length;

            Console.WriteLine("Payload Size:" + payloadSize);

            using (var ms = new MemoryStream(messageBytes))
                using (var rdr = new BinaryReader(ms))
                {
                    var epochSeconds = rdr.ReadInt32();

                    var timeStamp = epoch.AddSeconds(epochSeconds);
                    Console.WriteLine($"Time Stamp {timeStamp}");

                    var sensorIndexValue = rdr.ReadUInt16();
                    Assert.AreEqual(sensorIndex, sensorIndexValue);
                    Console.WriteLine($"Sensor Index {sensorIndexValue}");

                    var pointCount = rdr.ReadUInt16();
                    Assert.AreEqual(pointsToGenerate, pointCount);
                    Console.WriteLine($"Point Count {pointCount}");

                    var interval = rdr.ReadUInt16() / 10.0;
                    Console.WriteLine($"Interval {interval}");
                    Assert.AreEqual(intervalParam, interval);

                    for (var idx = 0; idx < pointCount; ++idx)
                    {
                        var pointValue = rdr.ReadInt16() / 100.0;
                        Console.WriteLine($"Point {idx} - {pointValue}");

                        Assert.IsTrue(pointValue >= min);
                        Assert.IsTrue(pointValue <= max);
                    }
                }
        }