public async Task CreateForUpstreamProtocolTest(UpstreamProtocol upstreamProtocol) { // Arrange Option <UpstreamProtocol> receivedProtocol = Option.None <UpstreamProtocol>(); Task <Client.ModuleClient> ModuleClientCreator(UpstreamProtocol up) { receivedProtocol = Option.Some(up); return(Task.FromResult((Client.ModuleClient)null)); } // Act await ModuleClient.CreateDeviceClientForUpstreamProtocol(Option.Some(upstreamProtocol), ModuleClientCreator); // Assert Assert.Equal(Option.Some(upstreamProtocol), receivedProtocol); }
public async Task CreateForUpstreamProtocolTest(UpstreamProtocol upstreamProtocol, TransportType expectedTransportType) { // Arrange var receivedTransportType = TransportType.Http1; Task <Client.ModuleClient> ModuleClientCreator(TransportType transportType) { receivedTransportType = transportType; return(Task.FromResult((Client.ModuleClient)null)); } // Act await ModuleClient.CreateDeviceClientForUpstreamProtocol(Option.Some(upstreamProtocol), ModuleClientCreator); // Assert Assert.Equal(expectedTransportType, receivedTransportType); }
public async Task CreateForNoUpstreamProtocolTest() { // Arrange var receivedProtocols = new List <UpstreamProtocol>(); Task <Client.ModuleClient> DeviceClientCreator(UpstreamProtocol up) { receivedProtocols.Add(up); return(receivedProtocols.Count == 1 ? Task.FromException <Client.ModuleClient>(new InvalidOperationException()) : Task.FromResult( Client.ModuleClient.Create( "example.com", new ModuleAuthenticationWithToken("deviceid", "moduleid", TokenHelper.CreateSasToken("foo.azure-devices.net"))))); } // Act await ModuleClient.CreateDeviceClientForUpstreamProtocol(Option.None <UpstreamProtocol>(), DeviceClientCreator); // Assert Assert.Equal(2, receivedProtocols.Count); Assert.Equal(UpstreamProtocol.Amqp, receivedProtocols[0]); Assert.Equal(UpstreamProtocol.AmqpWs, receivedProtocols[1]); }