예제 #1
0
        public void SelectNonExistentContext()
        {
            var cmdlet             = new SelectAzureRmContext();
            var profile            = CreateMultipleContextProfile();
            var defaultContext     = profile.DefaultContext;
            var defaultContextName = profile.DefaultContextKey;

            cmdlet.CommandRuntime = commandRuntimeMock;
            cmdlet.DefaultProfile = profile;
            cmdlet.MyInvocation.BoundParameters.Add("Name", "This context does not exist");
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();
            Assert.NotNull(commandRuntimeMock.OutputPipeline);
            Assert.Single(commandRuntimeMock.OutputPipeline);
            PSAzureContext testContext = commandRuntimeMock.OutputPipeline[0] as PSAzureContext;

            Assert.NotNull(testContext);
            Assert.NotNull(testContext.Name);
            Assert.True(defaultContext.IsEqual(testContext));
            Assert.True(profile.Contexts.ContainsKey(defaultContextName));
            Assert.True(defaultContext.IsEqual(profile.DefaultContext));
            Assert.False(string.IsNullOrEmpty(profile.DefaultContextKey));
            Assert.Equal(defaultContextName, profile.DefaultContextKey);
        }
예제 #2
0
        public void SelectNonDefaultContext()
        {
            var cmdlet              = new SelectAzureRmContext();
            var profile             = CreateMultipleContextProfile();
            var selectedContextName = profile.Contexts.Keys.First(k => !string.Equals(k, profile.DefaultContextKey));
            var selectedContext     = profile.Contexts[selectedContextName];

            Assert.NotNull(selectedContext);
            cmdlet.CommandRuntime = commandRuntimeMock;
            cmdlet.DefaultProfile = profile;
            cmdlet.MyInvocation.BoundParameters.Add("Name", selectedContextName);
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();
            Assert.NotNull(commandRuntimeMock.OutputPipeline);
            Assert.Equal(1, commandRuntimeMock.OutputPipeline.Count);
            PSAzureContext testContext = commandRuntimeMock.OutputPipeline[0] as PSAzureContext;

            Assert.NotNull(testContext);
            Assert.NotNull(testContext.Name);
            Assert.True(selectedContext.IsEqual(testContext));
            Assert.True(profile.Contexts.ContainsKey(selectedContextName));
            Assert.True(selectedContext.IsEqual(profile.DefaultContext));
            Assert.False(string.IsNullOrEmpty(profile.DefaultContextKey));
            Assert.Equal(selectedContextName, profile.DefaultContextKey);
        }