Exemplo n.º 1
0
        public async Task PollForLogicAppRun_ByCorrelationId_Success()
        {
            // Arrange
            string correlationId = $"correlationId-{Guid.NewGuid()}";
            var    headers       = new Dictionary <string, string>
            {
                { "correlationId", correlationId }
            };

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

                    // Act
                    Task <LogicAppRun> pollingTask =
                        LogicAppsProvider.LocatedAt(ResourceGroup, LogicAppName, Authentication, Logger)
                        .WithCorrelationId(correlationId)
                        .PollForSingleLogicAppRunAsync();

                    await Task.WhenAll(pollingTask, postTask);

                    // Assert
                    Assert.NotNull(pollingTask.Result);
                    Assert.Equal(correlationId, pollingTask.Result.CorrelationId);
                }
        }
        public async Task TemporaryEnableSuccessStaticResultForAction_WithoutConsumerStaticResult_Success()
        {
            // Arrange
            const string actionName    = "HTTP";
            string       correlationId = $"correlationId-{Guid.NewGuid()}";
            var          headers       = new Dictionary <string, string>
            {
                { "correlationId", correlationId },
            };

            using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppMockingName, Authentication, Logger))
            {
                await using (await logicApp.TemporaryEnableAsync())
                {
                    // Act
                    await using (await logicApp.TemporaryEnableSuccessStaticResultAsync(actionName))
                    {
                        // Assert
                        await logicApp.TriggerAsync(headers);

                        LogicAppAction enabledAction = await PollForLogicAppActionAsync(correlationId, actionName);

                        Assert.Equal(actionName, enabledAction.Name);
                        Assert.Equal("200", enabledAction.Outputs.statusCode.ToString());
                        Assert.Equal(LogicAppActionStatus.Succeeded, enabledAction.Status);
                    }

                    await logicApp.TriggerAsync(headers);

                    LogicAppAction disabledAction = await PollForLogicAppActionAsync(correlationId, actionName);

                    Assert.NotEmpty(disabledAction.Outputs.headers);
                }
            }
        }
Exemplo n.º 3
0
        public async Task PollForLogicAppRun_ByTrackedProperty_DifferentValues_GetsLatest_Success()
        {
            // Arrange
            const string trackedPropertyName   = "trackedproperty";
            string       correlationId         = $"correlationId-{Guid.NewGuid()}";
            string       trackedPropertyValue1 = $"tracked-{Guid.NewGuid()}";
            string       trackedPropertyValue2 = $"tracked-{Guid.NewGuid()}";

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

            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)
                        .WithTrackedProperty(trackedPropertyName, trackedPropertyValue1)
                        .PollForSingleLogicAppRunAsync();

                    await Task.WhenAll(pollingTask, postTask);

                    // Assert
                    Assert.NotNull(pollingTask.Result);
                    Assert.Contains(pollingTask.Result.TrackedProperties, property => property.Value == trackedPropertyValue2);
                }
        }
        public async Task TemporaryEnableStaticResultsForAction_WithSuccessStaticResult_Success()
        {
            // Arrange
            const string actionName    = "HTTP";
            string       correlationId = $"correlationId-{Guid.NewGuid()}";
            var          headers       = new Dictionary <string, string>
            {
                { "correlationId", correlationId },
            };

            var definition = new StaticResultDefinition
            {
                Outputs = new Outputs
                {
                    Headers = new Dictionary <string, string> {
                        { "testheader", "testvalue" }
                    },
                    StatusCode = "200",
                    Body       = JToken.Parse("{id : 12345, name : 'test body'}")
                },
                Status = "Succeeded"
            };

            var definitions = new Dictionary <string, StaticResultDefinition> {
                [actionName] = definition
            };

            using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppMockingName, Authentication, Logger))
            {
                await using (await logicApp.TemporaryEnableAsync())
                {
                    // Act
                    await using (await logicApp.TemporaryEnableStaticResultsAsync(definitions))
                    {
                        // Assert
                        await logicApp.TriggerAsync(headers);

                        LogicAppAction enabledAction = await PollForLogicAppActionAsync(correlationId, actionName);

                        Assert.Equal("200", enabledAction.Outputs.statusCode.ToString());
                        Assert.Equal("testvalue", enabledAction.Outputs.headers["testheader"].ToString());
                        Assert.Contains("test body", enabledAction.Outputs.body.ToString());
                    }

                    await logicApp.TriggerAsync(headers);

                    LogicAppAction disabledAction = await PollForLogicAppActionAsync(correlationId, actionName);

                    Assert.DoesNotContain("test body", disabledAction.Outputs.body.ToString());
                }
            }
        }
        public async Task GetLogicAppTriggerUrl_ByName_Success()
        {
            // Arrange
            using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppName, Authentication))
            {
                // Act
                LogicAppTriggerUrl logicAppTriggerUrl = await logicApp.GetTriggerUrlByNameAsync(triggerName : "manual");

                // Assert
                Assert.NotNull(logicAppTriggerUrl.Url);
                Assert.Equal("POST", logicAppTriggerUrl.Method);
            }
        }
Exemplo n.º 6
0
        public async Task PollForLogicAppRuns_ByTrackedProperty_NumberOfRuns_Success()
        {
            // Arrange
            const string trackedPropertyName = "trackedproperty";
            const int    numberOfRuns        = 2;
            TimeSpan     timeout             = TimeSpan.FromSeconds(40);

            string correlationId        = $"correlationId-{Guid.NewGuid()}";
            var    trackedPropertyValue = Guid.NewGuid().ToString();
            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())
                {
                    // Run logic app twice with the same tracked property.
                    Task postTask1 = logicApp.TriggerAsync(headers);
                    Task postTask2 = logicApp.TriggerAsync(headers);

                    // Act
                    // Poll for a specific number of logic app runs with provided tracked property.
                    Task <IEnumerable <LogicAppRun> > pollingTask =
                        LogicAppsProvider.LocatedAt(ResourceGroup, LogicAppName, Authentication, Logger)
                        .WithTrackedProperty(trackedPropertyName, trackedPropertyValue)
                        .WithTimeout(timeout)
                        .PollForLogicAppRunsAsync(numberOfRuns);

                    await Task.WhenAll(pollingTask, postTask1, postTask2);

                    // Assert
                    Assert.NotNull(pollingTask.Result);
                    Assert.Equal(numberOfRuns, pollingTask.Result.Count());
                    Assert.All(pollingTask.Result, logicAppRun =>
                    {
                        Assert.Contains(logicAppRun.TrackedProperties, property => property.Value == trackedPropertyValue);
                    });
                }
        }
        public async Task RunByNameLogicApp_WithoutTrigger_ReturnsCorrelationId()
        {
            // Arrange
            using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, TestBaseLogicAppName, Authentication, Logger))
            {
                await using (await logicApp.TemporaryEnableAsync())
                {
                    // Act
                    await logicApp.RunByNameAsync(triggerName : "manual");

                    // Assert
                    LogicAppRun run = await LogicAppsProvider
                                      .LocatedAt(ResourceGroup, TestBaseLogicAppName, Authentication, Logger)
                                      .WithStartTime(DateTimeOffset.UtcNow.AddMinutes(-1))
                                      .PollForSingleLogicAppRunAsync();

                    Assert.Contains("Response", run.Actions.Select(action => action.Name));
                }
            }
        }
        public async Task TemporaryEnableLogicApp_Success()
        {
            // Arrange
            using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppMockingName, Authentication, Logger))
            {
                // Act
                await using (await logicApp.TemporaryEnableAsync())
                {
                    // Assert
                    LogicAppMetadata metadata = await logicApp.GetMetadataAsync();

                    Assert.Equal(LogicAppState.Enabled, metadata.State);
                }
                {
                    LogicAppMetadata metadata = await logicApp.GetMetadataAsync();

                    Assert.Equal(LogicAppState.Disabled, metadata.State);
                }
            }
        }
Exemplo n.º 9
0
        public async Task PollForLogicAppRun_NotMatchedCorrelation_Fails()
        {
            // Arrange
            var headers = new Dictionary <string, string>
            {
                { "correlationId", $"correlationId-{Guid.NewGuid()}" }
            };

            // Act
            Task <LogicAppRun> pollingTask =
                LogicAppsProvider.LocatedAt(ResourceGroup, LogicAppName, Authentication, Logger)
                .WithTimeout(TimeSpan.FromSeconds(5))
                .WithCorrelationId("not-matched-correlation-ID")
                .PollForSingleLogicAppRunAsync();

            using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppName, Authentication, Logger))
            {
                // Assert
                await logicApp.TriggerAsync(headers);

                await Assert.ThrowsAsync <TimeoutException>(() => pollingTask);
            }
        }
Exemplo n.º 10
0
        public async Task PollForLogicAppRuns_ByCorrelationId_NumberOfRuns_Success()
        {
            // Arrange
            const int numberOfRuns = 2;
            TimeSpan  timeout      = TimeSpan.FromSeconds(30);

            string correlationId = $"correlationId-{Guid.NewGuid()}";
            var    headers       = new Dictionary <string, string>
            {
                { "correlationId", correlationId }
            };

            using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppName, Authentication))
                await using (await logicApp.TemporaryEnableAsync())
                {
                    // Run logic app twice with the same correlation id.
                    Task postTask1 = logicApp.TriggerAsync(headers);
                    Task postTask2 = logicApp.TriggerAsync(headers);

                    // Act
                    Task <IEnumerable <LogicAppRun> > pollingTask =
                        LogicAppsProvider.LocatedAt(ResourceGroup, LogicAppName, Authentication, Logger)
                        .WithCorrelationId(correlationId)
                        .WithTimeout(timeout)
                        .PollForLogicAppRunsAsync(numberOfRuns);

                    await Task.WhenAll(pollingTask, postTask1, postTask2);

                    // Assert
                    Assert.Equal(numberOfRuns, pollingTask.Result.Count());
                    Assert.All(pollingTask.Result, logicAppRun =>
                    {
                        Assert.Equal(correlationId, logicAppRun.CorrelationId);
                    });
                }
        }
        public async Task TemporaryUpdateLogicApp_WithUpdatedResponse_ReturnsUpdatedResponse()
        {
            // Arrange
            const string actionName    = "Response";
            string       correlationId = $"correlation-{Guid.NewGuid()}";
            var          headers       = new Dictionary <string, string>
            {
                { "correlationId", correlationId },
            };

            string definition = Configuration.GetLogicAppTriggerUpdateDefinition();

            using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, TestBaseLogicAppName, Authentication, Logger))
            {
                await using (await logicApp.TemporaryEnableAsync())
                {
                    // Act
                    await using (await logicApp.TemporaryUpdateAsync(definition))
                    {
                        // Assert
                        await logicApp.TriggerAsync(headers);

                        LogicAppAction updatedAction = await PollForLogicAppActionAsync(correlationId, actionName, TestBaseLogicAppName);

                        Assert.Equal("Updated", updatedAction.Outputs.body.response.ToString());
                    }
                    {
                        await logicApp.TriggerAsync(headers);

                        LogicAppAction updatedAction = await PollForLogicAppActionAsync(correlationId, actionName, TestBaseLogicAppName);

                        Assert.Equal("Original", updatedAction.Outputs.body.response.ToString());
                    }
                }
            }
        }
 public async Task ConstructorWithLogger_WithNullAuthentication_Fails()
 {
     await Assert.ThrowsAnyAsync <ArgumentException>(
         () => LogicAppClient.CreateAsync(ResourceGroup, LogicAppName, authentication: null, logger: Logger));
 }
 public async Task ConstructorWithLogger_WithBlankLogicApp_Fails(string logicApp)
 {
     await Assert.ThrowsAsync <ArgumentException>(
         () => LogicAppClient.CreateAsync(ResourceGroup, logicApp, Authentication, Logger));
 }
 public async Task Constructor_WithBlankResourceGroup_Fails(string resourceGroup)
 {
     await Assert.ThrowsAsync <ArgumentException>(
         () => LogicAppClient.CreateAsync(resourceGroup, LogicAppName, Authentication));
 }