From 550fe1bfdc620ddfceb34291473597d341ab0888 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Wed, 17 Jun 2020 06:59:02 +0200 Subject: [PATCH 1/2] Update LogicAppsProvider.cs --- src/Invictus.Testing/LogicAppsProvider.cs | 31 +++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Invictus.Testing/LogicAppsProvider.cs b/src/Invictus.Testing/LogicAppsProvider.cs index f980d13..75955bd 100644 --- a/src/Invictus.Testing/LogicAppsProvider.cs +++ b/src/Invictus.Testing/LogicAppsProvider.cs @@ -28,11 +28,12 @@ public class LogicAppsProvider private readonly string _resourceGroup, _logicAppName; private readonly LogicAuthentication _authentication; private readonly TimeSpan _retryInterval = TimeSpan.FromSeconds(1); + private readonly IDictionary _trackingProperties = new Dictionary(); private readonly ILogger _logger; private DateTimeOffset _startTime = DateTimeOffset.UtcNow; private TimeSpan _timeout = TimeSpan.FromSeconds(90); - private string _trackedPropertyName, _trackedPropertyValue, _correlationId; + private string _correlationId; private bool _hasTrackedProperty, _hasCorrelationId; private static readonly HttpClient HttpClient = new HttpClient(); @@ -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; + _trackedProperties[trackedPropertyName] = trackedPropertyValue; return this; } @@ -275,8 +274,8 @@ private async Task> GetLogicAppRunsAsync() IEnumerable actions = await FindLogicAppRunActionsAsync(managementClient, workFlowRun.Name); - if (_hasTrackedProperty && actions.Any(action => HasTrackedProperty(action.TrackedProperties)) - || !_hasTrackedProperty) + if (_trackedProperties.Any() && actions.Any(action => HasTrackedProperty(action.TrackedProperties)) + || !_trackedProperties.Any()) { var logicAppRun = LogicAppConverter.ToLogicAppRun(workFlowRun, actions); logicAppRuns.Add(logicAppRun); @@ -326,16 +325,20 @@ private bool HasTrackedProperty(IReadOnlyDictionary properties) return false; } - return properties.Any(property => + return _trackedProperties.Any(prop => { - if (property.Key is null || property.Value is null) + + return properties.Any(property => { - return false; - } + if (property.Key is null || property.Value is null) + { + return false; + } - return property.Key.Equals(_trackedPropertyName, StringComparison.OrdinalIgnoreCase) - && property.Value.Equals(_trackedPropertyValue, StringComparison.OrdinalIgnoreCase); - }); + return property.Key.Equals(prop, StringComparison.OrdinalIgnoreCase) + && property.Value.Equals(prop, StringComparison.OrdinalIgnoreCase); + }); + } } } -} \ No newline at end of file +} From 73846490bf82c15747e8b8cdf85f000bae05fb46 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Wed, 17 Jun 2020 07:37:17 +0200 Subject: [PATCH 2/2] Feature - add multiple tracking properties --- .../LogicAppsProviderTests.cs | 32 +++++++++++++++++++ src/Invictus.Testing/LogicAppsProvider.cs | 25 +++++++-------- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/Invictus.Testing.Tests.Integration/LogicAppsProviderTests.cs b/src/Invictus.Testing.Tests.Integration/LogicAppsProviderTests.cs index 1771607..3096b06 100644 --- a/src/Invictus.Testing.Tests.Integration/LogicAppsProviderTests.cs +++ b/src/Invictus.Testing.Tests.Integration/LogicAppsProviderTests.cs @@ -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 + { + { "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 pollingTask = + LogicAppsProvider.LocatedAt(ResourceGroup, LogicAppName, Authentication, Logger) + .WithTimeout(TimeSpan.FromSeconds(10)) + .WithTrackedProperty(trackedPropertyName, trackedPropertyValue) + .WithTrackedProperty("unknown-tracking-property", trackedPropertyValue) + .PollForSingleLogicAppRunAsync(); + + await Assert.ThrowsAsync(() => Task.WhenAll(pollingTask, postTask)); + } + } + [Fact] public async Task PollForLogicAppRun_ByTrackedProperty_DifferentValues_GetsLatest_Success() { diff --git a/src/Invictus.Testing/LogicAppsProvider.cs b/src/Invictus.Testing/LogicAppsProvider.cs index 75955bd..64d7368 100644 --- a/src/Invictus.Testing/LogicAppsProvider.cs +++ b/src/Invictus.Testing/LogicAppsProvider.cs @@ -34,7 +34,7 @@ public class LogicAppsProvider private DateTimeOffset _startTime = DateTimeOffset.UtcNow; private TimeSpan _timeout = TimeSpan.FromSeconds(90); private string _correlationId; - private bool _hasTrackedProperty, _hasCorrelationId; + private bool _hasCorrelationId; private static readonly HttpClient HttpClient = new HttpClient(); @@ -137,7 +137,7 @@ public LogicAppsProvider WithTrackedProperty(string trackedPropertyName, string Guard.NotNull(trackedPropertyName, nameof(trackedPropertyName)); Guard.NotNull(trackedPropertyValue, nameof(trackedPropertyValue)); - _trackedProperties[trackedPropertyName] = trackedPropertyValue; + _trackingProperties[trackedPropertyName] = trackedPropertyValue; return this; } @@ -219,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( @@ -274,8 +274,8 @@ private async Task> GetLogicAppRunsAsync() IEnumerable actions = await FindLogicAppRunActionsAsync(managementClient, workFlowRun.Name); - if (_trackedProperties.Any() && actions.Any(action => HasTrackedProperty(action.TrackedProperties)) - || !_trackedProperties.Any()) + if (_trackingProperties.Count > 0 && actions.Any(action => HasTrackedProperty(action.TrackedProperties)) + || _trackingProperties.Count <= 0) { var logicAppRun = LogicAppConverter.ToLogicAppRun(workFlowRun, actions); logicAppRuns.Add(logicAppRun); @@ -325,20 +325,19 @@ private bool HasTrackedProperty(IReadOnlyDictionary properties) return false; } - return _trackedProperties.Any(prop => + return _trackingProperties.All(expectedProp => { - - return properties.Any(property => + return properties.Any(actualProp => { - if (property.Key is null || property.Value is null) + if (actualProp.Key is null || actualProp.Value is null) { return false; } - return property.Key.Equals(prop, StringComparison.OrdinalIgnoreCase) - && property.Value.Equals(prop, StringComparison.OrdinalIgnoreCase); + return actualProp.Key.Equals(expectedProp.Key, StringComparison.OrdinalIgnoreCase) + && actualProp.Value.Equals(expectedProp.Value, StringComparison.OrdinalIgnoreCase); }); - } + }); } } }