Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,38 @@ public async Task PollForLogicAppRun_ByTrackedProperty_Success()
}
}

[Fact]
public async Task PollForLogicAppRun_ByUnknownTrackedProperty_Success()
{
// Arrange
const string trackedPropertyName = "trackedproperty";
string correlationId = $"correlationId-{Guid.NewGuid()}";
string trackedPropertyValue = $"tracked-{Guid.NewGuid()}";

var headers = new Dictionary<string, string>
{
{ "correlationId", correlationId },
{ "trackedpropertyheader1", trackedPropertyValue },
{ "trackedpropertyheader2", trackedPropertyValue }
};

using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppName, Authentication))
await using (await logicApp.TemporaryEnableAsync())
{
Task postTask = logicApp.TriggerAsync(headers);

// Act
Task<LogicAppRun> pollingTask =
LogicAppsProvider.LocatedAt(ResourceGroup, LogicAppName, Authentication, Logger)
.WithTimeout(TimeSpan.FromSeconds(10))
.WithTrackedProperty(trackedPropertyName, trackedPropertyValue)
.WithTrackedProperty("unknown-tracking-property", trackedPropertyValue)
.PollForSingleLogicAppRunAsync();

await Assert.ThrowsAsync<TimeoutException>(() => Task.WhenAll(pollingTask, postTask));
}
}

[Fact]
public async Task PollForLogicAppRun_ByTrackedProperty_DifferentValues_GetsLatest_Success()
{
Expand Down
34 changes: 18 additions & 16 deletions src/Invictus.Testing/LogicAppsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ public class LogicAppsProvider
private readonly string _resourceGroup, _logicAppName;
private readonly LogicAuthentication _authentication;
private readonly TimeSpan _retryInterval = TimeSpan.FromSeconds(1);
private readonly IDictionary<string, string> _trackingProperties = new Dictionary<string, string>();
private readonly ILogger _logger;

private DateTimeOffset _startTime = DateTimeOffset.UtcNow;
private TimeSpan _timeout = TimeSpan.FromSeconds(90);
private string _trackedPropertyName, _trackedPropertyValue, _correlationId;
private bool _hasTrackedProperty, _hasCorrelationId;
private string _correlationId;
private bool _hasCorrelationId;

private static readonly HttpClient HttpClient = new HttpClient();

Expand Down Expand Up @@ -136,9 +137,7 @@ public LogicAppsProvider WithTrackedProperty(string trackedPropertyName, string
Guard.NotNull(trackedPropertyName, nameof(trackedPropertyName));
Guard.NotNull(trackedPropertyValue, nameof(trackedPropertyValue));

_hasTrackedProperty = true;
_trackedPropertyName = trackedPropertyName;
_trackedPropertyValue = trackedPropertyValue;
_trackingProperties[trackedPropertyName] = trackedPropertyValue;
return this;
}

Expand Down Expand Up @@ -220,8 +219,8 @@ await Policy.TimeoutAsync(_timeout)
? $"{Environment.NewLine} with correlation property equal '{_correlationId}'"
: String.Empty;

string trackedProperty = _hasTrackedProperty
? $" {Environment.NewLine} with tracked property [{_trackedPropertyName}] = {_trackedPropertyValue}"
string trackedProperty = _trackingProperties.Count > 0
? $" {Environment.NewLine} with tracked properties {{{String.Join(", ", _trackingProperties.Select(prop => $"[{prop.Key}] = {prop.Value}"))}}}"
: String.Empty;

throw new TimeoutException(
Expand Down Expand Up @@ -275,8 +274,8 @@ private async Task<IEnumerable<LogicAppRun>> GetLogicAppRunsAsync()
IEnumerable<LogicAppAction> actions =
await FindLogicAppRunActionsAsync(managementClient, workFlowRun.Name);

if (_hasTrackedProperty && actions.Any(action => HasTrackedProperty(action.TrackedProperties))
|| !_hasTrackedProperty)
if (_trackingProperties.Count > 0 && actions.Any(action => HasTrackedProperty(action.TrackedProperties))
|| _trackingProperties.Count <= 0)
{
var logicAppRun = LogicAppConverter.ToLogicAppRun(workFlowRun, actions);
logicAppRuns.Add(logicAppRun);
Expand Down Expand Up @@ -326,16 +325,19 @@ private bool HasTrackedProperty(IReadOnlyDictionary<string, string> properties)
return false;
}

return properties.Any(property =>
return _trackingProperties.All(expectedProp =>
{
if (property.Key is null || property.Value is null)
return properties.Any(actualProp =>
{
return false;
}
if (actualProp.Key is null || actualProp.Value is null)
{
return false;
}

return property.Key.Equals(_trackedPropertyName, StringComparison.OrdinalIgnoreCase)
&& property.Value.Equals(_trackedPropertyValue, StringComparison.OrdinalIgnoreCase);
return actualProp.Key.Equals(expectedProp.Key, StringComparison.OrdinalIgnoreCase)
&& actualProp.Value.Equals(expectedProp.Value, StringComparison.OrdinalIgnoreCase);
});
});
}
}
}
}