예제 #1
0
        /// <summary>
        /// Process the record with the provided server name
        /// </summary>
        /// <param name="databaseName">The name of the database to retrieve</param>
        private void ProcessWithServerName(string databaseName)
        {
            Func <string> GetClientRequestId = () => string.Empty;

            try
            {
                // Get the current subscription data.
                WindowsAzureSubscription subscription = WindowsAzureProfile.Instance.CurrentSubscription;

                // create a temporary context
                ServerDataServiceCertAuth context =
                    ServerDataServiceCertAuth.Create(this.ServerName, subscription);

                GetClientRequestId = () => context.ClientRequestId;

                if (databaseName != null)
                {
                    // Retrieve the database with the specified name
                    this.WriteObject(context.GetDatabase(databaseName));
                }
                else
                {
                    // No name specified, retrieve all databases in the server
                    this.WriteObject(context.GetDatabases());
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    GetClientRequestId(),
                    ex);
            }
        }
예제 #2
0
        /// <summary>
        /// Process the record with the provided server name
        /// </summary>
        /// <param name="databaseName">The name of the database to retrieve</param>
        private void ProcessWithServerName(string databaseName)
        {
            string clientRequestId = string.Empty;

            try
            {
                // Get the current subscription data.
                SubscriptionData subscriptionData = this.GetCurrentSubscription();

                // create a temporary context
                ServerDataServiceCertAuth context =
                    ServerDataServiceCertAuth.Create(this.ServerName, subscriptionData);

                clientRequestId = context.ClientRequestId;

                if (databaseName != null)
                {
                    // Retrieve the database with the specified name
                    this.WriteObject(context.GetDatabase(databaseName));
                }
                else
                {
                    // No name specified, retrieve all databases in the server
                    this.WriteObject(context.GetDatabases());
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    clientRequestId,
                    ex);
            }
        }
예제 #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");
        }