Exemplo n.º 1
0
        /// <summary>
        /// Gets a list of all the databases in the current context.
        /// </summary>
        /// <returns>An array of databases in the current context</returns>
        public Database[] GetDatabases()
        {
            this.clientRequestId = SqlDatabaseManagementHelper.GenerateClientTracingId();

            ISqlDatabaseManagement channel = GetManagementChannel();

            SqlDatabaseList databases =
                channel.EndGetDatabases(
                    channel.BeginGetDatabases(this.subscriptionId, this.ServerName, null, null));

            List <Database> results = new List <Database>();

            foreach (var db in databases)
            {
                //Create the database from the response
                results.Add(CreateDatabaseFromResponse(db));
            }

            return(results.ToArray());
        }
        public void GetAzureSqlDatabasesWithCertAuth()
        {
            SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement();

            channel.GetDatabasesThunk = ar =>
            {
                List<SqlDatabaseResponse> databases = new List<SqlDatabaseResponse>();

                SqlDatabaseResponse db1 = new SqlDatabaseResponse();
                db1.CollationName = "Japanese_CI_AS";
                db1.Edition = "Web";
                db1.Id = "1";
                db1.MaxSizeGB = "1";
                db1.Name = "testdb1";
                db1.CreationDate = DateTime.Now.ToString();
                db1.IsFederationRoot = true.ToString();
                db1.IsSystemObject = true.ToString();
                db1.MaxSizeBytes = "1073741824";
                databases.Add(db1);

                SqlDatabaseResponse db2 = new SqlDatabaseResponse();
                db2.CollationName = "Japanese_CI_AS";
                db2.Edition = "Business";
                db2.Id = "2";
                db2.MaxSizeGB = "10";
                db2.Name = "testdb2";
                db2.CreationDate = DateTime.Now.ToString();
                db2.IsFederationRoot = true.ToString();
                db2.IsSystemObject = true.ToString();
                db2.MaxSizeBytes = "10737418240";
                databases.Add(db2);

                SqlDatabaseList operationResult = new SqlDatabaseList(databases);

                return operationResult;
            };

            SubscriptionData subscriptionData = UnitTestHelper.CreateUnitTestSubscription();
            subscriptionData.ServiceEndpoint =
                MockHttpServer.DefaultHttpsServerPrefixUri.AbsoluteUri;

            NewAzureSqlDatabaseServerContext contextCmdlet =
                new NewAzureSqlDatabaseServerContext();

            ServerDataServiceCertAuth service =
                contextCmdlet.GetServerDataServiceByCertAuth("TestServer", subscriptionData);
            service.Channel = channel;

            Database[] results = service.GetDatabases();

            // Expecting master, testdb1, testdb2
            Assert.AreEqual(2, results.Length, "Expecting two Database objects");

            Database database1Obj = results[0];
            Assert.AreEqual("testdb1", database1Obj.Name, "Expected db name to be testdb1");

            Database database2Obj = results[1];

            Assert.AreEqual("testdb2", database2Obj.Name, "Expected db name to be testdb2");
            Assert.AreEqual(
                "Japanese_CI_AS",
                database2Obj.CollationName,
                "Expected collation to be Japanese_CI_AS");
            Assert.AreEqual("Business", database2Obj.Edition, "Expected edition to be Business");
            Assert.AreEqual(10, database2Obj.MaxSizeGB, "Expected max size to be 10 GB");
        }
Exemplo n.º 3
0
        public void GetAzureSqlDatabasesWithCertAuth()
        {
            SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement();

            channel.GetDatabasesThunk = ar =>
            {
                List <SqlDatabaseResponse> databases = new List <SqlDatabaseResponse>();

                SqlDatabaseResponse db1 = new SqlDatabaseResponse();
                db1.CollationName    = "Japanese_CI_AS";
                db1.Edition          = "Web";
                db1.Id               = "1";
                db1.MaxSizeGB        = "1";
                db1.Name             = "testdb1";
                db1.CreationDate     = DateTime.Now.ToString();
                db1.IsFederationRoot = true.ToString();
                db1.IsSystemObject   = true.ToString();
                db1.MaxSizeBytes     = "1073741824";
                databases.Add(db1);

                SqlDatabaseResponse db2 = new SqlDatabaseResponse();
                db2.CollationName    = "Japanese_CI_AS";
                db2.Edition          = "Business";
                db2.Id               = "2";
                db2.MaxSizeGB        = "10";
                db2.Name             = "testdb2";
                db2.CreationDate     = DateTime.Now.ToString();
                db2.IsFederationRoot = true.ToString();
                db2.IsSystemObject   = true.ToString();
                db2.MaxSizeBytes     = "10737418240";
                databases.Add(db2);

                SqlDatabaseList operationResult = new SqlDatabaseList(databases);

                return(operationResult);
            };

            SubscriptionData subscriptionData = UnitTestHelper.CreateUnitTestSubscription();

            subscriptionData.ServiceEndpoint =
                MockHttpServer.DefaultHttpsServerPrefixUri.AbsoluteUri;

            NewAzureSqlDatabaseServerContext contextCmdlet =
                new NewAzureSqlDatabaseServerContext();

            ServerDataServiceCertAuth service =
                contextCmdlet.GetServerDataServiceByCertAuth("TestServer", subscriptionData);

            service.Channel = channel;

            Database[] results = service.GetDatabases();

            // Expecting master, testdb1, testdb2
            Assert.AreEqual(2, results.Length, "Expecting two Database objects");

            Database database1Obj = results[0];

            Assert.AreEqual("testdb1", database1Obj.Name, "Expected db name to be testdb1");

            Database database2Obj = results[1];

            Assert.AreEqual("testdb2", database2Obj.Name, "Expected db name to be testdb2");
            Assert.AreEqual(
                "Japanese_CI_AS",
                database2Obj.CollationName,
                "Expected collation to be Japanese_CI_AS");
            Assert.AreEqual("Business", database2Obj.Edition, "Expected edition to be Business");
            Assert.AreEqual(10, database2Obj.MaxSizeGB, "Expected max size to be 10 GB");
        }