예제 #1
0
        public void RemoveNonDefaultContext()
        {
            var cmdlet            = new RemoveAzureRmContext();
            var profile           = CreateMultipleContextProfile();
            var removedContextKey = profile.Contexts.Keys.First(k => !string.Equals(k, profile.DefaultContextKey));
            var removedContext    = profile.Contexts[removedContextKey];
            var defaultContextKey = profile.DefaultContextKey;

            cmdlet.CommandRuntime = commandRuntimeMock;
            cmdlet.DefaultProfile = profile;
            cmdlet.PassThru       = true;
            cmdlet.MyInvocation.BoundParameters.Add("Name", removedContextKey);
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();
            Assert.True(commandRuntimeMock.OutputPipeline != null && commandRuntimeMock.OutputPipeline.Count == 1);
            PSAzureContext testContext = commandRuntimeMock.OutputPipeline[0] as PSAzureContext;

            Assert.NotNull(testContext);
            Assert.NotNull(testContext.Name);
            Assert.True(removedContext.IsEqual(testContext));
            Assert.False(profile.Contexts.ContainsKey(removedContextKey));
            Assert.DoesNotContain(profile.Contexts, c => removedContext.IsEqual(c.Value));
            Assert.Equal(defaultContextKey, profile.DefaultContextKey);
        }
예제 #2
0
        public void RemoveDefaultContext()
        {
            var cmdlet             = new RemoveAzureRmContext();
            var profile            = CreateMultipleContextProfile();
            var defaultContext     = profile.DefaultContext;
            var defaultContextName = profile.DefaultContextKey;

            cmdlet.CommandRuntime = commandRuntimeMock;
            cmdlet.DefaultProfile = profile;
            cmdlet.Force          = true;
            cmdlet.PassThru       = true;
            cmdlet.MyInvocation.BoundParameters.Add("Name", profile.DefaultContextKey);
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();
            Assert.True(commandRuntimeMock.OutputPipeline != null && commandRuntimeMock.OutputPipeline.Count == 1);
            PSAzureContext testContext = commandRuntimeMock.OutputPipeline[0] as PSAzureContext;

            Assert.NotNull(testContext);
            Assert.NotNull(testContext.Name);
            Assert.True(defaultContext.IsEqual(testContext));
            Assert.False(profile.Contexts.ContainsKey(defaultContextName));
            Assert.False(profile.Contexts.Any(c => defaultContext.IsEqual(c.Value)));
            Assert.False(string.IsNullOrEmpty(profile.DefaultContextKey));
            Assert.NotNull(profile.DefaultContext);
        }
예제 #3
0
        public void RemoveContextNoLogin()
        {
            var cmdlet            = new RemoveAzureRmContext();
            var profile           = new AzureRmProfile();
            var removedContextKey = "This context does not exist";
            var defaultContextKey = profile.DefaultContextKey;
            var contextCount      = profile.Contexts.Count;

            cmdlet.CommandRuntime = commandRuntimeMock;
            cmdlet.DefaultProfile = profile;
            cmdlet.PassThru       = true;
            cmdlet.MyInvocation.BoundParameters.Add("Name", removedContextKey);
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();
            Assert.NotNull(commandRuntimeMock.OutputPipeline);
            Assert.Empty(commandRuntimeMock.OutputPipeline);
            Assert.Equal(contextCount, profile.Contexts.Count);
        }