/// <summary> /// Removes all existing db which name starting with PremiumTest on the given context. /// </summary> /// <param name="powershell">The powershell instance containing the context.</param> /// <param name="contextVariable">The variable name that holds the server context.</param> public static void RemoveTestDatabasesWithSqlAuth( System.Management.Automation.PowerShell powershell, string contextVariable) { HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTest.Common.RemoveTestPremiumDatabasesWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); switch (expected.Index) { // Request 0-11: Remove database requests case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); break; default: Assert.Fail("No more requests expected."); break; } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { powershell.InvokeBatchScript( @"Get-AzureSqlDatabase $context | " + @"? {$_.Name.contains(""NewAzureSqlPremiumDatabaseTests"")} " + @"| Remove-AzureSqlDatabase -Context $context -Force"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); } }
public void CreatePremiumDatabasesWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTest.Common.CreatePremiumDatabasesWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); }); TestCreatePremiumDatabase(powershell, testSession); } }
public void GetAzureSqlDatabaseWithSqlAuthByPipe() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); // Query the created test databases HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.GetAzureSqlDatabaseWithSqlAuthByPipe"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); if (expected.Index < 12) { // Request 0-3: Get all databases + ServiceObjectives requests // Request 4-11: 4 Get databases, 2 requests per get call DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); } else { Assert.Fail("No more requests expected."); } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { Collection <PSObject> databases, database1, database2; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { databases = powershell.InvokeBatchScript( @"Get-AzureSqlDatabase " + @"-Context $context"); powershell.InvokeBatchScript( @"$testdb1 = Get-AzureSqlDatabase $context -DatabaseName testdb1"); powershell.InvokeBatchScript( @"$testdb2 = Get-AzureSqlDatabase $context -DatabaseName testdb2"); database1 = powershell.InvokeBatchScript( @"$testdb1 | Get-AzureSqlDatabase"); database2 = powershell.InvokeBatchScript( @"$testdb2 | Get-AzureSqlDatabase"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); // Expecting master, testdb1, testdb2 Assert.AreEqual( 3, databases.Count, "Expecting three Database objects"); Services.Server.Database database1Obj = database1.Single().BaseObject as Services.Server.Database; Assert.IsNotNull(database1Obj, "Expecting a Database object"); DatabaseTestHelper.ValidateDatabaseProperties(database1Obj, "testdb1", "Web", 1, 1073741824L, "SQL_Latin1_General_CP1_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid); Services.Server.Database database2Obj = database2.Single().BaseObject as Services.Server.Database; Assert.IsNotNull(database2Obj, "Expecting a Database object"); DatabaseTestHelper.ValidateDatabaseProperties(database2Obj, "testdb2", "Web", 5, 5368709120L, "Japanese_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid); } } }
public void NewAzureSqlDatabaseWithSqlAuthDuplicateName() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); // Issue another create testdb1, causing a failure HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTest.NewAzureSqlDatabaseWithSqlAuthDuplicateName"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); switch (expected.Index) { // Request 0-1: Create testdb1 case 0: case 1: DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); break; default: Assert.Fail("No more requests expected."); break; } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { Services.Server.ServerDataServiceSqlAuth context; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { Collection <PSObject> ctxPsObject = powershell.InvokeBatchScript("$context"); context = (Services.Server.ServerDataServiceSqlAuth)ctxPsObject.First().BaseObject; powershell.InvokeBatchScript( @"New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb1 " + @"-Force"); } } Assert.AreEqual(1, powershell.Streams.Error.Count, "Expecting errors"); Assert.AreEqual(2, powershell.Streams.Warning.Count, "Expecting tracing IDs"); Assert.AreEqual( "Database 'testdb1' already exists. Choose a different database name.", powershell.Streams.Error.First().Exception.Message, "Unexpected error message"); Assert.IsTrue( powershell.Streams.Warning.Any(w => w.Message.StartsWith("Client Session Id")), "Expecting Client Session Id"); Assert.IsTrue( powershell.Streams.Warning.Any(w => w.Message.StartsWith("Client Request Id")), "Expecting Client Request Id"); powershell.Streams.ClearStreams(); } }
/// <summary> /// Create $testdb1 and $testdb2 on the given context. /// </summary> /// <param name="powershell">The powershell instance containing the context.</param> /// <param name="contextVariable">The variable name that holds the server context.</param> public static void CreateTestDatabasesWithSqlAuth( System.Management.Automation.PowerShell powershell, string contextVariable) { HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTest.Common.CreateTestDatabasesWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); switch (expected.Index) { // Request 0-2: Create testdb1 // Request 3-5: Create testdb2 // Request 6-8: Create testdb3 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); break; default: Assert.Fail("No more requests expected."); break; } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { Collection <PSObject> database1, database2, database3; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { database1 = powershell.InvokeBatchScript( @"$testdb1 = New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb1 " + @"-Force", @"$testdb1"); database2 = powershell.InvokeBatchScript( @"$testdb2 = New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb2 " + @"-Collation Japanese_CI_AS " + @"-Edition Web " + @"-MaxSizeGB 5 " + @"-Force", @"$testdb2"); database3 = powershell.InvokeBatchScript( @"$testdb3 = New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb3 " + @"-MaxSizeBytes 104857600 " + @"-Force", @"$testdb3"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); Services.Server.Database database = database1.Single().BaseObject as Services.Server.Database; Assert.IsTrue(database != null, "Expecting a Database object"); DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb1", "Web", 1, 1073741824L, "SQL_Latin1_General_CP1_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid); database = database2.Single().BaseObject as Services.Server.Database; Assert.IsTrue(database != null, "Expecting a Database object"); DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb2", "Web", 5, 5368709120L, "Japanese_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid); database = database3.Single().BaseObject as Services.Server.Database; Assert.IsTrue(database != null, "Expecting a Database object"); DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb3", "Web", 0, 104857600L, "SQL_Latin1_General_CP1_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid); } }
public void GetRestorableDroppedDatabaseWithSqlAuthNonExistentDb() { using (var powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth(powershell, "$context"); var testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.GetRestorableDroppedDatabaseWithSqlAuthNonExistentDb"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.IsNotNull(actual.UserAgent); if (expected.Index < 1) { DatabaseTestHelper.ValidateHeadersForODataRequest(expected.RequestInfo, actual); } else { Assert.Fail("No more requests expected."); } }); using (var exceptionManager = new AsyncExceptionManager()) { using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { powershell.InvokeBatchScript( @"Get-AzureSqlDatabase -RestorableDropped " + @"-Context $context " + @"-DatabaseName testdbnonexistent " + @"-DatabaseDeletionDate '10/01/2013 12:00:00 AM'"); } Assert.AreEqual( 1, powershell.Streams.Error.Count, "Expecting errors"); Assert.AreEqual( 2, powershell.Streams.Warning.Count, "Expecting tracing IDs"); Assert.AreEqual( string.Format( CultureInfo.InvariantCulture, "Database '{0}' with deletion date '{1}' not found.", testSession.SessionProperties["Servername"] + ".testdbnonexistent", new DateTime(2013, 10, 01, 0, 0, 0, DateTimeKind.Utc)), powershell.Streams.Error.First().Exception.Message, "Unexpected error message"); Assert.IsTrue( powershell.Streams.Warning.Any(w => w.Message.StartsWith("Client Session Id")), "Expecting Client Session Id"); Assert.IsTrue( powershell.Streams.Warning.Any(w => w.Message.StartsWith("Client Request Id")), "Expecting Client Request Id"); } } }
public void SetAzureSqlDatabaseNameWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$contextCleanup"); HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.SetAzureSqlDatabaseNameWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); if (expected.Index < 10) { // Request 0-4: Set testdb1 with new name of new_testdb1 // Request 5-9: Set new_testdb1 with new name of testdb1 DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); } else { Assert.Fail("No more requests expected."); } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { // Create context with both ManageUrl and ServerName overriden Collection <PSObject> database; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { database = powershell.InvokeBatchScript( @"Set-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb1 " + @"-NewName new_testdb1 " + @"-Force " + @"-PassThru"); powershell.InvokeBatchScript( @"Set-AzureSqlDatabase " + @"-Context $contextCleanup " + @"-DatabaseName new_testdb1 " + @"-NewName testdb1 " + @"-Force"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); Services.Server.Database databaseObj = database.Single().BaseObject as Services.Server.Database; Assert.IsNotNull(databaseObj, "Expecting a Database object"); DatabaseTestHelper.ValidateDatabaseProperties(databaseObj, "new_testdb1", "Web", 1, 1073741824L, "SQL_Latin1_General_CP1_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid); } } }
public void CreatePremiumDatabasesWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTest.Common.CreatePremiumDatabasesWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); switch (expected.Index) { // Request 0-6: Query P1 and P2 Service Objective case 0: case 1: case 2: case 3: case 4: case 5: case 6: // Request 7-9: Create NewAzureSqlPremiumDatabaseTests_P1 case 7: case 8: case 9: // Request 10-12: Create NewAzureSqlPremiumDatabaseTests_P2 case 10: case 11: case 12: DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); break; default: Assert.Fail("No more requests expected."); break; } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { Collection <PSObject> premiumDB_P1, PremiumDB_P2; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { powershell.InvokeBatchScript( @"$P1 = Get-AzureSqlDatabaseServiceObjective" + @" -Context $context" + @" -ServiceObjectiveName ""Reserved P1"""); powershell.InvokeBatchScript( @"$P2 = Get-AzureSqlDatabaseServiceObjective " + @"-Context $context" + @" -ServiceObjectiveName ""Reserved P2"""); premiumDB_P1 = powershell.InvokeBatchScript( @"$premiumDB_P1 = New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName NewAzureSqlPremiumDatabaseTests_P1 " + @"-Edition Premium " + @"-ServiceObjective $P1 "); premiumDB_P1 = powershell.InvokeBatchScript("$PremiumDB_P1"); powershell.InvokeBatchScript( @"$PremiumDB_P2 = New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName NewAzureSqlPremiumDatabaseTests_P2 " + @"-Collation Japanese_CI_AS " + @"-Edition Premium " + @"-ServiceObjective $P2 " + @"-MaxSizeGB 10 " + @"-Force"); PremiumDB_P2 = powershell.InvokeBatchScript("$PremiumDB_P2"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); Assert.IsTrue( premiumDB_P1.Single().BaseObject is Services.Server.Database, "Expecting a Database object"); Services.Server.Database databaseP1 = (Services.Server.Database)premiumDB_P1.Single().BaseObject; Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P1", databaseP1.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P1"); Assert.IsTrue( PremiumDB_P2.Single().BaseObject is Services.Server.Database, "Expecting a Database object"); Services.Server.Database databaseP2 = (Services.Server.Database)PremiumDB_P2.Single().BaseObject; Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P2", databaseP2.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P2"); Assert.AreEqual( "Japanese_CI_AS", databaseP2.CollationName, "Expected collation to be Japanese_CI_AS"); /* SQL Server: Defect 1655888: When creating a premium database, * the immediate returned value do not have valid Edition and Max Database Size info * We should active the following asserts once the defect is fixed. * Assert.AreEqual("Premium", database2Obj.Edition, "Expected edition to be Premium"); * Assert.AreEqual(10, database2Obj.MaxSizeGB, "Expected max size to be 10 GB"); */ } } }
public void GetAzureSqlDatabaseOperationWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTest.Common.GetAzureSqlDatabaseOperationWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); switch (expected.Index) { // Request 0-7: Create and Query $testdb case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: // Request 8: Delete $testdb case 8: // Request 9-11: Query Database Operations case 9: case 10: case 11: DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); break; default: Assert.Fail("No more requests expected."); break; } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { // There is a known issue about the Get-AzureSqlDatabaseOperation that it returns all // operations which has the required database name no matter it's been deleted and recreated. // So when run it against the mock session, please use the hard coded testsDBName. // Run against onebox, please use the one with NewGuid(). // This unit test should be updated once that behavior get changed which was already been // created as a task. // string testsDBName = string.Format("getAzureSqlDatabaseOperationTestsDB_{0}", // Guid.NewGuid().ToString()); string testsDBName = "getAzureSqlDatabaseOperationTestsDB_08ebd7c9-bfb7-426a-9e2f-9921999567e1"; Collection <PSObject> database, operationsByName, operationsByDatabase, operationsById; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { database = powershell.InvokeBatchScript( string.Format( @"$testdb = New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName {0} " + @"-Force", testsDBName), @"$testdb"); powershell.InvokeBatchScript( string.Format( @"Remove-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName {0} " + @"-Force", testsDBName)); operationsByName = powershell.InvokeBatchScript( string.Format( @"$operations = Get-AzureSqlDatabaseOperation " + @"-ConnectionContext $context " + @"-DatabaseName {0}", testsDBName), @"$operations"); operationsByDatabase = powershell.InvokeBatchScript( @"Get-AzureSqlDatabaseOperation " + @"-ConnectionContext $context " + @"-Database $testdb"); operationsById = powershell.InvokeBatchScript( @"Get-AzureSqlDatabaseOperation " + @"-ConnectionContext $context " + @"-OperationGuid $operations[0].Id" ); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); VerifyGetOperationsResult(testsDBName, operationsByName); VerifyGetOperationsResult(testsDBName, operationsByDatabase); // Update this verification once Task 1615375:Adding Drop record in dm_operation_status resolved VerifyGetOperationsResult(testsDBName, operationsById); } } }
public void GetAzureSqlDatabaseServiceObjectiveWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.GetAzureSqlServiceObjectiveWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); switch (expected.Index) { // Request 0-6: Retrieving all (6) ServiceObjectives and DimensionSettings case 0: case 1: case 2: case 3: case 4: case 5: case 6: // Request 7-8: Retrieving Reserved P1 ServiceObjectives and DimensionSettings case 7: case 8: DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); break; default: Assert.Fail("No more requests expected."); break; } }); testSession.ResponseModifier = new Action <HttpMessage>( (message) => { DatabaseTestHelper.FixODataResponseUri( message.ResponseInfo, testSession.ServiceBaseUri, MockHttpServer.DefaultServerPrefixUri); }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { Collection <PSObject> objectives, objective1; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { objectives = powershell.InvokeBatchScript( @"Get-AzureSqlDatabaseServiceObjective " + @"-Context $context"); objective1 = powershell.InvokeBatchScript( @"Get-AzureSqlDatabaseServiceObjective " + @"-Context $context " + @"-ServiceObjectiveName ""P1"""); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); Assert.AreEqual(6, objectives.Count, "Expecting 6 Objective objects"); Assert.IsTrue( objective1.Single().BaseObject is Services.Server.ServiceObjective, "Expecting a ServiceObjective object"); Services.Server.ServiceObjective objective1Obj = (Services.Server.ServiceObjective)objective1.Single().BaseObject; Assert.AreEqual("P1", objective1Obj.Name, "Expected objective name to be 'Reserved P1'"); } } }
public void SetAzureSqlDatabaseSizeWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.SetAzureSqlDatabaseSizeWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); if (expected.Index < 5) { // Request 0-2: Set testdb1 with new MaxSize // Request 3-4: Get updated testdb1 DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); } else { Assert.Fail("No more requests expected."); } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { // Create context with both ManageUrl and ServerName overriden Collection <PSObject> database; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { database = powershell.InvokeBatchScript( @"Set-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb1 " + @"-MaxSizeGB 5 " + @"-Force " + @"-PassThru"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); Assert.IsTrue( database.Single().BaseObject is Services.Server.Database, "Expecting a Database object"); Services.Server.Database databaseObj = (Services.Server.Database)database.Single().BaseObject; Assert.AreEqual("testdb1", databaseObj.Name, "Expected db name to be testdb1"); Assert.AreEqual("Web", databaseObj.Edition, "Expected edition to be Web"); Assert.AreEqual(5, databaseObj.MaxSizeGB, "Expected max size to be 5 GB"); } } }
public void SetAzureSqlPremiumDatabaseServiceObjectiveWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.SetAzureSqlPremiumDatabaseServiceObjectiveWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { // Create context with both ManageUrl and ServerName overriden Collection <PSObject> database, premiumDB; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { powershell.InvokeBatchScript( @"$P1 = Get-AzureSqlDatabaseServiceObjective" + @" -Context $context" + @" -ServiceObjectiveName ""Reserved P1"""); powershell.InvokeBatchScript( @"$premiumDB_P1 = New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName SetAzureSqlPremiumDatabaseTests_P1 " + @"-Edition Premium " + @"-ServiceObjective $P1 "); premiumDB = powershell.InvokeBatchScript( @"Set-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName SetAzureSqlPremiumDatabaseTests_P1 " + @"-Edition Business " + @"-Force " + @"-PassThru"); powershell.InvokeBatchScript( @"Remove-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName SetAzureSqlPremiumDatabaseTests_P1 " + @"-Force "); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); Assert.IsTrue( premiumDB.Single().BaseObject is Services.Server.Database, "Expecting a Database object"); Services.Server.Database premiumDBObj = (Services.Server.Database)premiumDB.Single().BaseObject; Assert.AreEqual("SetAzureSqlPremiumDatabaseTests_P1", premiumDBObj.Name, "Expected db name to be SetAzureSqlPremiumDatabaseTests_P1"); Assert.AreEqual("Business", premiumDBObj.Edition, "Expected db edition to be Business"); Assert.AreEqual("Shared", premiumDBObj.ServiceObjective.Name, "Expected db ServiceObjective to be Shared"); } } }
public void GetAzureSqlDatabaseWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); // Query the created test databases HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.GetAzureSqlDatabaseWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); switch (expected.Index) { // Request 0-3: Get all databases + ServiceObjective lookup for each database case 0: case 1: case 2: case 3: // Request 4-7: Get database requests, 2 requests per get case 4: case 5: case 6: case 7: DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); break; default: Assert.Fail("No more requests expected."); break; } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { // Retrieve all databases then each individual ones Collection <PSObject> databases, database1, database2; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { databases = powershell.InvokeBatchScript( @"Get-AzureSqlDatabase " + @"-Context $context"); database1 = powershell.InvokeBatchScript( @"Get-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb1"); database2 = powershell.InvokeBatchScript( @"Get-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb2"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); // Expecting master, testdb1, testdb2 Assert.AreEqual( 3, databases.Count, "Expecting three Database objects"); Assert.IsTrue( database1.Single().BaseObject is Services.Server.Database, "Expecting a Database object"); Services.Server.Database database1Obj = (Services.Server.Database)database1.Single().BaseObject; Assert.AreEqual( "testdb1", database1Obj.Name, "Expected db name to be testdb1"); Assert.IsTrue( database2.Single().BaseObject is Services.Server.Database, "Expecting a Database object"); Services.Server.Database database2Obj = (Services.Server.Database)database2.Single().BaseObject; 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("Web", database2Obj.Edition, "Expected edition to be Web"); Assert.AreEqual(5, database2Obj.MaxSizeGB, "Expected max size to be 5 GB"); } } }
public void GetAzureSqlDatabaseWithSqlAuthNonExistentDb() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); // Query a non-existent test database HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.GetAzureSqlDatabaseWithSqlAuthNonExistentDb"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); switch (expected.Index) { // Request 0-2: Get database requests case 0: DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); break; default: Assert.Fail("No more requests expected."); break; } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { powershell.InvokeBatchScript( @"Get-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb3"); } } Assert.AreEqual(1, powershell.Streams.Error.Count, "Expecting errors"); Assert.AreEqual(2, powershell.Streams.Warning.Count, "Expecting tracing IDs"); Assert.AreEqual( "Database 'myserver01.testdb3' not found.", powershell.Streams.Error.First().Exception.Message, "Unexpected error message"); Assert.IsTrue( powershell.Streams.Warning.Any(w => w.Message.StartsWith("Client Session Id")), "Expecting Client Session Id"); Assert.IsTrue( powershell.Streams.Warning.Any(w => w.Message.StartsWith("Client Request Id")), "Expecting Client Request Id"); powershell.Streams.ClearStreams(); } }
public void SetAzureSqlDatabaseServiceObjectiveWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.SetAzureSqlDatabaseServiceObjectiveWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); switch (expected.Index) { // Request 0-1: Get Service Objective case 0: case 1: // Request 2-7: Get/Update/Re-Get testdb2 case 2: case 3: case 4: case 5: case 6: DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); break; default: Assert.Fail("No more requests expected."); break; } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { // Create context with both ManageUrl and ServerName overriden Collection <PSObject> database; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { powershell.InvokeBatchScript( @"$slo = Get-AzureSqlDatabaseServiceObjective " + @"-Context $context " + @"-ServiceObjectiveName ""P1"""); database = powershell.InvokeBatchScript( @"Set-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb2 " + @"-ServiceObjective $slo " + @"-Force " + @"-PassThru"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); Services.Server.Database databaseObj = database.Single().BaseObject as Services.Server.Database; Assert.IsNotNull(databaseObj, "Expecting a Database object"); Assert.AreEqual("testdb2", databaseObj.Name, "Expected db name to be testdb2"); Assert.AreEqual((byte)0, databaseObj.ServiceObjectiveAssignmentState, "Expected assignment state to be complete"); DatabaseTestHelper.ValidateDatabaseProperties(databaseObj, "testdb2", "Web", 5, 5368709120L, "Japanese_CI_AS", "Shared", false, DatabaseTestHelper.PremiumP1SloGuid); } } }
public void GetAzureSqlDatabaseWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); // Query the created test databases HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.GetAzureSqlDatabaseWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); // 0 - 5 // Get all databases + ServiceObjective lookup // 6 - 11 // get database requests, 2 requests per get. if (expected.Index > 11) { Assert.Fail("No More Requests Expected"); } else { DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { // Retrieve all databases then each individual ones Collection <PSObject> databases, database1, database2, database3; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { databases = powershell.InvokeBatchScript( @"Get-AzureSqlDatabase " + @"-Context $context"); database1 = powershell.InvokeBatchScript( @"Get-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb1"); database2 = powershell.InvokeBatchScript( @"Get-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb2"); database3 = powershell.InvokeBatchScript( @"Get-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb3"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); // Expecting master, testdb1, testdb2, testdb3 Assert.AreEqual(4, databases.Count, "Expecting four Database objects"); Services.Server.Database database = database1.Single().BaseObject as Services.Server.Database; Assert.IsNotNull(database, "Expecting a Database object"); DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb1", "Web", 1, 1073741824L, "SQL_Latin1_General_CP1_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid); database = database2.Single().BaseObject as Services.Server.Database; Assert.IsTrue(database != null, "Expecting a Database object"); DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb2", "Web", 5, 5368709120L, "Japanese_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid); database = database3.Single().BaseObject as Services.Server.Database; Assert.IsTrue(database != null, "Expecting a Database object"); DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb3", "Web", 0, 104857600L, "SQL_Latin1_General_CP1_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid); } } }
public void SetAzureSqlPremiumDatabaseServiceObjectiveWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.SetAzureSqlPremiumDatabaseServiceObjectiveWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { // Create context with both ManageUrl and ServerName overriden Collection <PSObject> premiumDB; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { powershell.InvokeBatchScript( @"$P1 = Get-AzureSqlDatabaseServiceObjective" + @" -Context $context" + @" -ServiceObjectiveName ""P1"""); powershell.InvokeBatchScript( @"$premiumDB_P1 = New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName SetAzureSqlPremiumDatabaseTests_P1 " + @"-Edition Premium " + @"-ServiceObjective $P1 "); premiumDB = powershell.InvokeBatchScript( @"Set-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName SetAzureSqlPremiumDatabaseTests_P1 " + @"-Edition Business " + @"-Force " + @"-PassThru"); powershell.InvokeBatchScript( @"Remove-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName SetAzureSqlPremiumDatabaseTests_P1 " + @"-Force "); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); Services.Server.Database premiumDBObj = premiumDB.Single().BaseObject as Services.Server.Database; Assert.IsNotNull(premiumDBObj, "Expecting a Database object"); DatabaseTestHelper.ValidateDatabaseProperties(premiumDBObj, "SetAzureSqlPremiumDatabaseTests_P1", "Premium", 10, 10737418240L, "SQL_Latin1_General_CP1_CI_AS", "P1", false, DatabaseTestHelper.PremiumP1SloGuid); } } }
/// <summary> /// Common helper method for other tests to create a context. /// </summary> /// <param name="contextVariable">The variable name that will hold the new context.</param> public static void CreateServerContextSqlAuth( System.Management.Automation.PowerShell powershell, string contextVariable) { HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTest.Common.NewAzureSqlDatabaseServerContextWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); switch (expected.Index) { // Request 0-2: Create context with both ManageUrl and ServerName overriden case 0: // GetAccessToken call DatabaseTestHelper.ValidateGetAccessTokenRequest( expected.RequestInfo, actual); break; case 1: // Get server call DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); break; case 2: // $metadata call Assert.IsTrue( actual.RequestUri.AbsoluteUri.EndsWith("$metadata"), "Incorrect Uri specified for $metadata"); DatabaseTestHelper.ValidateHeadersForServiceRequest( expected.RequestInfo, actual); Assert.AreEqual( expected.RequestInfo.Headers[DataServiceConstants.AccessTokenHeader], actual.Headers[DataServiceConstants.AccessTokenHeader], "AccessToken header does not match"); Assert.AreEqual( expected.RequestInfo.Cookies[DataServiceConstants.AccessCookie], actual.Cookies[DataServiceConstants.AccessCookie], "AccessCookie does not match"); break; default: Assert.Fail("No more requests expected."); break; } }); UnitTestHelper.ImportAzureModule(powershell); UnitTestHelper.CreateTestCredential( powershell, testSession.SessionProperties["Username"], testSession.SessionProperties["Password"]); Collection <PSObject> serverContext; using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { serverContext = powershell.InvokeBatchScript( string.Format( CultureInfo.InvariantCulture, @"{1} = New-AzureSqlDatabaseServerContext " + @"-ServerName {2} " + @"-ManageUrl {0} " + @"-Credential $credential", MockHttpServer.DefaultServerPrefixUri.AbsoluteUri, contextVariable, testSession.SessionProperties["Servername"]), contextVariable); } } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); PSObject contextPsObject = serverContext.Single(); Assert.IsTrue( contextPsObject.BaseObject is ServerDataServiceSqlAuth, "Expecting a ServerDataServiceSqlAuth object"); }
public void SetAzureSqlDatabaseSizeWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.SetAzureSqlDatabaseSizeWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); if (expected.Index < 10) { // Request 0-2: Set testdb1 with new MaxSize // Request 3-5: Set testdb2 with new MaxSize // Request 6-7: Get updated testdb1 // Request 8-9: Get updated testdb2 DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); } else { Assert.Fail("No more requests expected."); } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { // Create context with both ManageUrl and ServerName overriden Collection <PSObject> database1, database2; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { database1 = powershell.InvokeBatchScript( @"Set-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb1 " + @"-MaxSizeGB 5 " + @"-Force " + @"-PassThru"); // Set the database to 100MB database2 = powershell.InvokeBatchScript( @"Set-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb2 " + @"-MaxSizeBytes 104857600 " + @"-Force " + @"-PassThru"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); Database database = database1.Single().BaseObject as Services.Server.Database; Assert.IsTrue(database != null, "Expecting a Database object"); DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb1", "Web", 5, 5368709120L, "SQL_Latin1_General_CP1_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid); database = database2.Single().BaseObject as Services.Server.Database; Assert.IsTrue(database != null, "Expecting a Database object"); DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb2", "Web", 0, 104857600L, "Japanese_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid); } } }
public void CreatePremiumDatabasesWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTest.Common.CreatePremiumDatabasesWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { Collection <PSObject> premiumDB_P1, PremiumDB_P2; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { powershell.InvokeBatchScript( @"$P1 = Get-AzureSqlDatabaseServiceObjective" + @" -Context $context" + @" -ServiceObjectiveName ""P1"""); powershell.InvokeBatchScript( @"$P2 = Get-AzureSqlDatabaseServiceObjective " + @"-Context $context" + @" -ServiceObjectiveName ""P2"""); premiumDB_P1 = powershell.InvokeBatchScript( @"$premiumDB_P1 = New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName NewAzureSqlPremiumDatabaseTests_P1 " + @"-Edition Premium " + @"-ServiceObjective $P1 "); premiumDB_P1 = powershell.InvokeBatchScript("$PremiumDB_P1"); powershell.InvokeBatchScript( @"$PremiumDB_P2 = New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName NewAzureSqlPremiumDatabaseTests_P2 " + @"-Collation Japanese_CI_AS " + @"-Edition Premium " + @"-ServiceObjective $P2 " + @"-MaxSizeGB 10 " + @"-Force"); PremiumDB_P2 = powershell.InvokeBatchScript("$PremiumDB_P2"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); Assert.IsTrue( premiumDB_P1.Single().BaseObject is Services.Server.Database, "Expecting a Database object"); Services.Server.Database databaseP1 = (Services.Server.Database)premiumDB_P1.Single().BaseObject; Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P1", databaseP1.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P1"); Assert.IsTrue( PremiumDB_P2.Single().BaseObject is Services.Server.Database, "Expecting a Database object"); Services.Server.Database databaseP2 = (Services.Server.Database)PremiumDB_P2.Single().BaseObject; Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P2", databaseP2.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P2"); Assert.AreEqual( "Japanese_CI_AS", databaseP2.CollationName, "Expected collation to be Japanese_CI_AS"); Assert.AreEqual("Premium", databaseP2.Edition, "Expected edition to be Premium"); Assert.AreEqual(10, databaseP2.MaxSizeGB, "Expected max size to be 10 GB"); } } }
public void RemoveAzureSqlDatabaseWithSqlAuth() { using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth( powershell, "$context"); // Create 2 test databases NewAzureSqlDatabaseTests.CreateTestDatabasesWithSqlAuth( powershell, "$context"); HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.RemoveAzureSqlDatabaseWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); if (expected.Index < 8) { // Request 0-5: Remove database requests // Request 6-7: Get all database request DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); } else { Assert.Fail("No more requests expected."); } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { // Create context with both ManageUrl and ServerName overriden Collection <PSObject> databases; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { powershell.InvokeBatchScript( @"Remove-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb1 " + @"-Force"); powershell.InvokeBatchScript( @"Remove-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb2 " + @"-Force"); databases = powershell.InvokeBatchScript( @"Get-AzureSqlDatabase " + @"-Context $context"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); Assert.AreEqual(1, databases.Count, "Expecting only master database object"); } } }
public void GetRestorableDroppedDatabaseWithSqlAuth() { using (var powershell = System.Management.Automation.PowerShell.Create()) { // Create a context NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth(powershell, "$context"); var testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTests.GetRestorableDroppedDatabaseWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.IsNotNull(actual.UserAgent); if (expected.Index < 3) { DatabaseTestHelper.ValidateHeadersForODataRequest(expected.RequestInfo, actual); } else { Assert.Fail("No more requests expected."); } }); using (var exceptionManager = new AsyncExceptionManager()) { Collection <PSObject> databases, database1, database2; using (new MockHttpServer(exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { databases = powershell.InvokeBatchScript( @"Get-AzureSqlDatabase -RestorableDropped " + @"-Context $context"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); // Expecting testdb1, testdb2, possibly dropped databases from previous runs Assert.IsTrue( databases.Count >= 2, "Expecting at-least two RestorableDroppedDatabase objects"); Assert.IsTrue( databases[0].BaseObject is RestorableDroppedDatabase, "Expecting a RestorableDroppedDatabase object"); Assert.IsTrue( databases[1].BaseObject is RestorableDroppedDatabase, "Expecting a RestorableDroppedDatabase object"); var database1Object = (RestorableDroppedDatabase)databases[0].BaseObject; var database1DeletionDate = database1Object.DeletionDate.ToUniversalTime().ToString(deletionDateStringFormat); var database2Object = (RestorableDroppedDatabase)databases[1].BaseObject; var database2DeletionDate = database2Object.DeletionDate.ToUniversalTime().ToString(deletionDateStringFormat); using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { database1 = powershell.InvokeBatchScript( @"Get-AzureSqlDatabase -RestorableDropped " + @"-Context $context " + @"-DatabaseName " + database1Object.Name + @" " + @"-DatabaseDeletionDate " + database1DeletionDate); database2 = powershell.InvokeBatchScript( @"Get-AzureSqlDatabase -RestorableDropped " + @"-Context $context " + @"-DatabaseName " + database2Object.Name + @" " + @"-DatabaseDeletionDate " + database2DeletionDate); } Assert.IsTrue( database1.Single().BaseObject is RestorableDroppedDatabase, "Expecting a RestorableDroppedDatabase object"); var refreshedDatabase1Object = (RestorableDroppedDatabase)database1.Single().BaseObject; Assert.AreEqual( database1Object.Name, refreshedDatabase1Object.Name, "Expected db name to be " + database1Object.Name); Assert.IsTrue( database2.Single().BaseObject is RestorableDroppedDatabase, "Expecting a RestorableDroppedDatabase object"); var refreshedDatabase2Object = (RestorableDroppedDatabase)database2.Single().BaseObject; Assert.AreEqual( database2Object.Name, refreshedDatabase2Object.Name, "Expected db name to be " + database2Object.Name); Assert.AreEqual( database2Object.Edition, refreshedDatabase2Object.Edition, "Expected edition to be " + database2Object.Edition); Assert.AreEqual( database2Object.MaxSizeBytes, refreshedDatabase2Object.MaxSizeBytes, "Expected max size to be " + database2Object.MaxSizeBytes); } } }
/// <summary> /// Create $testdb1 and $testdb2 on the given context. /// </summary> /// <param name="powershell">The powershell instance containing the context.</param> /// <param name="contextVariable">The variable name that holds the server context.</param> public static void CreateTestDatabasesWithSqlAuth( System.Management.Automation.PowerShell powershell, string contextVariable) { HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( "UnitTest.Common.CreateTestDatabasesWithSqlAuth"); DatabaseTestHelper.SetDefaultTestSessionSettings(testSession); testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent); switch (expected.Index) { // Request 0-2: Create testdb1 // Request 3-5: Create testdb2 case 0: case 1: case 2: case 3: case 4: case 5: DatabaseTestHelper.ValidateHeadersForODataRequest( expected.RequestInfo, actual); break; default: Assert.Fail("No more requests expected."); break; } }); using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager()) { Collection <PSObject> database1, database2; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { database1 = powershell.InvokeBatchScript( @"$testdb1 = New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb1 " + @"-Force", @"$testdb1"); database2 = powershell.InvokeBatchScript( @"$testdb2 = New-AzureSqlDatabase " + @"-Context $context " + @"-DatabaseName testdb2 " + @"-Collation Japanese_CI_AS " + @"-Edition Web " + @"-MaxSizeGB 5 " + @"-Force", @"$testdb2"); } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); Assert.IsTrue( database1.Single().BaseObject is Services.Server.Database, "Expecting a Database object"); Services.Server.Database database1Obj = (Services.Server.Database)database1.Single().BaseObject; Assert.AreEqual("testdb1", database1Obj.Name, "Expected db name to be testdb1"); Assert.IsTrue( database2.Single().BaseObject is Services.Server.Database, "Expecting a Database object"); Services.Server.Database database2Obj = (Services.Server.Database)database2.Single().BaseObject; 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("Web", database2Obj.Edition, "Expected edition to be Web"); Assert.AreEqual(5, database2Obj.MaxSizeGB, "Expected max size to be 5 GB"); } }