public async Task AssertIoTHubDeviceMessageExistsAsync(string deviceID, string targetJsonProperty, string expectedJsonValue, SearchLogOptions options) { var assertionLevel = Configuration.IoTHubAssertLevel; if (options != null && options.TreatAsError.HasValue) { assertionLevel = options.TreatAsError.Value ? LogValidationAssertLevel.Error : LogValidationAssertLevel.Warning; } if (assertionLevel == LogValidationAssertLevel.Ignore) { return; } var searchResult = await SearchIoTHubMessageAsync( (eventData, eventDeviceID, eventDataMessageBody) => IsDeviceMessage(deviceID, targetJsonProperty, expectedJsonValue, eventDeviceID, eventDataMessageBody), new SearchLogOptions(options.Description) { TreatAsError = options.TreatAsError, }); if (assertionLevel == LogValidationAssertLevel.Error) { var logs = string.Join("\n\t", searchResult.Logs.TakeLast(5)); Assert.True(searchResult.Found, $"Searching for \"{targetJsonProperty}\": {expectedJsonValue} failed for device {deviceID}. Current log content: [{logs}]"); } else if (assertionLevel == LogValidationAssertLevel.Warning) { if (!searchResult.Found) { var logs = string.Join("\n\t", searchResult.Logs.TakeLast(5)); TestLogger.Log($"[WARN] \"{targetJsonProperty}\": {expectedJsonValue} for device {deviceID} was not found. Logs: [{logs}]"); } } }
// Asserts leaf device message payload exists. It searches inside the payload "data" property. Has built-in retries public async Task AssertIoTHubDeviceMessageExistsAsync(string deviceID, string expectedDataValue, SearchLogOptions options) { await AssertIoTHubDeviceMessageExistsAsync(deviceID, "data", expectedDataValue, options); }
public async Task <SearchLogResult> SearchNetworkServerModuleAsync(Func <string, bool> predicate, SearchLogOptions options) => this.tcpLogListener != null ? await SearchTcpLogs(predicate, options) : await SearchIoTHubLogs(predicate, options);