public async Task ExecuteAsync_SendsEvent() { // Arrange var deviceClientMock = new Mock <IDeviceClient>(); var command = new SendEventCommand(deviceClientMock.Object); var commandParameters = new Dictionary <string, object> { { "obj", new { name = "foo" } } }; // Act await command.ExecuteAsync(commandParameters); // Assert deviceClientMock.Verify( m => m.SendEventAsync(It.IsAny <Message>()), Times.Once); }
public async Task ExecuteAsync_ReturnsPayloadInCamelCase() { // Arrange var deviceClientMock = new Mock <IDeviceClient>(); var command = new SendEventCommand(deviceClientMock.Object); var commandParameters = new Dictionary <string, object> { { "obj", new { Name = "foo" } } }; // Act var result = await command.ExecuteAsync(commandParameters); // Assert var jo = JObject.Parse(result); ((string)jo["name"]).Should().Be("foo"); }
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 }
public virtual void ExecuteSendEvent(SendEventCommand command) { command.Sender = RoomPanel; RoomPanel.SendEvent.OnNext(command); }
public virtual void SendEventHandler(SendEventCommand command) { this.SendEvent(command.Sender as RoomPanelViewModel); }