Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
David R. Williamson committed Dec 7, 2022
1 parent 6265432 commit 46935aa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async Task TestOperationAsync(IotHubDeviceClient deviceClient, TestDevice testDe

// D2C Operation
VerboseTestLogger.WriteLine($"{nameof(CombinedClientOperationsPoolAmqpTests)}: Operation 1: Send D2C for device={testDevice.Id}");
var message = TelemetryE2ETests.ComposeD2cTestMessage(out string _, out string _);
TelemetryMessage message = TelemetryE2ETests.ComposeD2cTestMessage(out string _, out string _);
Task sendD2cMessage = deviceClient.SendTelemetryAsync(message);
clientOperations.Add(sendD2cMessage);

Expand Down
7 changes: 4 additions & 3 deletions e2e/test/iothub/device/MethodE2ECustomPayloadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ private async Task SendMethodAndRespondAsync(
await Task.WhenAll(serviceSendTask, methodReceivedTask).ConfigureAwait(false);
}

public static async Task ServiceSendMethodAndVerifyResponseAsync(
public static async Task ServiceSendMethodAndVerifyResponseAsync<T>(
string deviceId,
string methodName,
object response,
object request,
T request,
TimeSpan responseTimeout = default,
IotHubServiceClientOptions serviceClientTransportSettings = default)
{
Expand All @@ -152,7 +152,8 @@ public static async Task ServiceSendMethodAndVerifyResponseAsync(

VerboseTestLogger.WriteLine($"{nameof(ServiceSendMethodAndVerifyResponseAsync)}: Method status: {methodResponse.Status}.");
methodResponse.Status.Should().Be(200);
methodResponse.PayloadAsString.Should().BeEquivalentTo(JsonConvert.SerializeObject(response));
methodResponse.TryGetPayload(out T actual).Should().BeTrue();
JsonConvert.SerializeObject(actual).Should().BeEquivalentTo(JsonConvert.SerializeObject(response));
}

public static async Task<Task> SetDeviceReceiveMethod_booleanPayloadAsync(IotHubDeviceClient deviceClient, string methodName)
Expand Down
14 changes: 8 additions & 6 deletions e2e/test/iothub/device/MethodE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ public static async Task ServiceSendMethodAndVerifyNotReceivedAsync(
error.And.IsTransient.Should().BeTrue();
}

public static async Task ServiceSendMethodAndVerifyResponseAsync(
public static async Task ServiceSendMethodAndVerifyResponseAsync<T>(
string deviceId,
string methodName,
object respJson,
T respJson,
object reqJson,
TimeSpan responseTimeout = default,
IotHubServiceClientOptions serviceClientTransportSettings = default)
Expand All @@ -309,14 +309,15 @@ public static async Task ServiceSendMethodAndVerifyResponseAsync(

VerboseTestLogger.WriteLine($"{nameof(ServiceSendMethodAndVerifyResponseAsync)}: Method status: {response.Status}.");
response.Status.Should().Be(200);
JsonConvert.SerializeObject(response.PayloadAsString).Should().Be(JsonConvert.SerializeObject(respJson));
response.TryGetPayload(out T actual).Should().BeTrue();
JsonConvert.SerializeObject(actual).Should().Be(JsonConvert.SerializeObject(respJson));
}

public static async Task ServiceSendMethodAndVerifyResponseAsync(
public static async Task ServiceSendMethodAndVerifyResponseAsync<T>(
string deviceId,
string moduleId,
string methodName,
object respJson,
T respJson,
object reqJson,
TimeSpan responseTimeout = default,
IotHubServiceClientOptions serviceClientTransportSettings = default)
Expand All @@ -338,7 +339,8 @@ public static async Task ServiceSendMethodAndVerifyResponseAsync(

VerboseTestLogger.WriteLine($"{nameof(ServiceSendMethodAndVerifyResponseAsync)}: Method status: {response.Status}.");
response.Status.Should().Be(200);
JsonConvert.SerializeObject(response.PayloadAsString).Should().Be(JsonConvert.SerializeObject(respJson));
response.TryGetPayload(out T actual).Should().BeTrue();
JsonConvert.SerializeObject(actual).Should().Be(JsonConvert.SerializeObject(respJson));
}

public static async Task<Task> SubscribeAndUnsubscribeMethodAsync(IotHubDeviceClient deviceClient, string methodName)
Expand Down
5 changes: 3 additions & 2 deletions e2e/test/iothub/device/MethodFaultInjectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ await SendMethodAndRespondRecoveryAsync(
.ConfigureAwait(false);
}

private async Task ServiceSendMethodAndVerifyResponseAsync(string deviceName, string methodName, object deviceResponsePayload, object serviceRequestPayload)
private async Task ServiceSendMethodAndVerifyResponseAsync<T>(string deviceName, string methodName, T deviceResponsePayload, object serviceRequestPayload)
{
var sw = Stopwatch.StartNew();
bool done = false;
Expand Down Expand Up @@ -238,7 +238,8 @@ private async Task ServiceSendMethodAndVerifyResponseAsync(string deviceName, st
VerboseTestLogger.WriteLine($"{nameof(ServiceSendMethodAndVerifyResponseAsync)}: Method status: {response.Status}.");

response.Status.Should().Be(200);
JsonConvert.SerializeObject(response.PayloadAsString).Should().Be(JsonConvert.SerializeObject(deviceResponsePayload));
response.TryGetPayload<T>(out T actual).Should().BeTrue();
JsonConvert.SerializeObject(actual).Should().Be(JsonConvert.SerializeObject(deviceResponsePayload));

done = true;
}
Expand Down

0 comments on commit 46935aa

Please sign in to comment.