Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/LogicAppUnit/TestConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ public class TestConfigurationWorkflow
/// </summary>
public List<string> BuiltInConnectorsToMock { get; set; } = new List<string>();


/// <summary>
/// List of managed api connectors where the actions are to be replaced with HTTP actions referencing the test mock server.
/// </summary>
public List<string> ManagedApisToMock { get; set; } = new List<string>();


/// <summary>
/// <c>true</c> if the test framework automatically configures the <i>OperationOptions</i> setting to <i>WithStatelessRunHistory</i> for a stateless workflow, otherwise <c>false</c>.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/LogicAppUnit/WorkflowTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/LogicAppUnit/Wrapper/ConnectionsWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,20 @@ public override string ToString()

/// <summary>
/// Update the <i>connections</i> by replacing all URL references to managed API connectors with the URL reference for the mock test server.
/// <param name="managedApisToMock">The list of managed API connections to mock, or <c>null</c> if the file does not exist.</param>
/// </summary>
public void ReplaceManagedApiConnectionUrlsWithMockServer()

public void ReplaceManagedApiConnectionUrlsWithMockServer(List<string> managedApisToMock)
{
if (_jObjectConnection == null)
return;

var managedApiConnections = _jObjectConnection.SelectToken("managedApiConnections").Children<JProperty>().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:");
Expand Down