示例#1
0
        public async Task ExecuteAsync_UpdatesDeviceProperties()
        {
            // Arrange
            Mock <IDeviceClient> deviceClientMock = new Mock <IDeviceClient>();
            var command           = new UpdateReportedPropertiesCommand(deviceClientMock.Object);
            var commandParameters = new Dictionary <string, object>();

            // Act
            await command.ExecuteAsync(commandParameters);

            // Assert
            deviceClientMock.Verify(
                m => m.UpdateReportedPropertiesAsync(
                    It.IsAny <TwinCollection>()),
                Times.Once);
        }
示例#2
0
        public async Task ExecuteAsync_ReturnsTwinCollection()
        {
            // Arrange
            Mock <IDeviceClient> deviceClientMock = new Mock <IDeviceClient>();
            var command           = new UpdateReportedPropertiesCommand(deviceClientMock.Object);
            var commandParameters = new Dictionary <string, object>
            {
                { "key", "val" }
            };

            // Act
            var actualTwinCollection = await command.ExecuteAsync(commandParameters);

            // Assert
            ((string)actualTwinCollection["key"]).Should().Be("val");
        }
示例#3
0
        private static async Task Main()
        {
            Console.WriteLine("Initializing...");

            var connectionString    = "HostName=ps-iothub-fm.azure-devices.net;DeviceId=device1;SharedAccessKey=ZJNtwonsWec64h0N0sXaW4jaml5CJ5JVCZMIO8S9erQ=";
            var deviceClientFactory = new DeviceClientFactory(connectionString);
            var createDeviceCommand = new CreateDeviceCommand(deviceClientFactory);

            var deviceClient = await createDeviceCommand.ExecuteAsync();

            await deviceClient.OpenAsync();

            Console.WriteLine("Device is connected.");

            var updatePropertiesCommandParameters = new Dictionary <string, object>
            {
                { "connectionType", "wi-fi" },
                { "connectionStrength", "strong" }
            };

            var updatePropertiesCommand = new UpdateReportedPropertiesCommand(deviceClient);
            await updatePropertiesCommand.ExecuteAsync(updatePropertiesCommandParameters);

            while (true)
            {
                var obj = new { LuckyNumber = new Random().Next(100, 200), Ts = DateTime.UtcNow };
                var sendEventCommand = new SendEventCommand(deviceClient);

                var sendEventCommandParameters = new Dictionary <string, object>
                {
                    { "obj", obj }
                };

                await sendEventCommand.ExecuteAsync(sendEventCommandParameters);

                Console.WriteLine("Message sent.");
                await Task.Delay(TimeSpan.FromSeconds(2));
            }
            // ReSharper disable once FunctionNeverReturns
        }