public void GetAzureContextNoLogin() { var cmdlt = new GetAzureRMContextCommand(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.DisableDataCollection(); var profile = AzureRmProfileProvider.Instance.Profile; AzureRmProfileProvider.Instance.Profile = new AzureRmProfile(); try { // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); } finally { AzureRmProfileProvider.Instance.Profile = profile; } // Verify Assert.True(commandRuntimeMock.OutputPipeline.Count == 0); }
public void GetAzureContextNoLogin() { var cmdlt = new GetAzureRMContextCommand(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.DisableDataCollection(); var profile = AzureRmProfileProvider.Instance.Profile; AzureRmProfileProvider.Instance.Profile = new AzureRmProfile(); try { // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); } finally { AzureRmProfileProvider.Instance.Profile = profile; } // Verify Assert.True(commandRuntimeMock.OutputPipeline.Count == 1); var context = (PSAzureContext)commandRuntimeMock.OutputPipeline[0]; Assert.True(context == null || context.Account == null || context.Account.Id == null); Assert.True(commandRuntimeMock.ErrorStream.Count == 1); var error = commandRuntimeMock.ErrorStream[0]; Assert.Equal("Run Connect-AzureRmAccount to login.", error.Exception.Message); }