diff --git a/src/LogicAppUnit/TestConfiguration.cs b/src/LogicAppUnit/TestConfiguration.cs index 42ea60e..fc3bc56 100644 --- a/src/LogicAppUnit/TestConfiguration.cs +++ b/src/LogicAppUnit/TestConfiguration.cs @@ -132,6 +132,13 @@ public class TestConfigurationWorkflow /// public List BuiltInConnectorsToMock { get; set; } = new List(); + + /// + /// List of managed api connectors where the actions are to be replaced with HTTP actions referencing the test mock server. + /// + public List ManagedApisToMock { get; set; } = new List(); + + /// /// true if the test framework automatically configures the OperationOptions setting to WithStatelessRunHistory for a stateless workflow, otherwise false. /// diff --git a/src/LogicAppUnit/WorkflowTestBase.cs b/src/LogicAppUnit/WorkflowTestBase.cs index c841b3b..1a45d06 100644 --- a/src/LogicAppUnit/WorkflowTestBase.cs +++ b/src/LogicAppUnit/WorkflowTestBase.cs @@ -277,7 +277,7 @@ private void ProcessConnectionsFile(string logicAppBasePath) _connections = new ConnectionsWrapper(ReadFromPath(Path.Combine(logicAppBasePath, Constants.CONNECTIONS), optional: true), _localSettings); - _connections.ReplaceManagedApiConnectionUrlsWithMockServer(); + _connections.ReplaceManagedApiConnectionUrlsWithMockServer(_testConfig.Workflow?.ManagedApisToMock); // The Functions runtime will not start if there are any Managed API connections using the 'ManagedServiceIdentity' authentication type // Check for this so that the test will fail early with a meaningful error message diff --git a/src/LogicAppUnit/Wrapper/ConnectionsWrapper.cs b/src/LogicAppUnit/Wrapper/ConnectionsWrapper.cs index 02d11cc..f562a6e 100644 --- a/src/LogicAppUnit/Wrapper/ConnectionsWrapper.cs +++ b/src/LogicAppUnit/Wrapper/ConnectionsWrapper.cs @@ -46,13 +46,20 @@ public override string ToString() /// /// Update the connections by replacing all URL references to managed API connectors with the URL reference for the mock test server. + /// The list of managed API connections to mock, or null if the file does not exist. /// - public void ReplaceManagedApiConnectionUrlsWithMockServer() + + public void ReplaceManagedApiConnectionUrlsWithMockServer(List managedApisToMock) { if (_jObjectConnection == null) return; var managedApiConnections = _jObjectConnection.SelectToken("managedApiConnections").Children().ToList(); + + // If no managed apis are specified then all managed apis are mocked + if (managedApisToMock != null && managedApisToMock.Count > 0) + managedApiConnections = managedApiConnections.Where(con => managedApisToMock.Contains(con.Name)).ToList(); + if (managedApiConnections.Count > 0) { Console.WriteLine("Updating connections file for managed API connectors:");