Beispiel #1
0
        /// <summary>
        /// Invoke the Enable-AzureServiceProjectRemoteDesktop enableRDCmdlet.
        /// </summary>
        /// <param name="username">Username.</param>
        /// <param name="password">Password.</param>
        public static void EnableRemoteDesktop(string username, string password)
        {
            SecureString securePassword = null;

            if (password != null)
            {
                securePassword = new SecureString();
                foreach (char ch in password)
                {
                    securePassword.AppendChar(ch);
                }
                securePassword.MakeReadOnly();
            }

            if (enableRDCmdlet == null)
            {
                enableRDCmdlet = new EnableAzureServiceProjectRemoteDesktopCommand();
                if (mockCommandRuntime == null)
                {
                    mockCommandRuntime = new MockCommandRuntime();
                }
                enableRDCmdlet.CommandRuntime = mockCommandRuntime;
            }

            enableRDCmdlet.Username = username;
            enableRDCmdlet.Password = securePassword;
            enableRDCmdlet.EnableRemoteDesktop();
        }
        public void SetAzureServiceProjectTestsLocationValid()
        {
            string[] locations = { "West US", "East US", "East Asia", "North Europe" };
            foreach (string item in locations)
            {
                using (FileSystemHelper files = new FileSystemHelper(this))
                {
                    // Create new empty settings file
                    //
                    ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                    ServiceSettings settings = new ServiceSettings();
                    mockCommandRuntime = new MockCommandRuntime();
                    setServiceProjectCmdlet.CommandRuntime = mockCommandRuntime;
                    settings.Save(paths.Settings);

                    settings = setServiceProjectCmdlet.SetAzureServiceProjectProcess(item, null, null, null, paths.Settings);

                    // Assert location is changed
                    //
                    Assert.AreEqual<string>(item, settings.Location);
                    ServiceSettings actualOutput = mockCommandRuntime.OutputPipeline[0] as ServiceSettings;
                    Assert.AreEqual<string>(item, settings.Location);
                }
            }
        }
        public void CreatesNewSBCaseInsensitiveRegion()
        {
            // Setup
            SimpleServiceBusManagement channel = new SimpleServiceBusManagement();
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            string name = "test";
            string location = "West US";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel)
            {
                Name = name,
                Location = "west Us",
                CommandRuntime = mockCommandRuntime
            };
            ServiceBusNamespace expected = new ServiceBusNamespace { Name = name, Region = location };
            channel.CreateServiceBusNamespaceThunk = csbn => { return expected; };
            channel.ListServiceBusRegionsThunk = lsbr =>
            {
                List<ServiceBusRegion> list = new List<ServiceBusRegion>();
                list.Add(new ServiceBusRegion { Code = location });
                return list;
            };

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            ServiceBusNamespace actual = mockCommandRuntime.OutputPipeline[0] as ServiceBusNamespace;
            Assert.AreEqual<ServiceBusNamespace>(expected, actual);
        }
        public void TestImportPublishSettingsWithMultiplePublishSettingsFilesFound()
        {
            MockCommandRuntime mockCommandRuntime;
            ImportAzurePublishSettingsCommand cmdlet;
            mockCommandRuntime = new MockCommandRuntime();
            cmdlet = new ImportAzurePublishSettingsCommand();
            cmdlet.CommandRuntime = mockCommandRuntime;
            cmdlet.SubscriptionClient = CreateMockSubscriptionClient();
            string directoryName = "testdir2";
            string fileName1 = "myfile1.publishsettings";
            string fileName2 = "myfile2.publishsettings";
            string filePath1 = Path.Combine(directoryName, fileName1);
            string filePath2 = Path.Combine(directoryName, fileName2);
            Directory.CreateDirectory(directoryName);
            File.WriteAllText(filePath1, File.ReadAllText(Data.ValidPublishSettings.First()));
            File.WriteAllText(filePath2, File.ReadAllText(Data.ValidPublishSettings.First()));
            cmdlet.PublishSettingsFile = directoryName;

            cmdlet.ExecuteCmdlet();

            SubscriptionData currentSubscription = cmdlet.GetCurrentSubscription();
            Assert.AreEqual(currentSubscription.SubscriptionName, Data.Subscription1);
            Assert.IsTrue(currentSubscription.IsDefault);
            Assert.AreEqual<string>(filePath1, mockCommandRuntime.OutputPipeline[0].ToString());
            Assert.AreEqual<string>(string.Format(Resources.MultiplePublishSettingsFilesFoundMessage, filePath1), mockCommandRuntime.WarningStream[0]);
        }
        /// <summary>
        /// Invoke the Enable-AzureServiceProjectRemoteDesktop enableRDCmdlet.
        /// </summary>
        /// <param name="username">Username.</param>
        /// <param name="password">Password.</param>
        public static void EnableRemoteDesktop(string username, string password)
        {
            SecureString securePassword = null;
            if (password != null)
            {
                securePassword = new SecureString();
                foreach (char ch in password)
                {
                    securePassword.AppendChar(ch);
                }
                securePassword.MakeReadOnly();
            }

            if (enableRDCmdlet == null)
            {
                enableRDCmdlet = new EnableAzureServiceProjectRemoteDesktopCommand();
                if (mockCommandRuntime == null)
                {
                    mockCommandRuntime = new MockCommandRuntime();
                }
                enableRDCmdlet.CommandRuntime = mockCommandRuntime;
            }

            enableRDCmdlet.Username = username;
            enableRDCmdlet.Password = securePassword;
            enableRDCmdlet.EnableRemoteDesktop();
        }
        public void GetAzureSqlDatabaseServerFirewallRuleProcessTest()
        {
            SqlDatabaseFirewallRulesList firewallList = new SqlDatabaseFirewallRulesList();
            MockCommandRuntime commandRuntime = new MockCommandRuntime();
            SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement();
            channel.NewServerFirewallRuleThunk = ar =>
            {
                Assert.AreEqual("Server1", (string)ar.Values["serverName"]);
                SqlDatabaseFirewallRule newRule = new SqlDatabaseFirewallRule();
                newRule.Name = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).Name;
                newRule.StartIPAddress = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).StartIPAddress;
                newRule.EndIPAddress = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).EndIPAddress;
                firewallList.Add(newRule);
            };

            channel.GetServerFirewallRulesThunk = ar =>
            {
                return firewallList;
            };

            // New firewall rule with IpRange parameter set
            NewAzureSqlDatabaseServerFirewallRule newAzureSqlDatabaseServerFirewallRule = new NewAzureSqlDatabaseServerFirewallRule(channel) { ShareChannel = true };
            newAzureSqlDatabaseServerFirewallRule.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            newAzureSqlDatabaseServerFirewallRule.CommandRuntime = commandRuntime;
            var newFirewallResult = newAzureSqlDatabaseServerFirewallRule.NewAzureSqlDatabaseServerFirewallRuleProcess("IpRange", "Server1", "Rule1", "0.0.0.0", "1.1.1.1");
            Assert.AreEqual("Success", newFirewallResult.OperationStatus);
            newFirewallResult = newAzureSqlDatabaseServerFirewallRule.NewAzureSqlDatabaseServerFirewallRuleProcess("IpRange", "Server1", "Rule2", "1.1.1.1", "2.2.2.2");
            Assert.AreEqual("Success", newFirewallResult.OperationStatus);

            // Get all rules
            GetAzureSqlDatabaseServerFirewallRule getAzureSqlDatabaseServerFirewallRule = new GetAzureSqlDatabaseServerFirewallRule(channel) { ShareChannel = true };
            getAzureSqlDatabaseServerFirewallRule.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            getAzureSqlDatabaseServerFirewallRule.CommandRuntime = commandRuntime;
            var getFirewallResult = getAzureSqlDatabaseServerFirewallRule.GetAzureSqlDatabaseServerFirewallRuleProcess("Server1", null);
            Assert.AreEqual(2, getFirewallResult.Count());
            var firstRule = getFirewallResult.First();
            Assert.AreEqual("Server1", firstRule.ServerName);
            Assert.AreEqual("Rule1", firstRule.RuleName);
            Assert.AreEqual("0.0.0.0", firstRule.StartIpAddress);
            Assert.AreEqual("1.1.1.1", firstRule.EndIpAddress);
            Assert.AreEqual("Success", firstRule.OperationStatus);
            var lastRule = getFirewallResult.Last();
            Assert.AreEqual("Server1", lastRule.ServerName);
            Assert.AreEqual("Rule2", lastRule.RuleName);
            Assert.AreEqual("1.1.1.1", lastRule.StartIpAddress);
            Assert.AreEqual("2.2.2.2", lastRule.EndIpAddress);
            Assert.AreEqual("Success", lastRule.OperationStatus);

            // Get one rule
            getFirewallResult = getAzureSqlDatabaseServerFirewallRule.GetAzureSqlDatabaseServerFirewallRuleProcess("Server1", "Rule2");
            Assert.AreEqual(1, getFirewallResult.Count());
            firstRule = getFirewallResult.First();
            Assert.AreEqual("Server1", firstRule.ServerName);
            Assert.AreEqual("Rule2", firstRule.RuleName);
            Assert.AreEqual("1.1.1.1", firstRule.StartIpAddress);
            Assert.AreEqual("2.2.2.2", firstRule.EndIpAddress);
            Assert.AreEqual("Success", firstRule.OperationStatus);

            Assert.AreEqual(0, commandRuntime.ErrorStream.Count);
        }
 public void SetupTest()
 {
     channel = new SimpleServiceManagement();
     serviceBusChannel = new SimpleServiceBusManagement();
     mockCommandRuntime = new MockCommandRuntime();
     cmdlet = new TestAzureNameCommand(channel, serviceBusChannel) { CommandRuntime = mockCommandRuntime };
     CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();
 }
        public void ProcessNewWebsiteTest()
        {
            const string websiteName = "website1";
            const string webspaceName = "webspace1";

            // Setup
            bool created = true;
            SimpleWebsitesManagement channel = new SimpleWebsitesManagement();
            channel.GetWebSpacesThunk = ar => new WebSpaces(new List<WebSpace>
            {
                new WebSpace { Name = "webspace1", GeoRegion = "webspace1" },
                new WebSpace { Name = "webspace2", GeoRegion = "webspace2" }
            });

            channel.GetSiteConfigThunk = ar =>
            {
                if (ar.Values["name"].Equals("website1") && ar.Values["webspaceName"].Equals("webspace1"))
                {
                    return new SiteConfig
                    {
                        PublishingUsername = "******"
                    };
                }

                return null;
            };

            channel.CreateSiteThunk = ar =>
                                          {
                                              Assert.AreEqual(webspaceName, ar.Values["webspaceName"]);
                                              Site website = ar.Values["site"] as Site;
                                              Assert.IsNotNull(website);
                                              Assert.AreEqual(websiteName, website.Name);
                                              Assert.IsNotNull(website.HostNames.FirstOrDefault(hostname => hostname.Equals(websiteName + General.AzureWebsiteHostNameSuffix)));
                                              created = true;
                                              return website;
                                          };

            // Test
            MockCommandRuntime mockRuntime = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand(channel)
            {
                ShareChannel = true,
                CommandRuntime = mockRuntime,
                Name = websiteName,
                Location = webspaceName,
                CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionName }
            };

            newAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsTrue(created);
            Assert.AreEqual<string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
        }
Beispiel #9
0
        public void SetupTest()
        {
            GlobalPathInfo.GlobalSettingsDirectory      = Data.AzureSdkAppDir;
            CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();
            mockCommandRuntime = new MockCommandRuntime();

            newServiceCmdlet   = new NewAzureServiceProjectCommand();
            addCacheRoleCmdlet = new AddAzureCacheWorkerRoleCommand();

            newServiceCmdlet.CommandRuntime   = mockCommandRuntime;
            addCacheRoleCmdlet.CommandRuntime = mockCommandRuntime;
        }
        public void SetupTest()
        {
            GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir;
            CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();
            mockCommandRuntime = new MockCommandRuntime();
            cloudServiceClientMock = new Mock<ICloudServiceClient>();

            stopServiceCmdlet = new StopAzureServiceCommand()
            {
                CloudServiceClient = cloudServiceClientMock.Object,
                CommandRuntime = mockCommandRuntime
            };
        }
        public void GetAzureSBNamespaceWithInvalidNamesFail()
        {
            // Setup
            string[] invalidNames = { "1test", "test#", "test invaid", "-test", "_test" };

            foreach (string invalidName in invalidNames)
            {
                MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
                GetAzureSBNamespaceCommand cmdlet = new GetAzureSBNamespaceCommand() { Name = invalidName, CommandRuntime = mockCommandRuntime };
                string expected = string.Format("{0}\r\nParameter name: Name", string.Format(Resources.InvalidNamespaceName, invalidName));

                Testing.AssertThrows<ArgumentException>(() => cmdlet.ExecuteCmdlet(), expected);
            }
        }
        public void SetupTest()
        {
            GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir;
            CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();
            mockCommandRuntime = new MockCommandRuntime();

            addNodeWebCmdlet = new AddAzureNodeWebRoleCommand();
            addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand();
            cmdlet = new SaveAzureServiceProjectPackageCommand();

            addNodeWorkerCmdlet.CommandRuntime = mockCommandRuntime;
            addNodeWebCmdlet.CommandRuntime = mockCommandRuntime;
            cmdlet.CommandRuntime = mockCommandRuntime;
        }
Beispiel #13
0
        public void SetupTest()
        {
            GlobalPathInfo.GlobalSettingsDirectory      = Data.AzureSdkAppDir;
            CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();
            mockCommandRuntime = new MockCommandRuntime();

            addNodeWebCmdlet    = new AddAzureNodeWebRoleCommand();
            addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand();
            enableRDCmdlet      = new EnableAzureServiceProjectRemoteDesktopCommand();

            addNodeWorkerCmdlet.CommandRuntime = mockCommandRuntime;
            addNodeWebCmdlet.CommandRuntime    = mockCommandRuntime;
            enableRDCmdlet.CommandRuntime      = mockCommandRuntime;
        }
        public void GetsWebsiteDefaultLocation()
        {
            const string websiteName = "website1";
            const string suffix = "azurewebsites.com";
            const string location = "West US";

            // Setup
            Mock<IWebsitesClient> clientMock = new Mock<IWebsitesClient>();
            clientMock.Setup(f => f.GetWebsiteDnsSuffix()).Returns(suffix);
            clientMock.Setup(f => f.GetDefaultLocation()).Returns(location);
            bool created = true;
            SimpleWebsitesManagement channel = new SimpleWebsitesManagement();
            channel.GetWebSpacesThunk = ar => new WebSpaces();

            channel.GetSiteConfigThunk = ar =>
            {
                return new SiteConfig
                {
                    PublishingUsername = "******"
                };
            };

            channel.CreateSiteThunk = ar =>
            {
                Site website = ar.Values["site"] as Site;
                Assert.IsNotNull(website);
                Assert.AreEqual(websiteName, website.Name);
                Assert.IsNotNull(website.HostNames.FirstOrDefault(hostname => hostname.Equals(string.Format("{0}.{1}", websiteName, suffix))));
                created = true;
                return website;
            };

            // Test
            MockCommandRuntime mockRuntime = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand(channel)
            {
                ShareChannel = true,
                CommandRuntime = mockRuntime,
                Name = websiteName,
                CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionId },
                WebsitesClient = clientMock.Object
            };

            newAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsTrue(created);
            Assert.AreEqual<string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
            clientMock.Verify(f => f.GetDefaultLocation(), Times.Once());
        }
        public void RemoveAzureSBNamespaceSuccessfull()
        {
            // Setup
            SimpleServiceBusManagement channel = new SimpleServiceBusManagement();
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            string name = "test";
            RemoveAzureSBNamespaceCommand cmdlet = new RemoveAzureSBNamespaceCommand(channel) { Name = name, CommandRuntime = mockCommandRuntime, PassThru = true };
            bool deleted = false;
            channel.DeleteServiceBusNamespaceThunk = dsbn => { deleted = true; };

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            Assert.IsTrue(deleted);
            Assert.IsTrue((bool)mockCommandRuntime.OutputPipeline[0]);
        }
        public void RemoveAzureSBNamespaceWithInternalServerError()
        {
            // Setup
            SimpleServiceBusManagement channel = new SimpleServiceBusManagement();
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            string name = "test";
            RemoveAzureSBNamespaceCommand cmdlet = new RemoveAzureSBNamespaceCommand(channel) { Name = name, CommandRuntime = mockCommandRuntime };
            string expected = Resources.RemoveNamespaceErrorMessage;
            channel.DeleteServiceBusNamespaceThunk = dsbn => { throw new Exception(Resources.InternalServerErrorMessage); };

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            ErrorRecord actual = mockCommandRuntime.ErrorStream[0];
            Assert.AreEqual<string>(expected, actual.Exception.Message);
        }
        public void AddAzurePHPWorkerRoleProcess()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string roleName = "WorkerRole1";
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                mockCommandRuntime = new MockCommandRuntime();
                addPHPWorkerCmdlet = new AddAzurePHPWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime };
                string expectedVerboseMessage = string.Format(Resources.AddRoleMessageCreatePHP, rootPath, roleName);

                addPHPWorkerCmdlet.ExecuteCmdlet();

                AzureAssert.ScaffoldingExists(Path.Combine(rootPath, roleName), Path.Combine(Resources.PHPScaffolding, Resources.WorkerRole));
                Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).GetVariableValue<string>(Parameters.RoleName));
                Assert.AreEqual<string>(expectedVerboseMessage, mockCommandRuntime.VerboseStream[0]);
            }
        }
        public void NewAzureSBNamespaceWithInvalidLocation()
        {
            // Setup
            SimpleServiceBusManagement channel = new SimpleServiceBusManagement();
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            string name = "test";
            string location = "Invalid location";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel) { Name = name, Location = location, CommandRuntime = mockCommandRuntime };
            channel.ListServiceBusRegionsThunk = lsbr =>
            {
                List<ServiceBusRegion> list = new List<ServiceBusRegion>();
                list.Add(new ServiceBusRegion { Code = "West US" });
                return list;
            };
            string expected = string.Format("{0}\r\nParameter name: Location", string.Format(Resources.InvalidServiceBusLocation, location));

            Testing.AssertThrows<ArgumentException>(() => cmdlet.ExecuteCmdlet(), expected);
        }
        public void RemoveAzureSBNamespaceWithInvalidNamesFail()
        {
            // Setup
            string[] invalidNames = { "1test", "test#", "test invaid", "-test", "_test" };

            foreach (string invalidName in invalidNames)
            {
                MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
                RemoveAzureSBNamespaceCommand cmdlet = new RemoveAzureSBNamespaceCommand() { Name = invalidName, CommandRuntime = mockCommandRuntime };
                ArgumentException expected = new ArgumentException(string.Format(Resources.InvalidNamespaceName, invalidName), "Name");

                // Test
                cmdlet.ExecuteCmdlet();

                // Assert
                ErrorRecord actual = mockCommandRuntime.ErrorStream[0];
                Assert.AreEqual<string>(expected.Message, actual.Exception.Message);
            }
        }
        public void NewAzureSBNamespaceWithInternalServerError()
        {
            // Setup
            SimpleServiceBusManagement channel = new SimpleServiceBusManagement();
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            string name = "test";
            string location = "West US";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel) { Name = name, Location = location, CommandRuntime = mockCommandRuntime };
            channel.CreateServiceBusNamespaceThunk = csbns => { throw new Exception(Resources.InternalServerErrorMessage); };
            channel.ListServiceBusRegionsThunk = lsbr =>
            {
                List<ServiceBusRegion> list = new List<ServiceBusRegion>();
                list.Add(new ServiceBusRegion { Code = location });
                return list;
            };
            string expected = Resources.NewNamespaceErrorMessage;

            Testing.AssertThrows<Exception>(() => cmdlet.ExecuteCmdlet(), expected);
        }
        public void TestImportPublishSettingsWithNoPublishSettingsFilesFound()
        {
            MockCommandRuntime mockCommandRuntime;
            ImportAzurePublishSettingsCommand cmdlet;
            mockCommandRuntime = new MockCommandRuntime();
            cmdlet = new ImportAzurePublishSettingsCommand();
            cmdlet.CommandRuntime = mockCommandRuntime;
            cmdlet.SubscriptionClient = CreateMockSubscriptionClient();
            string directoryName = "testdir3";
            string originalDirectory = Directory.GetCurrentDirectory();
            Directory.CreateDirectory(directoryName);
            Directory.SetCurrentDirectory(Path.GetFullPath(directoryName));

            Testing.AssertThrows<Exception>(
                () => cmdlet.ExecuteCmdlet(),
                string.Format(Resources.NoPublishSettingsFilesFoundMessage, Directory.GetCurrentDirectory()));
            Directory.SetCurrentDirectory(originalDirectory);
            Assert.AreEqual<string>(originalDirectory, Directory.GetCurrentDirectory());
        }
        public void TestRemoveDefaultSubscriptionProcess()
        {
            for (var i = 0; i < Data.ValidPublishSettings.Count; i++)
            {
                var targetFile = Path.Combine(Directory.GetParent(Data.ValidSubscriptionsData[i]).FullName, "removeonce" + Path.GetFileName(Data.ValidSubscriptionsData[i]));
                File.Copy(Data.ValidSubscriptionsData[i], targetFile, true);
                var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, targetFile, Data.ValidPublishSettings[i]);
                MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
                var removeSubscriptionCommand = new RemoveAzureSubscriptionCommand();
                removeSubscriptionCommand.CommandRuntime = mockCommandRuntime;
                removeSubscriptionCommand.RemoveSubscriptionProcess("mysub1", targetFile);

                var subscriptionsManager = SubscriptionsManager.Import(targetFile);
                Assert.IsFalse(subscriptionsManager.Subscriptions.Values.Any(subscription => subscription.SubscriptionName == "mysub1"));
                Assert.IsFalse(subscriptionsManager.Subscriptions.Values.Any(subscription => subscription.IsDefault));

                // Clean
                globalSettingsManager.DeleteGlobalSettingsManager();
            }
        }
        public void SetAzureServiceProjectTestsLocationValid()
        {
            foreach (KeyValuePair<LocationName, string> item in ArgumentConstants.Locations)
            {
                using (FileSystemHelper files = new FileSystemHelper(this))
                {
                    // Create new empty settings file
                    //
                    ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                    ServiceSettings settings = new ServiceSettings();
                    mockCommandRuntime = new MockCommandRuntime();
                    setServiceProjectCmdlet.CommandRuntime = mockCommandRuntime;
                    settings.Save(paths.Settings);

                    settings = setServiceProjectCmdlet.SetAzureServiceProjectProcess(item.Value, null, null, null, paths.Settings);

                    // Assert location is changed
                    //
                    Assert.AreEqual<string>(item.Value, settings.Location);
                    ServiceSettings actualOutput = mockCommandRuntime.OutputPipeline[0] as ServiceSettings;
                    Assert.AreEqual<string>(item.Value, settings.Location);
                }
            }
        }
        public void GetAzureSBLocationSuccessfull()
        {
            // Setup
            SimpleServiceBusManagement channel = new SimpleServiceBusManagement();
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            string name = "test";
            GetAzureSBLocationCommand cmdlet = new GetAzureSBLocationCommand(channel) { CommandRuntime = mockCommandRuntime };
            List<ServiceBusRegion> expected = new List<ServiceBusRegion>();
            expected.Add(new ServiceBusRegion { Code = name, FullName = name });
            channel.ListServiceBusRegionsThunk = gn => { return expected; };

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            List<ServiceBusRegion> actual = mockCommandRuntime.OutputPipeline[0] as List<ServiceBusRegion>;
            Assert.AreEqual<int>(expected.Count, actual.Count);

            for (int i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual<string>(expected[i].Code, actual[i].Code);
                Assert.AreEqual<string>(expected[i].FullName, actual[i].FullName);
            }
        }
 public void TestSetup()
 {
     mockCommandRuntime = new MockCommandRuntime();
     newServiceCmdlet = new NewAzureServiceProjectCommand();
     newServiceCmdlet.CommandRuntime = mockCommandRuntime;
 }
 public void TestSetup()
 {
     mockCommandRuntime = new MockCommandRuntime();
     cmdlet = new SetAzureServiceProjectRoleCommand();
     cmdlet.CommandRuntime = mockCommandRuntime;
     cmdlet.PassThru = true;
 }
        public void SetupTest()
        {
            GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir;
            CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();
            mockCommandRuntime = new MockCommandRuntime();

            setServiceProjectCmdlet = new SetAzureServiceProjectCommand();
            setServiceProjectCmdlet.CommandRuntime = mockCommandRuntime;
            setServiceProjectCmdlet.PassThru = true;
        }
        public void SetAzureServiceProjectTestsStorageTests()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Create new empty settings file
                //
                ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                ServiceSettings settings = new ServiceSettings();
                mockCommandRuntime = new MockCommandRuntime();
                setServiceProjectCmdlet.CommandRuntime = mockCommandRuntime;
                settings.Save(paths.Settings);

                settings = setServiceProjectCmdlet.SetAzureServiceProjectProcess(null, null, "companystore", null, paths.Settings);

                // Assert storageAccountName is changed
                //
                Assert.AreEqual<string>("companystore", settings.StorageServiceName);
                ServiceSettings actualOutput = mockCommandRuntime.OutputPipeline[0] as ServiceSettings;
                Assert.AreEqual<string>("companystore", settings.StorageServiceName);
            }
        }
        public void SetupTest()
        {
            GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir;
            CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();
            mockCommandRuntime = new MockCommandRuntime();

            disableRDCmdlet = new DisableAzureServiceProjectRemoteDesktopCommand();
            disableRDCmdlet.CommandRuntime = mockCommandRuntime;
        }
 public void SetupTest()
 {
     cmdlet = new NewAzureServiceProjectCommand();
     mockCommandRuntime = new MockCommandRuntime();
     cmdlet.CommandRuntime = mockCommandRuntime;
 }
        public void NewAzureSqlDatabaseServerFirewallRuleProcessTest()
        {
            MockCommandRuntime commandRuntime = new MockCommandRuntime();
            SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement();
            bool newFirewallRuleCalled = false;
            channel.NewServerFirewallRuleThunk = ar =>
            {
                newFirewallRuleCalled = true;
                Assert.AreEqual("Server1", (string)ar.Values["serverName"]);
                Assert.AreEqual("Rule1", ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).Name);
                Assert.AreEqual("0.0.0.0", ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).StartIPAddress);
                Assert.AreEqual("1.1.1.1", ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).EndIPAddress);
            };

            // New firewall rule with IpRange parameter set
            NewAzureSqlDatabaseServerFirewallRule newAzureSqlDatabaseServerFirewallRule = new NewAzureSqlDatabaseServerFirewallRule(channel) { ShareChannel = true };
            newAzureSqlDatabaseServerFirewallRule.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            newAzureSqlDatabaseServerFirewallRule.CommandRuntime = commandRuntime;
            var newFirewallResult = newAzureSqlDatabaseServerFirewallRule.NewAzureSqlDatabaseServerFirewallRuleProcess("IpRange", "Server1", "Rule1", "0.0.0.0", "1.1.1.1");
            Assert.AreEqual("Server1", newFirewallResult.ServerName);
            Assert.AreEqual("Rule1", newFirewallResult.RuleName);
            Assert.AreEqual("0.0.0.0", newFirewallResult.StartIpAddress);
            Assert.AreEqual("1.1.1.1", newFirewallResult.EndIpAddress);
            Assert.AreEqual("Success", newFirewallResult.OperationStatus);
            Assert.AreEqual(true, newFirewallRuleCalled);
            Assert.AreEqual(0, commandRuntime.ErrorStream.Count);
        }
        public void RemoveAzureSqlDatabaseServerFirewallRuleProcessTest()
        {
            SqlDatabaseFirewallRulesList firewallList = new SqlDatabaseFirewallRulesList();
            MockCommandRuntime commandRuntime = new MockCommandRuntime();
            SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement();
            channel.NewServerFirewallRuleThunk = ar =>
            {
                Assert.AreEqual("Server1", (string)ar.Values["serverName"]);
                SqlDatabaseFirewallRule newRule = new SqlDatabaseFirewallRule();
                newRule.Name = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).Name;
                newRule.StartIPAddress = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).StartIPAddress;
                newRule.EndIPAddress = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).EndIPAddress;
                firewallList.Add(newRule);
            };

            channel.GetServerFirewallRulesThunk = ar =>
            {
                return firewallList;
            };

            channel.RemoveServerFirewallRuleThunk = ar =>
            {
                Assert.AreEqual("Server1", (string)ar.Values["serverName"]);
                string ruleName = (string)ar.Values["ruleName"];
                var ruleToDelete = firewallList.SingleOrDefault((rule) => rule.Name == ruleName);
                if (ruleToDelete == null)
                {
                    throw new CommunicationException("Firewall rule does not exist!");
                }

                firewallList.Remove(ruleToDelete);
            };

            // New firewall rule with IpRange parameter set
            NewAzureSqlDatabaseServerFirewallRule newAzureSqlDatabaseServerFirewallRule = new NewAzureSqlDatabaseServerFirewallRule(channel) { ShareChannel = true };
            newAzureSqlDatabaseServerFirewallRule.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            newAzureSqlDatabaseServerFirewallRule.CommandRuntime = commandRuntime;
            var newFirewallResult = newAzureSqlDatabaseServerFirewallRule.NewAzureSqlDatabaseServerFirewallRuleProcess("IpRange", "Server1", "Rule1", "0.0.0.0", "1.1.1.1");
            Assert.AreEqual("Success", newFirewallResult.OperationStatus);
            newFirewallResult = newAzureSqlDatabaseServerFirewallRule.NewAzureSqlDatabaseServerFirewallRuleProcess("IpRange", "Server1", "Rule2", "1.1.1.1", "2.2.2.2");
            Assert.AreEqual("Success", newFirewallResult.OperationStatus);

            // Get all rules
            GetAzureSqlDatabaseServerFirewallRule getAzureSqlDatabaseServerFirewallRule = new GetAzureSqlDatabaseServerFirewallRule(channel) { ShareChannel = true };
            getAzureSqlDatabaseServerFirewallRule.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            getAzureSqlDatabaseServerFirewallRule.CommandRuntime = commandRuntime;
            var getFirewallResult = getAzureSqlDatabaseServerFirewallRule.GetAzureSqlDatabaseServerFirewallRuleProcess("Server1", null);
            Assert.AreEqual(2, getFirewallResult.Count());

            // Remove Rule1
            RemoveAzureSqlDatabaseServerFirewallRule removeAzureSqlDatabaseServerFirewallRule = new RemoveAzureSqlDatabaseServerFirewallRule(channel) { ShareChannel = true };
            removeAzureSqlDatabaseServerFirewallRule.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            removeAzureSqlDatabaseServerFirewallRule.CommandRuntime = commandRuntime;
            var removeServerContext = removeAzureSqlDatabaseServerFirewallRule.RemoveAzureSqlDatabaseServerFirewallRuleProcess("Server1", "Rule1");

            // Verify only one rule is left
            getFirewallResult = getAzureSqlDatabaseServerFirewallRule.GetAzureSqlDatabaseServerFirewallRuleProcess("Server1", null);
            Assert.AreEqual(1, getFirewallResult.Count());
            var firstRule = getFirewallResult.First();
            Assert.AreEqual("Server1", firstRule.ServerName);
            Assert.AreEqual("Rule2", firstRule.RuleName);
            Assert.AreEqual("1.1.1.1", firstRule.StartIpAddress);
            Assert.AreEqual("2.2.2.2", firstRule.EndIpAddress);
            Assert.AreEqual("Success", firstRule.OperationStatus);

            Assert.AreEqual(0, commandRuntime.ErrorStream.Count);

            // Remove Rule1 again
            removeServerContext = removeAzureSqlDatabaseServerFirewallRule.RemoveAzureSqlDatabaseServerFirewallRuleProcess("Server1", "Rule1");
            Assert.AreEqual(1, commandRuntime.ErrorStream.Count);
            Assert.IsTrue(commandRuntime.WarningStream.Count > 0);
        }
        public void SetAzureSqlDatabaseServerFirewallRuleProcessTest()
        {
            SqlDatabaseFirewallRulesList firewallList = new SqlDatabaseFirewallRulesList();
            MockCommandRuntime commandRuntime = new MockCommandRuntime();
            SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement();
            channel.NewServerFirewallRuleThunk = ar =>
            {
                Assert.AreEqual("Server1", (string)ar.Values["serverName"]);
                SqlDatabaseFirewallRule newRule = new SqlDatabaseFirewallRule();
                newRule.Name = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).Name;
                newRule.StartIPAddress = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).StartIPAddress;
                newRule.EndIPAddress = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).EndIPAddress;
                firewallList.Add(newRule);
            };

            channel.GetServerFirewallRulesThunk = ar =>
            {
                return firewallList;
            };

            channel.UpdateServerFirewallRuleThunk = ar =>
            {
                string ruleName = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).Name;
                Assert.AreEqual(ruleName, (string)ar.Values["ruleName"]);
                var ruleToUpdate = firewallList.SingleOrDefault((rule) => rule.Name == ruleName);
                if (ruleToUpdate == null)
                {
                    throw new CommunicationException("Firewall rule does not exist!");
                }

                ruleToUpdate.StartIPAddress = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).StartIPAddress;
                ruleToUpdate.EndIPAddress = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).EndIPAddress;
            };

            // New firewall rule with IpRange parameter set
            NewAzureSqlDatabaseServerFirewallRule newAzureSqlDatabaseServerFirewallRule = new NewAzureSqlDatabaseServerFirewallRule(channel) { ShareChannel = true };
            newAzureSqlDatabaseServerFirewallRule.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            newAzureSqlDatabaseServerFirewallRule.CommandRuntime = commandRuntime;
            var newFirewallResult = newAzureSqlDatabaseServerFirewallRule.NewAzureSqlDatabaseServerFirewallRuleProcess("IpRange", "Server1", "Rule1", "0.0.0.0", "1.1.1.1");
            Assert.AreEqual("Success", newFirewallResult.OperationStatus);

            // Get the rule
            GetAzureSqlDatabaseServerFirewallRule getAzureSqlDatabaseServerFirewallRule = new GetAzureSqlDatabaseServerFirewallRule(channel) { ShareChannel = true };
            getAzureSqlDatabaseServerFirewallRule.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            getAzureSqlDatabaseServerFirewallRule.CommandRuntime = commandRuntime;
            var getFirewallResult = getAzureSqlDatabaseServerFirewallRule.GetAzureSqlDatabaseServerFirewallRuleProcess("Server1", null);
            Assert.AreEqual(1, getFirewallResult.Count());
            var firstRule = getFirewallResult.First();
            Assert.AreEqual("Server1", firstRule.ServerName);
            Assert.AreEqual("Rule1", firstRule.RuleName);
            Assert.AreEqual("0.0.0.0", firstRule.StartIpAddress);
            Assert.AreEqual("1.1.1.1", firstRule.EndIpAddress);
            Assert.AreEqual("Success", firstRule.OperationStatus);

            // Update the rule
            SetAzureSqlDatabaseServerFirewallRule setAzureSqlDatabaseServerFirewallRule = new SetAzureSqlDatabaseServerFirewallRule(channel) { ShareChannel = true };
            setAzureSqlDatabaseServerFirewallRule.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            setAzureSqlDatabaseServerFirewallRule.CommandRuntime = commandRuntime;
            var setFirewallResult = setAzureSqlDatabaseServerFirewallRule.SetAzureSqlDatabaseServerFirewallRuleProcess("Server1", "Rule1", "2.2.2.2", "3.3.3.3");
            Assert.AreEqual("Server1", setFirewallResult.ServerName);
            Assert.AreEqual("Rule1", setFirewallResult.RuleName);
            Assert.AreEqual("2.2.2.2", setFirewallResult.StartIpAddress);
            Assert.AreEqual("3.3.3.3", setFirewallResult.EndIpAddress);
            Assert.AreEqual("Success", setFirewallResult.OperationStatus);

            // Get the rule again
            getFirewallResult = getAzureSqlDatabaseServerFirewallRule.GetAzureSqlDatabaseServerFirewallRuleProcess("Server1", "Rule1");
            Assert.AreEqual(1, getFirewallResult.Count());
            firstRule = getFirewallResult.First();
            Assert.AreEqual("Server1", firstRule.ServerName);
            Assert.AreEqual("Rule1", firstRule.RuleName);
            Assert.AreEqual("2.2.2.2", firstRule.StartIpAddress);
            Assert.AreEqual("3.3.3.3", firstRule.EndIpAddress);
            Assert.AreEqual("Success", firstRule.OperationStatus);

            Assert.AreEqual(0, commandRuntime.ErrorStream.Count);
        }