|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Net; |
| 5 | +using System.Net.Http; |
| 6 | +using System.Text; |
| 7 | +using System.Threading.Tasks; |
| 8 | +using LogicAppUnit.Helper; |
| 9 | +using LogicAppUnit.Mocking; |
| 10 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 11 | + |
| 12 | +namespace LogicAppUnit.Samples.LogicApps.Tests.HttpWithManagedIdentityWorkflow |
| 13 | +{ |
| 14 | + /// <summary> |
| 15 | + /// Test cases for the <i>http-with-managed-identity-workflow</i> workflow which has an HTTP action with Managed Identity as the authentication type. |
| 16 | + /// </summary> |
| 17 | + [TestClass] |
| 18 | + public class HttpWithManagedIdentityWorkflowTest : WorkflowTestBase |
| 19 | + { |
| 20 | + [TestInitialize] |
| 21 | + public void TestInitialize() |
| 22 | + { |
| 23 | + Initialize(Constants.LOGIC_APP_TEST_EXAMPLE_BASE_PATH, Constants.HTTP_WITH_MANAGED_IDENTITY_WORKFLOW); |
| 24 | + } |
| 25 | + |
| 26 | + [ClassCleanup] |
| 27 | + public static void CleanResources() |
| 28 | + { |
| 29 | + Close(); |
| 30 | + } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Tests that the correct response is returned when the HTTP call to the Service to get the customers is successful. |
| 34 | + /// </summary> |
| 35 | + [TestMethod] |
| 36 | + public void HttpWithManagedIdentityWorkflowTest_When_Successful() |
| 37 | + { |
| 38 | + using (ITestRunner testRunner = CreateTestRunner()) |
| 39 | + { |
| 40 | + // Configure mock responses |
| 41 | + testRunner |
| 42 | + .AddMockResponse( |
| 43 | + MockRequestMatcher.Create() |
| 44 | + .UsingGet() |
| 45 | + .WithPath(PathMatchType.Exact, "/api/v1/customers")) |
| 46 | + .RespondWith( |
| 47 | + MockResponseBuilder.Create() |
| 48 | + .WithSuccess()); |
| 49 | + |
| 50 | + // Run the workflow |
| 51 | + var workflowResponse = testRunner.TriggerWorkflow(HttpMethod.Post); |
| 52 | + |
| 53 | + // Check workflow run status |
| 54 | + Assert.AreEqual(WorkflowRunStatus.Succeeded, testRunner.WorkflowRunStatus); |
| 55 | + |
| 56 | + // Check workflow response |
| 57 | + testRunner.ExceptionWrapper(() => Assert.AreEqual(HttpStatusCode.OK, workflowResponse.StatusCode)); |
| 58 | + |
| 59 | + // Check action result |
| 60 | + Assert.AreEqual(ActionStatus.Succeeded, testRunner.GetWorkflowActionStatus("Get_Customers_from_Service_One")); |
| 61 | + Assert.AreEqual(ActionStatus.Succeeded, testRunner.GetWorkflowActionStatus("Success_Response")); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments