public void IncomingTelemetryDataTest()
        {
            var deviceOperations = Substitute.For <Management.Model.Operations.IDeviceOperations>();
            var queueSendAdapter = Substitute.For <IQueueSendAdapter>();

            deviceOperations.Create(null).ReturnsForAnyArgs("12345");

            IncomingStubs.Initialize("12345");

            var telemetryDataSinkResolver = Substitute.For <ITelemetryDataSinkResolver>();

            var device1 = new Management.Model.Device()
            {
                Network = new Management.Model.Network()
                {
                    Id = "1234"
                },
                Service = new Management.Model.Service()
                {
                    Id = "2345"
                },
                Company = new Management.Model.Company()
                {
                    Id = "3456"
                },
                Name      = "new device",
                DeviceKey = Identity.Next()
            };

            var deviceId = deviceOperations.Create(device1);

            telemetryDataSinkResolver.ResolveIncoming(deviceId)
            .Returns(new List <ITelemetryDataSink>()
            {
                new IncomingStubs.CurrentDataStub(), new IncomingStubs.TimeSeriesStub()
            });

            var telemetryDataService = new QueueingTelemetryDataService(telemetryDataSinkResolver, queueSendAdapter);

            telemetryDataService.RecordTelemetryData(deviceId, JToken.Parse("{\"Temperature\": 24, \"Time\":" + DateTime.UtcNow.Ticks + "}"));

            queueSendAdapter.ReceivedWithAnyArgs().Send(Arg.Any <TelemetryData>());
        }
Example #2
0
        public void IncomingTelemetryDataRealDevice2Test()
        {
            Initialize();

            IncomingStubs.Initialize(_deviceId);

            var telemetryDataSinkResolver = Substitute.For <ITelemetryDataSinkResolver>();

            telemetryDataSinkResolver.ResolveIncoming(_deviceId)
            .Returns(new List <ITelemetryDataSink>()
            {
                new IncomingStubs.CurrentDataStub(), new IncomingStubs.TimeSeriesStub()
            });

            var telemetryDataService = new DirectTelemetryDataService(telemetryDataSinkResolver);

            telemetryDataService.RecordTelemetryData(new TelemetryData(_deviceId, "{\"Temperature\": 24, \"Time\":" + DateTime.UtcNow.Ticks + "}", DateTime.UtcNow));

            Assert.AreEqual(2, IncomingStubs.RecordCounter);
        }
        public void IncomingTelemetryDataRealDeviceTest()
        {
            Initialize();

            IncomingStubs.Initialize(_deviceId);

            var queueSendAdapter          = Substitute.For <IQueueSendAdapter>();
            var telemetryDataSinkResolver = Substitute.For <ITelemetryDataSinkResolver>();

            telemetryDataSinkResolver.ResolveIncoming(_deviceId)
            .Returns(new List <ITelemetryDataSink>()
            {
                new IncomingStubs.CurrentDataStub(), new IncomingStubs.TimeSeriesStub()
            });

            var telemetryDataService = new QueueingTelemetryDataService(telemetryDataSinkResolver, queueSendAdapter);

            telemetryDataService.RecordTelemetryData(_deviceId, JToken.Parse("{\"Temperature\": 24, \"Time\":" + DateTime.UtcNow.Ticks + "}"));

            queueSendAdapter.ReceivedWithAnyArgs().Send(Arg.Any <TelemetryData>());
        }