public void GetAzureSqlDatabaseServerProcessTest()
        {
            MockCommandRuntime commandRuntime = new MockCommandRuntime();
            SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement();
            SqlDatabaseServerList serverList = new SqlDatabaseServerList();

            channel.NewServerThunk = ar =>
            {
                string newServerName = "TestServer" + serverList.Count.ToString();
                serverList.Add(new SqlDatabaseServer()
                {
                    Name = newServerName,
                    AdministratorLogin = ((NewSqlDatabaseServerInput)ar.Values["input"]).AdministratorLogin,
                    Location = ((NewSqlDatabaseServerInput)ar.Values["input"]).Location
                });

                XmlElement operationResult = new XmlDocument().CreateElement("ServerName", "http://schemas.microsoft.com/sqlazure/2010/12/");
                operationResult.InnerText = newServerName;
                return operationResult;
            };

            channel.GetServersThunk = ar =>
            {
                return serverList;
            };

            // Add two servers
            NewAzureSqlDatabaseServer newAzureSqlDatabaseServer = new NewAzureSqlDatabaseServer(channel) { ShareChannel = true };
            newAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            newAzureSqlDatabaseServer.CommandRuntime = commandRuntime;
            var newServerResult = newAzureSqlDatabaseServer.NewAzureSqlDatabaseServerProcess("MyLogin0", "MyPassword0", "MyLocation0");
            Assert.AreEqual("TestServer0", newServerResult.ServerName);
            Assert.AreEqual("Success", newServerResult.OperationStatus);

            newServerResult = newAzureSqlDatabaseServer.NewAzureSqlDatabaseServerProcess("MyLogin1", "MyPassword1", "MyLocation1");
            Assert.AreEqual("TestServer1", newServerResult.ServerName);
            Assert.AreEqual("Success", newServerResult.OperationStatus);

            // Get all servers
            GetAzureSqlDatabaseServer getAzureSqlDatabaseServer = new GetAzureSqlDatabaseServer(channel) { ShareChannel = true };
            getAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            getAzureSqlDatabaseServer.CommandRuntime = commandRuntime;
            var getServerResult = getAzureSqlDatabaseServer.GetAzureSqlDatabaseServersProcess(null);
            Assert.AreEqual(2, getServerResult.Count());
            var firstServer = getServerResult.First();
            Assert.AreEqual("TestServer0", firstServer.ServerName);
            Assert.AreEqual("MyLogin0", firstServer.AdministratorLogin);
            Assert.AreEqual("MyLocation0", firstServer.Location);
            Assert.AreEqual("Success", firstServer.OperationStatus);
            var lastServer = getServerResult.Last();
            Assert.AreEqual("TestServer1", lastServer.ServerName);
            Assert.AreEqual("MyLogin1", lastServer.AdministratorLogin);
            Assert.AreEqual("MyLocation1", lastServer.Location);
            Assert.AreEqual("Success", lastServer.OperationStatus);

            // Get one server
            getServerResult = getAzureSqlDatabaseServer.GetAzureSqlDatabaseServersProcess("TestServer1");
            Assert.AreEqual(1, getServerResult.Count());
            firstServer = getServerResult.First();
            Assert.AreEqual("TestServer1", firstServer.ServerName);
            Assert.AreEqual("MyLogin1", firstServer.AdministratorLogin);
            Assert.AreEqual("MyLocation1", firstServer.Location);
            Assert.AreEqual("Success", firstServer.OperationStatus);

            Assert.AreEqual(0, commandRuntime.ErrorStream.Count);
        }
Exemple #2
0
        public void GetAzureSqlDatabaseServerProcessTest()
        {
            MockCommandRuntime          commandRuntime = new MockCommandRuntime();
            SimpleSqlDatabaseManagement channel        = new SimpleSqlDatabaseManagement();
            SqlDatabaseServerList       serverList     = new SqlDatabaseServerList();

            channel.NewServerThunk = ar =>
            {
                string newServerName = "TestServer" + serverList.Count.ToString();
                serverList.Add(new SqlDatabaseServer()
                {
                    Name = newServerName,
                    AdministratorLogin = ((NewSqlDatabaseServerInput)ar.Values["input"]).AdministratorLogin,
                    Location           = ((NewSqlDatabaseServerInput)ar.Values["input"]).Location
                });

                XmlElement operationResult = new XmlDocument().CreateElement("ServerName", "http://schemas.microsoft.com/sqlazure/2010/12/");
                operationResult.InnerText = newServerName;
                return(operationResult);
            };

            channel.GetServersThunk = ar =>
            {
                return(serverList);
            };

            // Add two servers
            NewAzureSqlDatabaseServer newAzureSqlDatabaseServer = new NewAzureSqlDatabaseServer(channel)
            {
                ShareChannel = true
            };

            newAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            newAzureSqlDatabaseServer.CommandRuntime      = commandRuntime;
            var newServerResult = newAzureSqlDatabaseServer.NewAzureSqlDatabaseServerProcess("MyLogin0", "MyPassword0", "MyLocation0");

            Assert.AreEqual("TestServer0", newServerResult.ServerName);
            Assert.AreEqual("Success", newServerResult.OperationStatus);

            newServerResult = newAzureSqlDatabaseServer.NewAzureSqlDatabaseServerProcess("MyLogin1", "MyPassword1", "MyLocation1");
            Assert.AreEqual("TestServer1", newServerResult.ServerName);
            Assert.AreEqual("Success", newServerResult.OperationStatus);

            // Get all servers
            GetAzureSqlDatabaseServer getAzureSqlDatabaseServer = new GetAzureSqlDatabaseServer(channel)
            {
                ShareChannel = true
            };

            getAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            getAzureSqlDatabaseServer.CommandRuntime      = commandRuntime;
            var getServerResult = getAzureSqlDatabaseServer.GetAzureSqlDatabaseServersProcess(null);

            Assert.AreEqual(2, getServerResult.Count());
            var firstServer = getServerResult.First();

            Assert.AreEqual("TestServer0", firstServer.ServerName);
            Assert.AreEqual("MyLogin0", firstServer.AdministratorLogin);
            Assert.AreEqual("MyLocation0", firstServer.Location);
            Assert.AreEqual("Success", firstServer.OperationStatus);
            var lastServer = getServerResult.Last();

            Assert.AreEqual("TestServer1", lastServer.ServerName);
            Assert.AreEqual("MyLogin1", lastServer.AdministratorLogin);
            Assert.AreEqual("MyLocation1", lastServer.Location);
            Assert.AreEqual("Success", lastServer.OperationStatus);

            // Get one server
            getServerResult = getAzureSqlDatabaseServer.GetAzureSqlDatabaseServersProcess("TestServer1");
            Assert.AreEqual(1, getServerResult.Count());
            firstServer = getServerResult.First();
            Assert.AreEqual("TestServer1", firstServer.ServerName);
            Assert.AreEqual("MyLogin1", firstServer.AdministratorLogin);
            Assert.AreEqual("MyLocation1", firstServer.Location);
            Assert.AreEqual("Success", firstServer.OperationStatus);

            Assert.AreEqual(0, commandRuntime.ErrorStream.Count);
        }
        public void RemoveAzureSqlDatabaseServerProcessTest()
        {
            MockCommandRuntime commandRuntime = new MockCommandRuntime();
            SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement();
            SqlDatabaseServerList serverList = new SqlDatabaseServerList();

            channel.NewServerThunk = ar =>
            {
                string newServerName = "TestServer" + serverList.Count.ToString();
                serverList.Add(new SqlDatabaseServer()
                {
                    Name = newServerName,
                    AdministratorLogin = ((NewSqlDatabaseServerInput)ar.Values["input"]).AdministratorLogin,
                    Location = ((NewSqlDatabaseServerInput)ar.Values["input"]).Location
                });

                XmlElement operationResult = new XmlDocument().CreateElement("ServerName", "http://schemas.microsoft.com/sqlazure/2010/12/");
                operationResult.InnerText = newServerName;
                return operationResult;
            };

            channel.GetServersThunk = ar =>
            {
                return serverList;
            };

            channel.RemoveServerThunk = ar =>
            {
                string serverName = (string)ar.Values["serverName"];
                var serverToDelete = serverList.SingleOrDefault((server) => server.Name == serverName);
                if (serverToDelete == null)
                {
                    throw new CommunicationException("Server does not exist!");
                }

                serverList.Remove(serverToDelete);
            };

            // Add two servers
            NewAzureSqlDatabaseServer newAzureSqlDatabaseServer = new NewAzureSqlDatabaseServer(channel) { ShareChannel = true };
            newAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            newAzureSqlDatabaseServer.CommandRuntime = commandRuntime;
            var newServerResult = newAzureSqlDatabaseServer.NewAzureSqlDatabaseServerProcess("MyLogin0", "MyPassword0", "MyLocation0");
            Assert.AreEqual("TestServer0", newServerResult.ServerName);
            Assert.AreEqual("Success", newServerResult.OperationStatus);

            newServerResult = newAzureSqlDatabaseServer.NewAzureSqlDatabaseServerProcess("MyLogin1", "MyPassword1", "MyLocation1");
            Assert.AreEqual("TestServer1", newServerResult.ServerName);
            Assert.AreEqual("Success", newServerResult.OperationStatus);

            // Get all servers
            GetAzureSqlDatabaseServer getAzureSqlDatabaseServer = new GetAzureSqlDatabaseServer(channel) { ShareChannel = true };
            getAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            getAzureSqlDatabaseServer.CommandRuntime = commandRuntime;
            var getServerContext = getAzureSqlDatabaseServer.GetAzureSqlDatabaseServersProcess(null);
            Assert.AreEqual(2, getServerContext.Count());

            // Remove TestServer0
            RemoveAzureSqlDatabaseServer removeAzureSqlDatabaseServer = new RemoveAzureSqlDatabaseServer(channel) { ShareChannel = true };
            removeAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            removeAzureSqlDatabaseServer.CommandRuntime = commandRuntime;
            var removeServerContext = removeAzureSqlDatabaseServer.RemoveAzureSqlDatabaseServerProcess("TestServer0");

            // Verify only one server is left
            getAzureSqlDatabaseServer = new GetAzureSqlDatabaseServer(channel) { ShareChannel = true };
            getAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            getAzureSqlDatabaseServer.CommandRuntime = commandRuntime;
            var getServerResult = getAzureSqlDatabaseServer.GetAzureSqlDatabaseServersProcess(null);
            Assert.AreEqual(1, getServerContext.Count());
            var firstServer = getServerResult.First();
            Assert.AreEqual("TestServer1", firstServer.ServerName);
            Assert.AreEqual("MyLogin1", firstServer.AdministratorLogin);
            Assert.AreEqual("MyLocation1", firstServer.Location);
            Assert.AreEqual("Success", firstServer.OperationStatus);

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

            // Remove TestServer0 again
            removeAzureSqlDatabaseServer = new RemoveAzureSqlDatabaseServer(channel) { ShareChannel = true };
            removeAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            removeAzureSqlDatabaseServer.CommandRuntime = commandRuntime;
            removeServerContext = removeAzureSqlDatabaseServer.RemoveAzureSqlDatabaseServerProcess("TestServer0");
            Assert.AreEqual(1, commandRuntime.ErrorStream.Count);
            Assert.IsTrue(commandRuntime.WarningStream.Count > 0);
        }
Exemple #4
0
        public void RemoveAzureSqlDatabaseServerProcessTest()
        {
            MockCommandRuntime          commandRuntime = new MockCommandRuntime();
            SimpleSqlDatabaseManagement channel        = new SimpleSqlDatabaseManagement();
            SqlDatabaseServerList       serverList     = new SqlDatabaseServerList();

            channel.NewServerThunk = ar =>
            {
                string newServerName = "TestServer" + serverList.Count.ToString();
                serverList.Add(new SqlDatabaseServer()
                {
                    Name = newServerName,
                    AdministratorLogin = ((NewSqlDatabaseServerInput)ar.Values["input"]).AdministratorLogin,
                    Location           = ((NewSqlDatabaseServerInput)ar.Values["input"]).Location
                });

                XmlElement operationResult = new XmlDocument().CreateElement("ServerName", "http://schemas.microsoft.com/sqlazure/2010/12/");
                operationResult.InnerText = newServerName;
                return(operationResult);
            };

            channel.GetServersThunk = ar =>
            {
                return(serverList);
            };

            channel.RemoveServerThunk = ar =>
            {
                string serverName     = (string)ar.Values["serverName"];
                var    serverToDelete = serverList.SingleOrDefault((server) => server.Name == serverName);
                if (serverToDelete == null)
                {
                    throw new CommunicationException("Server does not exist!");
                }

                serverList.Remove(serverToDelete);
            };

            // Add two servers
            NewAzureSqlDatabaseServer newAzureSqlDatabaseServer = new NewAzureSqlDatabaseServer(channel)
            {
                ShareChannel = true
            };

            newAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            newAzureSqlDatabaseServer.CommandRuntime      = commandRuntime;
            var newServerResult = newAzureSqlDatabaseServer.NewAzureSqlDatabaseServerProcess("MyLogin0", "MyPassword0", "MyLocation0");

            Assert.AreEqual("TestServer0", newServerResult.ServerName);
            Assert.AreEqual("Success", newServerResult.OperationStatus);

            newServerResult = newAzureSqlDatabaseServer.NewAzureSqlDatabaseServerProcess("MyLogin1", "MyPassword1", "MyLocation1");
            Assert.AreEqual("TestServer1", newServerResult.ServerName);
            Assert.AreEqual("Success", newServerResult.OperationStatus);

            // Get all servers
            GetAzureSqlDatabaseServer getAzureSqlDatabaseServer = new GetAzureSqlDatabaseServer(channel)
            {
                ShareChannel = true
            };

            getAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            getAzureSqlDatabaseServer.CommandRuntime      = commandRuntime;
            var getServerContext = getAzureSqlDatabaseServer.GetAzureSqlDatabaseServersProcess(null);

            Assert.AreEqual(2, getServerContext.Count());

            // Remove TestServer0
            RemoveAzureSqlDatabaseServer removeAzureSqlDatabaseServer = new RemoveAzureSqlDatabaseServer(channel)
            {
                ShareChannel = true
            };

            removeAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            removeAzureSqlDatabaseServer.CommandRuntime      = commandRuntime;
            var removeServerContext = removeAzureSqlDatabaseServer.RemoveAzureSqlDatabaseServerProcess("TestServer0");

            // Verify only one server is left
            getAzureSqlDatabaseServer = new GetAzureSqlDatabaseServer(channel)
            {
                ShareChannel = true
            };
            getAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            getAzureSqlDatabaseServer.CommandRuntime      = commandRuntime;
            var getServerResult = getAzureSqlDatabaseServer.GetAzureSqlDatabaseServersProcess(null);

            Assert.AreEqual(1, getServerContext.Count());
            var firstServer = getServerResult.First();

            Assert.AreEqual("TestServer1", firstServer.ServerName);
            Assert.AreEqual("MyLogin1", firstServer.AdministratorLogin);
            Assert.AreEqual("MyLocation1", firstServer.Location);
            Assert.AreEqual("Success", firstServer.OperationStatus);

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

            // Remove TestServer0 again
            removeAzureSqlDatabaseServer = new RemoveAzureSqlDatabaseServer(channel)
            {
                ShareChannel = true
            };
            removeAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            removeAzureSqlDatabaseServer.CommandRuntime      = commandRuntime;
            removeServerContext = removeAzureSqlDatabaseServer.RemoveAzureSqlDatabaseServerProcess("TestServer0");
            Assert.AreEqual(1, commandRuntime.ErrorStream.Count);
            Assert.IsTrue(commandRuntime.WarningStream.Count > 0);
        }