private static LogicAppDefinition UpdateLogicAppDefinitionWithStaticResult( LogicAppDefinition logicAppDefinition, string actionName, StaticResultDefinition staticResultDefinition) { ActionDefinition actionDefinition = logicAppDefinition.Actions[actionName]; if (actionDefinition.RuntimeConfiguration != null) { actionDefinition.RuntimeConfiguration.StaticResult.StaticResultOptions = "Enabled"; } else { string staticResultName = $"{actionName}0"; actionDefinition.RuntimeConfiguration = new RuntimeConfiguration { StaticResult = new StaticResult { Name = staticResultName, StaticResultOptions = "Enabled" } }; if (logicAppDefinition.StaticResults == null) { logicAppDefinition.StaticResults = new Dictionary <string, StaticResultDefinition>(); } logicAppDefinition.StaticResults[staticResultName] = staticResultDefinition; } return(logicAppDefinition); }
/// <summary> /// Temporary enables a static result for an action with the given <paramref name="actionName"/> on the logic app, /// and disables the static result when the returned instance gets disposed. /// </summary> /// <param name="actionName">The name of the action to enable the static result.</param> /// <returns> /// An instance to control when the static result for the action on the logic app should be disabled. /// </returns> public async Task<IAsyncDisposable> TemporaryEnableSuccessStaticResultAsync(string actionName) { Guard.NotNullOrEmpty(actionName, nameof(actionName)); var successfulStaticResult = new StaticResultDefinition { Outputs = new Outputs { Headers = new Dictionary<string, string>(), StatusCode = "OK" }, Status = "Succeeded" }; return await TemporaryEnableStaticResultAsync(actionName, successfulStaticResult); }
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()); } } }
/// <summary> /// Temporary enables a static result for an action with the given <paramref name="actionName"/> on the logic app, /// and disables the static result when the returned instance gets disposed. /// </summary> /// <param name="actionName">The name of the action to enable the static result.</param> /// <param name="definition">The definition that describes the static result for the action.</param> /// <returns> /// An instance to control when the static result for the action on the logic app should be disabled. /// </returns> public async Task <IAsyncDisposable> TemporaryEnableStaticResultAsync(string actionName, StaticResultDefinition definition) { Guard.NotNullOrEmpty(actionName, nameof(actionName)); Guard.NotNull(definition, nameof(definition)); return(await AsyncDisposable.CreateAsync( async() => await EnableStaticResultForActionsAsync(new Dictionary <string, StaticResultDefinition> { [actionName] = definition }), async() => await DisableStaticResultForActionAsync(actionName))); }