public void ClearMultipleContexts() { var cmdlet = new ClearAzureRmContext(); var profile = CreateMultipleContextProfile(); var defaultContext = profile.DefaultContext; var cacheType = profile.DefaultContext.TokenCache.GetType(); cmdlet.CommandRuntime = commandRuntimeMock; cmdlet.DefaultProfile = profile; cmdlet.Scope = ContextModificationScope.Process; cmdlet.PassThru = true; cmdlet.InvokeBeginProcessing(); cmdlet.ExecuteCmdlet(); cmdlet.InvokeEndProcessing(); Assert.NotNull(commandRuntimeMock.OutputPipeline); Assert.Single(commandRuntimeMock.OutputPipeline); bool testResult = (bool)commandRuntimeMock.OutputPipeline[0]; Assert.True(testResult); Assert.Equal(1, profile.Contexts.Count); Assert.NotNull(profile.DefaultContext); Assert.Null(profile.DefaultContext.Account); Assert.Null(profile.DefaultContext.Subscription); Assert.NotNull(profile.DefaultContext.TokenCache); Assert.Equal(AzureSession.Instance.TokenCache.GetType(), profile.DefaultContext.TokenCache.GetType()); }
public void ClearContextNoLogin() { var cmdlet = new ClearAzureRmContext(); var profile = new AzureRmProfile(); cmdlet.CommandRuntime = commandRuntimeMock; cmdlet.DefaultProfile = profile; cmdlet.PassThru = true; cmdlet.Scope = ContextModificationScope.Process; cmdlet.InvokeBeginProcessing(); cmdlet.ExecuteCmdlet(); cmdlet.InvokeEndProcessing(); Assert.NotNull(commandRuntimeMock.OutputPipeline); Assert.Single(commandRuntimeMock.OutputPipeline); bool testResult = (bool)commandRuntimeMock.OutputPipeline[0]; Assert.True(testResult); Assert.Equal(1, profile.Contexts.Count); Assert.NotNull(profile.DefaultContext); Assert.Null(profile.DefaultContext.Account); Assert.Null(profile.DefaultContext.Subscription); }
public void ClearContextSetsDefaultContextName() { var getCmdlet = new GetAzureRMContextCommand(); var profile = CreateMultipleContextProfile(); var defaultContextName = profile.DefaultContextKey; getCmdlet.CommandRuntime = commandRuntimeMock; getCmdlet.DefaultProfile = profile; getCmdlet.InvokeBeginProcessing(); getCmdlet.ExecuteCmdlet(); getCmdlet.InvokeEndProcessing(); Assert.True(commandRuntimeMock.OutputPipeline != null); Assert.Single(commandRuntimeMock.OutputPipeline); Assert.Equal(defaultContextName, ((PSAzureContext)commandRuntimeMock.OutputPipeline[0]).Name); var clearCmdlet = new ClearAzureRmContext(); commandRuntimeMock = new MockCommandRuntime(); clearCmdlet.CommandRuntime = commandRuntimeMock; clearCmdlet.DefaultProfile = profile; clearCmdlet.Scope = ContextModificationScope.Process; clearCmdlet.PassThru = true; clearCmdlet.InvokeBeginProcessing(); clearCmdlet.ExecuteCmdlet(); clearCmdlet.InvokeEndProcessing(); Assert.NotNull(commandRuntimeMock.OutputPipeline); Assert.Single(commandRuntimeMock.OutputPipeline); var result = (bool)commandRuntimeMock.OutputPipeline[0]; Assert.True(result); Assert.True(profile.Contexts != null); Assert.Equal(1, profile.Contexts.Count); Assert.True(profile.Contexts.ContainsKey("Default")); Assert.NotNull(profile.DefaultContext); Assert.Null(profile.DefaultContext.Account); Assert.Null(profile.DefaultContext.Subscription); }