Inheritance: Microsoft.WindowsAzure.Commands.Utilities.Profile.SubscriptionCmdletBase
Ejemplo n.º 1
0
        public void ClearAzureProfileClearsDefaultProfile()
        {
            ClearAzureProfileCommand cmdlt = new ClearAzureProfileCommand();
            // Setup
            var profile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            AzurePSCmdlet.CurrentProfile = profile;
            ProfileClient client = new ProfileClient(profile);
            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.Profile.Save();

            cmdlt.CommandRuntime = commandRuntimeMock;
            cmdlt.Force = new SwitchParameter(true);

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            client = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
            Assert.Equal(0, client.Profile.Subscriptions.Count);
            Assert.Equal(0, client.Profile.Accounts.Count);
            Assert.Equal(2, client.Profile.Environments.Count); //only default environments
        }
Ejemplo n.º 2
0
        public void ClearAzureProfileClearsCustomProfile()
        {
            string subscriptionDataFile = "C:\\foo.json";

            ClearAzureProfileCommand cmdlt = new ClearAzureProfileCommand();
            // Setup
            ProfileClient client = new ProfileClient(subscriptionDataFile);
            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.Profile.Save();

            cmdlt.CommandRuntime = commandRuntimeMock;
            cmdlt.Force = new SwitchParameter(true);
            cmdlt.SubscriptionDataFile = subscriptionDataFile;

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            client = new ProfileClient(subscriptionDataFile);
            Assert.Equal(0, client.Profile.Subscriptions.Count);
            Assert.Equal(0, client.Profile.Accounts.Count);
            Assert.Equal(2, client.Profile.Environments.Count); //only default environments
        }
Ejemplo n.º 3
0
        public void ClearAzureProfileClearsTokenCache()
        {
            var profile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            AzurePSCmdlet.CurrentProfile = profile;
            ClearAzureProfileCommand cmdlt = new ClearAzureProfileCommand();
            AzureSession.DataStore = new MemoryDataStore();
            AzureSession.TokenCache = new ProtectedFileTokenCache(Path.Combine(AzureSession.ProfileDirectory, AzureSession.TokenCacheFile));

            cmdlt.CommandRuntime = commandRuntimeMock;
            cmdlt.Force = new SwitchParameter(true);

            // Act
            cmdlt.InvokeBeginProcessing();
            var tokenCache = AzureSession.TokenCache as ProtectedFileTokenCache;
            tokenCache.HasStateChanged = true;

            // HACK: Do not look at this code
            TokenCacheNotificationArgs args = new TokenCacheNotificationArgs();
            typeof(TokenCacheNotificationArgs).GetProperty("ClientId").SetValue(args, "123");
            typeof(TokenCacheNotificationArgs).GetProperty("Resource").SetValue(args, "123");
            typeof(TokenCacheNotificationArgs).GetProperty("TokenCache").SetValue(args, tokenCache);
            typeof(TokenCacheNotificationArgs).GetProperty("UniqueId").SetValue(args, "*****@*****.**");
            typeof(TokenCacheNotificationArgs).GetProperty("DisplayableId").SetValue(args, "*****@*****.**");
            AuthenticationResult authenticationResult =
                typeof(AuthenticationResult).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance,
                    null, new Type[] { typeof(string), typeof(string), typeof(string), typeof(DateTimeOffset) }, null).Invoke(new object[]
                    {
                        "foo", "123", "123",
                        new DateTimeOffset(DateTime.Now.AddDays(1))
                    }) as AuthenticationResult;
            var storeToCache = typeof(TokenCache).GetMethod("StoreToCache", BindingFlags.Instance | BindingFlags.NonPublic);
            storeToCache.Invoke(tokenCache,
                new object[] { authenticationResult, "Common", "123", "123", 0, null});

            tokenCache.AfterAccess.Invoke(args);

            Assert.Equal(1, tokenCache.ReadItems().Count());
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();
            // Verify
            Assert.Equal(0, tokenCache.ReadItems().Count());
        }