public void StartAzureSqlDatabaseContinuousCopyWithSqlAuth() { 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"); // Start a continuous database copy operation StartAzureSqlDatabaseCopyTests.StartDatabaseContinuousCopyWithSqlAuth( powershell, "$context", "$copy", "testdb1"); } }
public void GetAzureSqlDatabaseContinuousCopyWithSqlAuth() { 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"); // Start two continuous database copy operation StartAzureSqlDatabaseCopyTests.StartDatabaseContinuousCopyWithSqlAuth( powershell, "$context", "$copy1", "testdb1"); StartAzureSqlDatabaseCopyTests.StartDatabaseContinuousCopyWithSqlAuth( powershell, "$context", "$copy2", "testdb2"); HttpSession testSession = DatabaseTestHelper.DefaultSessionCollection.GetSession( "UnitTest.GetAzureSqlDatabaseContinuousCopyWithSqlAuth"); 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 all database copies request case 0: case 1: // Request 2-3: Get database copies for testdb1 case 2: case 3: // Request 4-5: Get database copies for testdb2 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> databaseCopies, databaseCopy1, databaseCopy2; using (new MockHttpServer( exceptionManager, MockHttpServer.DefaultServerPrefixUri, testSession)) { databaseCopies = powershell.InvokeBatchScript( @"Get-AzureSqlDatabaseCopy " + @"-Context $context"); databaseCopy1 = powershell.InvokeBatchScript( @"Get-AzureSqlDatabaseCopy " + @"-Context $context " + @"-DatabaseName testdb1"); databaseCopy2 = powershell.InvokeBatchScript( @"Get-AzureSqlDatabaseCopy " + @"-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(); Assert.AreEqual(2, databaseCopies.Count, "Expecting 2 Database Copy objects"); Assert.IsTrue( databaseCopy1.First().BaseObject is Services.Server.DatabaseCopy, "Expecting a Database Copy object"); Services.Server.DatabaseCopy databaseCopyObj = (Services.Server.DatabaseCopy)databaseCopy1.Single().BaseObject; Assert.AreEqual( "testserver", databaseCopyObj.SourceServerName, "Expected source server name to be testserver"); Assert.AreEqual( "testdb1", databaseCopyObj.SourceDatabaseName, "Expected source database name to be testdb1"); Assert.AreEqual( "partnersrv", databaseCopyObj.DestinationServerName, "Expected destination server name to be partnersrv"); Assert.AreEqual( "testdb1", databaseCopyObj.DestinationDatabaseName, "Expected destination database name to be testdb1"); Assert.IsTrue( databaseCopyObj.IsContinuous, "Expected copy to be continuous"); Assert.IsTrue( databaseCopy2.First().BaseObject is Services.Server.DatabaseCopy, "Expecting a Database Copy object"); databaseCopyObj = (Services.Server.DatabaseCopy)databaseCopy2.Single().BaseObject; Assert.AreEqual( "testserver", databaseCopyObj.SourceServerName, "Expected source server name to be testserver"); Assert.AreEqual( "testdb2", databaseCopyObj.SourceDatabaseName, "Expected source database name to be testdb2"); Assert.AreEqual( "partnersrv", databaseCopyObj.DestinationServerName, "Expected destination server name to be partnersrv"); Assert.AreEqual( "testdb2", databaseCopyObj.DestinationDatabaseName, "Expected destination database name to be testdb2"); Assert.IsTrue( databaseCopyObj.IsContinuous, "Expected copy to be continuous"); } } }
public void StopAzureSqlDatabaseContinuousCopyWithSqlAuth() { 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"); // Start two continuous database copy operation StartAzureSqlDatabaseCopyTests.StartDatabaseContinuousCopyWithSqlAuth( powershell, "$context", "$copy1", "testdb1"); GetAzureSqlDatabaseCopyTests.WaitContinuousCopyCatchup( powershell, "$context", "$copy1"); HttpSession testSession = DatabaseTestHelper.DefaultSessionCollection.GetSession( "UnitTest.StopAzureSqlDatabaseContinuousCopyWithSqlAuth"); 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: Stop Database Copy case 0: case 1: case 2: // Request 3-4: Retrieve all copies case 3: case 4: 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( @"Stop-AzureSqlDatabaseCopy " + @"-Context $context " + @"-DatabaseName testdb1"); } } Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!"); Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!"); powershell.Streams.ClearStreams(); WaitForCopyTermination(powershell, "$context"); } }