Skip to content

Commit fac21e3

Browse files
authored
Added functionality to specify managed api connections to Mock (#38)
Co-authored-by: Zach Herberstein <Zach.herberstein@chcs.com.au>
1 parent f5308ad commit fac21e3

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/LogicAppUnit/TestConfiguration.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ public class TestConfigurationWorkflow
132132
/// </summary>
133133
public List<string> BuiltInConnectorsToMock { get; set; } = new List<string>();
134134

135+
136+
/// <summary>
137+
/// List of managed api connectors where the actions are to be replaced with HTTP actions referencing the test mock server.
138+
/// </summary>
139+
public List<string> ManagedApisToMock { get; set; } = new List<string>();
140+
141+
135142
/// <summary>
136143
/// <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>.
137144
/// </summary>

src/LogicAppUnit/WorkflowTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ private void ProcessConnectionsFile(string logicAppBasePath)
277277

278278
_connections = new ConnectionsWrapper(ReadFromPath(Path.Combine(logicAppBasePath, Constants.CONNECTIONS), optional: true), _localSettings);
279279

280-
_connections.ReplaceManagedApiConnectionUrlsWithMockServer();
280+
_connections.ReplaceManagedApiConnectionUrlsWithMockServer(_testConfig.Workflow?.ManagedApisToMock);
281281

282282
// The Functions runtime will not start if there are any Managed API connections using the 'ManagedServiceIdentity' authentication type
283283
// Check for this so that the test will fail early with a meaningful error message

src/LogicAppUnit/Wrapper/ConnectionsWrapper.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,20 @@ public override string ToString()
4646

4747
/// <summary>
4848
/// Update the <i>connections</i> by replacing all URL references to managed API connectors with the URL reference for the mock test server.
49+
/// <param name="managedApisToMock">The list of managed API connections to mock, or <c>null</c> if the file does not exist.</param>
4950
/// </summary>
50-
public void ReplaceManagedApiConnectionUrlsWithMockServer()
51+
52+
public void ReplaceManagedApiConnectionUrlsWithMockServer(List<string> managedApisToMock)
5153
{
5254
if (_jObjectConnection == null)
5355
return;
5456

5557
var managedApiConnections = _jObjectConnection.SelectToken("managedApiConnections").Children<JProperty>().ToList();
58+
59+
// If no managed apis are specified then all managed apis are mocked
60+
if (managedApisToMock != null && managedApisToMock.Count > 0)
61+
managedApiConnections = managedApiConnections.Where(con => managedApisToMock.Contains(con.Name)).ToList();
62+
5663
if (managedApiConnections.Count > 0)
5764
{
5865
Console.WriteLine("Updating connections file for managed API connectors:");

0 commit comments

Comments
 (0)