public static ITwinModuleApi CreateModueClient(string deviceId, string moduleName) { var logger = ConsoleLogger.Create(LogEventLevel.Error); var iotHubConfig = ConnectionStringEx.ToIoTHubConfig(Environment.GetEnvironmentVariable("IOT_HUB_CONNECTION_STRING")); var httpClient = new HttpClient(logger); var iotHubServiceClient = new IoTHubServiceHttpClient(httpClient, iotHubConfig, new NewtonSoftJsonSerializer(), logger); var methodClient = new ChunkMethodClient(new IoTHubTwinMethodClient(iotHubServiceClient, logger), new NewtonSoftJsonSerializer(), logger); return(new TwinModuleClient(methodClient, deviceId, moduleName)); }
public void TestTest2InvocationChunked(int size) { var router = GetRouter(); var client = new ChunkMethodClient(new TestMethodClient(router), new ConsoleLogger()); var expected = new byte[size]; r.NextBytes(expected); var response = client.CallMethodAsync("test", "test", "Test2_V1", Encoding.UTF8.GetBytes(JsonConvertEx.SerializeObject(expected)), null, null).Result; var returned = JsonConvertEx.DeserializeObject <byte[]>( Encoding.UTF8.GetString(response)); Assert.Equal(expected, returned); }
public void TestTest8InvocationV2Chunked(int size) { var router = GetRouter(); var client = new ChunkMethodClient(new TestMethodClient(router), Log.Logger); var expected = new byte[size]; kRand.NextBytes(expected); var response = client.CallMethodAsync("test", "test", "Test8_V2", Encoding.UTF8.GetBytes(JsonConvertEx.SerializeObject(expected)), null, null, CancellationToken.None).Result; var returned = JsonConvertEx.DeserializeObject <byte[]>( Encoding.UTF8.GetString(response)); Assert.Equal(expected, returned); }
public void TestTest8InvocationV1Chunked(int size) { var router = GetRouter(); var client = new ChunkMethodClient(new TestMethodClient(router), _serializer, Log.Logger); var expected = new byte[size]; kRand.NextBytes(expected); var response = client.CallMethodAsync("test", "test", "Test8_V1", _serializer.SerializeToBytes(expected).ToArray(), null, null, CancellationToken.None).Result; var returned = _serializer.Deserialize <byte[]>( Encoding.UTF8.GetString(response)); Assert.Equal(expected, returned); }
public void TestTest1InvocationChunked() { var router = GetRouter(); var client = new ChunkMethodClient(new TestMethodClient(router), new ConsoleLogger()); var buffer = new byte[300809]; r.NextBytes(buffer); var expected = new TestModel { Test = buffer }; var response = client.CallMethodAsync("test", "test", "Test1_V1", Encoding.UTF8.GetBytes(JsonConvertEx.SerializeObject(expected)), null, null).Result; var returned = JsonConvertEx.DeserializeObject <TestModel>( Encoding.UTF8.GetString(response)); Assert.Equal(expected.Test, returned.Test); }
public void TestTest1InvocationChunked() { var router = GetRouter(); var client = new ChunkMethodClient(new TestMethodClient(router), _serializer, Log.Logger); var buffer = new byte[300809]; kRand.NextBytes(buffer); var expected = new TestModel { Test = buffer }; var response = client.CallMethodAsync("test", "test", "Test1_V1", _serializer.SerializeToBytes(expected).ToArray(), null, null, CancellationToken.None).Result; var returned = _serializer.Deserialize <TestModel>( Encoding.UTF8.GetString(response)); Assert.Equal(expected.Test, returned.Test); }