Skip to content

Commit ff4bde9

Browse files
committed
Add extension methods to enable and disable data collection for tests
1 parent 33c51f7 commit ff4bde9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Common/Commands.Common/Extensions/CmdletExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.WindowsAzure.Commands.Common;
1516
using System;
1617
using System.Collections.Generic;
1718
using System.Collections.ObjectModel;
@@ -216,6 +217,18 @@ public static void InvokeEndProcessing(this PSCmdlet cmdlt)
216217
dynMethod.Invoke(cmdlt, null);
217218
}
218219

220+
public static void EnableDataCollection(this AzurePSCmdlet cmdlt)
221+
{
222+
FieldInfo dynField = (typeof(AzurePSCmdlet)).GetField("_dataCollectionProfile", BindingFlags.NonPublic | BindingFlags.Static);
223+
dynField.SetValue(cmdlt, new AzurePSDataCollectionProfile(true));
224+
}
225+
226+
public static void DisableDataCollection(this AzurePSCmdlet cmdlt)
227+
{
228+
FieldInfo dynField = (typeof(AzurePSCmdlet)).GetField("_dataCollectionProfile", BindingFlags.NonPublic | BindingFlags.Static);
229+
dynField.SetValue(cmdlt, new AzurePSDataCollectionProfile(false));
230+
}
231+
219232
#endregion
220233
}
221234
}

src/ResourceManager/Profile/Commands.Profile.Test/ContextCmdletTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public ContextCmdletTests(ITestOutputHelper output)
4444
AzureSession.Instance.DataStore = dataStore;
4545
commandRuntimeMock = new MockCommandRuntime();
4646
AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory();
47-
Environment.SetEnvironmentVariable(AzurePSDataCollectionProfile.EnvironmentVariableName, "false");
4847
}
4948

5049
[Fact]
@@ -75,6 +74,7 @@ public void GetAzureContextNoLogin()
7574

7675
// Setup
7776
cmdlt.CommandRuntime = commandRuntimeMock;
77+
cmdlt.DisableDataCollection();
7878
var profile = AzureRmProfileProvider.Instance.Profile;
7979
AzureRmProfileProvider.Instance.Profile = new AzureRmProfile();
8080

0 commit comments

Comments
 (0)