public void TestSetup() { mockCommandRuntime = new MockCommandRuntime(); cmdlet = new SetAzureServiceProjectRoleCommand(); cmdlet.CommandRuntime = mockCommandRuntime; cmdlet.PassThru = true; }
public void GetAzureSBLocationSuccessfull() { // Setup Mock<ServiceBusClientExtensions> client = new Mock<ServiceBusClientExtensions>(); MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); string name = "test"; GetAzureSBLocationCommand cmdlet = new GetAzureSBLocationCommand() { CommandRuntime = mockCommandRuntime, Client = client.Object }; List<ServiceBusLocation> expected = new List<ServiceBusLocation>(); expected.Add(new ServiceBusLocation { Code = name, FullName = name }); client.Setup(f => f.GetServiceBusRegions()).Returns(expected); // Test cmdlet.ExecuteCmdlet(); // Assert List<ServiceBusLocation> actual = mockCommandRuntime.OutputPipeline[0] as List<ServiceBusLocation>; Assert.AreEqual<int>(expected.Count, actual.Count); for (int i = 0; i < expected.Count; i++) { Assert.AreEqual<string>(expected[i].Code, actual[i].Code); Assert.AreEqual<string>(expected[i].FullName, actual[i].FullName); } }
/// <summary> /// Invoke the Enable-AzureServiceProjectRemoteDesktop enableRDCmdlet. /// </summary> /// <param name="username">Username.</param> /// <param name="password">Password.</param> public static void EnableRemoteDesktop(string username, string password) { SecureString securePassword = null; if (password != null) { securePassword = new SecureString(); foreach (char ch in password) { securePassword.AppendChar(ch); } securePassword.MakeReadOnly(); } if (enableRDCmdlet == null) { enableRDCmdlet = new EnableAzureServiceProjectRemoteDesktopCommand(); if (mockCommandRuntime == null) { mockCommandRuntime = new MockCommandRuntime(); } enableRDCmdlet.CommandRuntime = mockCommandRuntime; } enableRDCmdlet.Username = username; enableRDCmdlet.Password = securePassword; enableRDCmdlet.EnableRemoteDesktop(); }
public void NewAzureSBNamespaceSuccessfull() { // Setup MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock<ServiceBusClientExtensions> client = new Mock<ServiceBusClientExtensions>(); string name = "test"; string location = "West US"; NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand() { Name = name, Location = location, CommandRuntime = mockCommandRuntime, Client = client.Object }; ExtendedServiceBusNamespace expected = new ExtendedServiceBusNamespace { Name = name, Region = location }; client.Setup(f => f.CreateNamespace(name, location)).Returns(expected); client.Setup(f => f.GetServiceBusRegions()).Returns(new List<ServiceBusLocation>() { new ServiceBusLocation () { Code = location } }); // Test cmdlet.ExecuteCmdlet(); // Assert ExtendedServiceBusNamespace actual = mockCommandRuntime.OutputPipeline[0] as ExtendedServiceBusNamespace; Assert.AreEqual<ExtendedServiceBusNamespace>(expected, actual); }
public TenantCmdletTests() { dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; commandRuntimeMock = new MockCommandRuntime(); AzureRmProfileProvider.Instance.Profile = new AzureRMProfile(); }
public SetAzureInstancesTests() { mockCommandRuntime = new MockCommandRuntime(); cmdlet = new SetAzureServiceProjectRoleCommand(); cmdlet.CommandRuntime = mockCommandRuntime; cmdlet.PassThru = true; }
public void GetAzureSBLocationSuccessfull() { // Setup Mock<ServiceBusClientExtensions> client = new Mock<ServiceBusClientExtensions>(); MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); string name = "test"; GetAzureSBLocationCommand cmdlet = new GetAzureSBLocationCommand() { CommandRuntime = mockCommandRuntime, Client = client.Object }; List<ServiceBusLocation> expected = new List<ServiceBusLocation>(); expected.Add(new ServiceBusLocation { Code = name, FullName = name }); client.Setup(f => f.GetServiceBusRegions()).Returns(expected); // Test cmdlet.ExecuteCmdlet(); // Assert IEnumerable<ServiceBusLocation> actual = System.Management.Automation.LanguagePrimitives.GetEnumerable(mockCommandRuntime.OutputPipeline).Cast<ServiceBusLocation>(); Assert.Equal<int>(expected.Count, actual.Count()); for (int i = 0; i < expected.Count; i++) { Assert.True(actual.Any((account) => account.Code == expected[i].Code)); Assert.True(actual.Any((account) => account.FullName == expected[i].FullName)); } }
public void SetAzureServiceProjectTestsLocationValid() { string[] locations = { "West US", "East US", "East Asia", "North Europe" }; foreach (string item in locations) { using (FileSystemHelper files = new FileSystemHelper(this)) { // Create new empty settings file // PowerShellProjectPathInfo paths = new PowerShellProjectPathInfo(files.RootPath); ServiceSettings settings = new ServiceSettings(); mockCommandRuntime = new MockCommandRuntime(); setServiceProjectCmdlet.CommandRuntime = mockCommandRuntime; settings.Save(paths.Settings); settings = setServiceProjectCmdlet.SetAzureServiceProjectProcess(item, null, null, paths.Settings); // Assert location is changed // Assert.AreEqual<string>(item, settings.Location); ServiceSettings actualOutput = mockCommandRuntime.OutputPipeline[0] as ServiceSettings; Assert.AreEqual<string>(item, settings.Location); } } }
public void GetAzureSqlDatabaseServerFirewallRuleProcessTest() { SqlDatabaseFirewallRulesList firewallList = new SqlDatabaseFirewallRulesList(); MockCommandRuntime commandRuntime = new MockCommandRuntime(); SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement(); channel.NewServerFirewallRuleThunk = ar => { Assert.AreEqual("Server1", (string)ar.Values["serverName"]); SqlDatabaseFirewallRule newRule = new SqlDatabaseFirewallRule(); newRule.Name = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).Name; newRule.StartIPAddress = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).StartIPAddress; newRule.EndIPAddress = ((SqlDatabaseFirewallRuleInput)ar.Values["input"]).EndIPAddress; firewallList.Add(newRule); }; channel.GetServerFirewallRulesThunk = ar => { return firewallList; }; // New firewall rule with IpRange parameter set NewAzureSqlDatabaseServerFirewallRule newAzureSqlDatabaseServerFirewallRule = new NewAzureSqlDatabaseServerFirewallRule(channel) { ShareChannel = true }; newAzureSqlDatabaseServerFirewallRule.CurrentSubscription = UnitTestHelpers.CreateUnitTestSubscription(); newAzureSqlDatabaseServerFirewallRule.CommandRuntime = commandRuntime; var newFirewallResult = newAzureSqlDatabaseServerFirewallRule.NewAzureSqlDatabaseServerFirewallRuleProcess("IpRange", "Server1", "Rule1", "0.0.0.0", "1.1.1.1"); Assert.AreEqual("Success", newFirewallResult.OperationStatus); newFirewallResult = newAzureSqlDatabaseServerFirewallRule.NewAzureSqlDatabaseServerFirewallRuleProcess("IpRange", "Server1", "Rule2", "1.1.1.1", "2.2.2.2"); Assert.AreEqual("Success", newFirewallResult.OperationStatus); // Get all rules GetAzureSqlDatabaseServerFirewallRule getAzureSqlDatabaseServerFirewallRule = new GetAzureSqlDatabaseServerFirewallRule(channel) { ShareChannel = true }; getAzureSqlDatabaseServerFirewallRule.CurrentSubscription = UnitTestHelpers.CreateUnitTestSubscription(); getAzureSqlDatabaseServerFirewallRule.CommandRuntime = commandRuntime; var getFirewallResult = getAzureSqlDatabaseServerFirewallRule.GetAzureSqlDatabaseServerFirewallRuleProcess("Server1", null); Assert.AreEqual(2, getFirewallResult.Count()); var firstRule = getFirewallResult.First(); Assert.AreEqual("Server1", firstRule.ServerName); Assert.AreEqual("Rule1", firstRule.RuleName); Assert.AreEqual("0.0.0.0", firstRule.StartIpAddress); Assert.AreEqual("1.1.1.1", firstRule.EndIpAddress); Assert.AreEqual("Success", firstRule.OperationStatus); var lastRule = getFirewallResult.Last(); Assert.AreEqual("Server1", lastRule.ServerName); Assert.AreEqual("Rule2", lastRule.RuleName); Assert.AreEqual("1.1.1.1", lastRule.StartIpAddress); Assert.AreEqual("2.2.2.2", lastRule.EndIpAddress); Assert.AreEqual("Success", lastRule.OperationStatus); // Get one rule getFirewallResult = getAzureSqlDatabaseServerFirewallRule.GetAzureSqlDatabaseServerFirewallRuleProcess("Server1", "Rule2"); Assert.AreEqual(1, getFirewallResult.Count()); firstRule = getFirewallResult.First(); Assert.AreEqual("Server1", firstRule.ServerName); Assert.AreEqual("Rule2", firstRule.RuleName); Assert.AreEqual("1.1.1.1", firstRule.StartIpAddress); Assert.AreEqual("2.2.2.2", firstRule.EndIpAddress); Assert.AreEqual("Success", firstRule.OperationStatus); Assert.AreEqual(0, commandRuntime.ErrorRecords.Count); }
public NewAzureServiceTests() { cmdlet = new NewAzureServiceProjectCommand(); mockCommandRuntime = new MockCommandRuntime(); cmdlet.CommandRuntime = mockCommandRuntime; TestMockSupport.TestExecutionFolder = AppDomain.CurrentDomain.BaseDirectory; }
public ProfileCmdletTests() { dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; commandRuntimeMock = new MockCommandRuntime(); AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(); }
public void InitCommand() { MockCmdRunTime = new MockCommandRuntime(); command = new StorageCloudCmdletBase<IStorageManagement> { CommandRuntime = MockCmdRunTime }; }
public ContextCmdletTests(ITestOutputHelper output) { XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output)); dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; commandRuntimeMock = new MockCommandRuntime(); AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(); }
public DisableAzureRemoteDesktopCommandTest() { AzurePowerShell.ProfileDirectory = Test.Utilities.Common.Data.AzureSdkAppDir; mockCommandRuntime = new MockCommandRuntime(); disableRDCmdlet = new DisableAzureServiceProjectRemoteDesktopCommand(); disableRDCmdlet.CommandRuntime = mockCommandRuntime; }
public void SetupTest() { GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir; mockCommandRuntime = new MockCommandRuntime(); disableRDCmdlet = new DisableAzureServiceProjectRemoteDesktopCommand(); disableRDCmdlet.CommandRuntime = mockCommandRuntime; }
public void GetAzureDedicatedCircuitSuccessful() { // Setup string circuitName = "TestCircuit"; uint bandwidth = 10; string serviceProviderName = "TestProvider"; string location = "us-west"; string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; BillingType billingType = BillingType.MeteredData; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock<ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var dcMock = new Mock<IDedicatedCircuitOperations>(); DedicatedCircuitGetResponse expected = new DedicatedCircuitGetResponse() { DedicatedCircuit = new AzureDedicatedCircuit() { CircuitName = circuitName, Bandwidth = bandwidth, BillingType = billingType.ToString(), Location = location, ServiceProviderName = serviceProviderName, ServiceKey = serviceKey, ServiceProviderProvisioningState = ProviderProvisioningState.NotProvisioned, Status = DedicatedCircuitState.Enabled, }, RequestId = "", StatusCode = new HttpStatusCode() }; var t = new Task<DedicatedCircuitGetResponse>(() => expected); t.Start(); dcMock.Setup(f => f.GetAsync(It.Is<string>(sKey => sKey == serviceKey), It.IsAny<CancellationToken>())).Returns((string sKey, CancellationToken cancellation) => t); client.SetupGet(f => f.DedicatedCircuits).Returns(dcMock.Object); GetAzureDedicatedCircuitCommand cmdlet = new GetAzureDedicatedCircuitCommand() { ServiceKey = Guid.Parse(serviceKey), CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert AzureDedicatedCircuit actual = mockCommandRuntime.OutputPipeline[0] as AzureDedicatedCircuit; Assert.Equal<string>(expected.DedicatedCircuit.BillingType, actual.BillingType); Assert.Equal<string>(expected.DedicatedCircuit.CircuitName, actual.CircuitName); Assert.Equal<uint>(expected.DedicatedCircuit.Bandwidth, actual.Bandwidth); Assert.Equal<string>(expected.DedicatedCircuit.Location, actual.Location); Assert.Equal<string>(expected.DedicatedCircuit.ServiceProviderName, actual.ServiceProviderName); Assert.Equal(expected.DedicatedCircuit.ServiceProviderProvisioningState, actual.ServiceProviderProvisioningState); Assert.Equal(expected.DedicatedCircuit.Status, actual.Status); Assert.Equal<string>(expected.DedicatedCircuit.ServiceKey, actual.ServiceKey); }
public SetAzureServiceProjectTests() { AzurePowerShell.ProfileDirectory = Test.Utilities.Common.Data.AzureSdkAppDir; mockCommandRuntime = new MockCommandRuntime(); setServiceProjectCmdlet = new SetAzureServiceProjectCommand(); setServiceProjectCmdlet.CommandRuntime = mockCommandRuntime; setServiceProjectCmdlet.PassThru = true; }
public void SetupTest() { GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir; mockCommandRuntime = new MockCommandRuntime(); setServiceProjectCmdlet = new SetAzureServiceProjectCommand(); setServiceProjectCmdlet.CommandRuntime = mockCommandRuntime; setServiceProjectCmdlet.PassThru = true; }
public void SetupTest() { this.mockAutomationClient = new Mock<IAutomationClient>(); this.mockCommandRuntime = new MockCommandRuntime(); this.cmdlet = new NewAzureAutomationRunbook { AutomationClient = this.mockAutomationClient.Object, CommandRuntime = this.mockCommandRuntime }; }
public void SetupTest() { this.mockAutomationClient = new Mock<IAutomationClient>(); this.mockCommandRuntime = new MockCommandRuntime(); this.cmdlet = new UnregisterAzureAutomationScheduledRunbook { AutomationClient = this.mockAutomationClient.Object, CommandRuntime = this.mockCommandRuntime }; }
public void SetupTest() { this.mockAutomationClient = new Mock<IAutomationClient>(); this.mockCommandRuntime = new MockCommandRuntime(); this.cmdlet = new RemoveAzureAutomationCredential { AutomationClient = this.mockAutomationClient.Object, CommandRuntime = this.mockCommandRuntime }; }
public void Setup() { mockCommandRuntime = new MockCommandRuntime(); profile = new WindowsAzureProfile(new Mock<IProfileStore>().Object); cmdlet = new ImportAzurePublishSettingsCommand { Profile = profile, CommandRuntime = mockCommandRuntime }; }
public void SetupTest() { GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir; mockCommandRuntime = new MockCommandRuntime(); enableCacheCmdlet = new EnableAzureMemcacheRoleCommand(); addCacheRoleCmdlet = new AddAzureCacheWorkerRoleCommand(); addCacheRoleCmdlet.CommandRuntime = mockCommandRuntime; enableCacheCmdlet.CommandRuntime = mockCommandRuntime; }
public void SetupTest() { this.mockAutomationClient = new Mock<IAutomationClient>(); this.mockCommandRuntime = new MockCommandRuntime(); this.cmdlet = new GetAzureAutomationVariable { AutomationClient = this.mockAutomationClient.Object, CommandRuntime = this.mockCommandRuntime }; }
public GetAzureAutomationHybridWorkerGroupTest() { this.mockAutomationClient = new Mock<IAutomationClient>(); this.mockCommandRuntime = new MockCommandRuntime(); this.cmdlet = new GetAzureAutomationHybridWorkerGroup { AutomationClient = this.mockAutomationClient.Object, CommandRuntime = this.mockCommandRuntime }; }
//[TestInitialize] public void SetupTest() { // CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager(); deploymentUrl = AnyUrl(); roleName = AnyString(); publicPort = AnyIpPort(); secondRolesPublicPort = AnyIpPort(); mockCommandRuntime = new MockCommandRuntime(); }
public void SetupTest() { new FileSystemHelper(this).CreateAzureSdkDirectoryAndImportPublishSettings(); client = new Mock<ServiceBusClientExtensions>(); mockCommandRuntime = new MockCommandRuntime(); cmdlet = new GetAzureSBNamespaceCommand() { CommandRuntime = mockCommandRuntime, Client = client.Object }; }
public EnableAzureMemcacheRoleTests() { AzureTool.IgnoreMissingSDKError = true; AzurePowerShell.ProfileDirectory = Test.Utilities.Common.Data.AzureSdkAppDir; mockCommandRuntime = new MockCommandRuntime(); enableCacheCmdlet = new EnableAzureMemcacheRoleCommand(); addCacheRoleCmdlet = new AddAzureCacheWorkerRoleCommand(); addCacheRoleCmdlet.CommandRuntime = mockCommandRuntime; enableCacheCmdlet.CommandRuntime = mockCommandRuntime; }
public StartAzureServiceTests() { AzurePowerShell.ProfileDirectory = Test.Utilities.Common.Data.AzureSdkAppDir; mockCommandRuntime = new MockCommandRuntime(); cloudServiceClientMock = new Mock<ICloudServiceClient>(); stopServiceCmdlet = new StartAzureServiceCommand() { CloudServiceClient = cloudServiceClientMock.Object, CommandRuntime = mockCommandRuntime }; }
public void SetupTest() { GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir; mockCommandRuntime = new MockCommandRuntime(); cloudServiceClientMock = new Mock<ICloudServiceClient>(); stopServiceCmdlet = new StartAzureServiceCommand() { CloudServiceClient = cloudServiceClientMock.Object, CommandRuntime = mockCommandRuntime }; }
public void InitMock() { tableMock = new MockStorageTableManagement(); MockCmdRunTime = new MockCommandRuntime(); }
public void InitMock() { BlobMock = new MockStorageBlobManagement(); MockCmdRunTime = new MockCommandRuntime(); AzureSession.DataStore = new MemoryDataStore(); }
public void TestSetup() { mockCommandRuntime = new MockCommandRuntime(); clientMock = new Mock <ITrafficManagerClient>(); }
public void InitMock() { BlobMock = new MockStorageBlobManagement(); MockCmdRunTime = new MockCommandRuntime(); }
public NewAzureServiceTests() { cmdlet = new NewAzureServiceProjectCommand(); mockCommandRuntime = new MockCommandRuntime(); cmdlet.CommandRuntime = mockCommandRuntime; }
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 = UnitTestHelpers.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 = UnitTestHelpers.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.ErrorRecords.Count); }
protected RemoteAppClientTest() { mockCommandRuntime = new MockCommandRuntime(); remoteAppManagementClientMock = new Mock <IRemoteAppManagementClient>(); remoteAppManagementClientMock.SetupProperty(c => c.RdfeNamespace, "remoteapp"); }
public void ExportAzureSqlDatabaseProcessTest() { string serverName = "TestServer"; ExportInput input = new ExportInput() { BlobCredentials = new BlobStorageAccessKeyCredentials() { Uri = "blobUri", StorageAccessKey = "storage access key" }, ConnectionInfo = new ConnectionInfo() { DatabaseName = "databaseName", Password = "******", ServerName = "serverName", UserName = "******" } }; Guid guid = Guid.NewGuid(); MockCommandRuntime commandRuntime = new MockCommandRuntime(); SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement(); channel.ExportDatabaseThunk = ar => { Assert.AreEqual(serverName, (string)ar.Values["serverName"]); Assert.AreEqual( input.BlobCredentials.Uri, ((ExportInput)ar.Values["input"]).BlobCredentials.Uri); Assert.AreEqual( input.ConnectionInfo.DatabaseName, ((ExportInput)ar.Values["input"]).ConnectionInfo.DatabaseName); Assert.AreEqual( input.ConnectionInfo.Password, ((ExportInput)ar.Values["input"]).ConnectionInfo.Password); Assert.AreEqual( input.ConnectionInfo.ServerName, ((ExportInput)ar.Values["input"]).ConnectionInfo.ServerName); Assert.AreEqual( input.ConnectionInfo.UserName, ((ExportInput)ar.Values["input"]).ConnectionInfo.UserName); XmlElement operationResult = new XmlDocument().CreateElement( "guid", "http://schemas.microsoft.com/2003/10/Serialization/"); operationResult.InnerText = guid.ToString(); return(operationResult); }; StartAzureSqlDatabaseExport exportAzureSqlDatabase = new StartAzureSqlDatabaseExport(channel) { ShareChannel = true }; exportAzureSqlDatabase.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription(); exportAzureSqlDatabase.CommandRuntime = commandRuntime; var result = exportAzureSqlDatabase.ExportSqlAzureDatabaseProcess(serverName, input); Assert.AreEqual(guid.ToString(), result.RequestGuid); Assert.AreEqual(0, commandRuntime.ErrorStream.Count); }
public void SetupTest() { cmdlet = new NewAzureServiceProjectCommand(); mockCommandRuntime = new MockCommandRuntime(); cmdlet.CommandRuntime = mockCommandRuntime; }
public NewAzureRoleTemplateTests() { AzurePowerShell.ProfileDirectory = Test.Utilities.Common.Data.AzureSdkAppDir; mockCommandRuntime = new MockCommandRuntime(); }
public void ListAzureDedicatedCircuitServiceProviderSuccessful() { // Setup var serviceProviderName = "TestServiceProvider1"; var serviceProviderName2 = "TestServiceProvier2"; var type1 = "IXP"; var type2 = "Telco"; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock <ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var dcsMock = new Mock <IDedicatedCircuitServiceProviderOperations>(); List <AzureDedicatedCircuitServiceProvider> dedicatedCircuitServiceProviders = new List <AzureDedicatedCircuitServiceProvider>() { new AzureDedicatedCircuitServiceProvider() { DedicatedCircuitBandwidths = new DedicatedCircuitBandwidth[1] { new DedicatedCircuitBandwidth() { Bandwidth = 10, Label = "T1" } }, DedicatedCircuitLocations = "us-west", Name = serviceProviderName, Type = type1 }, new AzureDedicatedCircuitServiceProvider() { DedicatedCircuitBandwidths = new DedicatedCircuitBandwidth[1] { new DedicatedCircuitBandwidth() { Bandwidth = 10, Label = "T1" } }, DedicatedCircuitLocations = "us-west", Name = serviceProviderName2, Type = type2 } }; DedicatedCircuitServiceProviderListResponse expected = new DedicatedCircuitServiceProviderListResponse() { DedicatedCircuitServiceProviders = dedicatedCircuitServiceProviders, StatusCode = HttpStatusCode.OK }; var t = new Task <DedicatedCircuitServiceProviderListResponse>(() => expected); t.Start(); dcsMock.Setup(f => f.ListAsync(It.IsAny <CancellationToken>())).Returns((CancellationToken cancellation) => t); client.SetupGet(f => f.DedicatedCircuitServiceProvider).Returns(dcsMock.Object); GetAzureDedicatedCircuitServiceProviderCommand cmdlet = new GetAzureDedicatedCircuitServiceProviderCommand() { CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert IEnumerable <AzureDedicatedCircuitServiceProvider> actual = mockCommandRuntime.OutputPipeline[0] as IEnumerable <AzureDedicatedCircuitServiceProvider>; Assert.AreEqual(actual.ToArray().Count(), 2); }
public AddAzurePythonWebRoleTests() { AzurePowerShell.ProfileDirectory = Test.Utilities.Common.Data.AzureSdkAppDir; mockCommandRuntime = new MockCommandRuntime(); }
public void SetBgpPeeringSuccessful() { // Setup string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; UInt32 peerAsn = 64496; string primaryPeerSubnet = "aaa"; string newPrimaryPeerSubnet = "ccc"; string secondayPeerSubnet = "bbb"; UInt32 azureAsn = 64494; string primaryAzurePort = "8081"; string secondaryAzurePort = "8082"; BgpPeeringState state = BgpPeeringState.Enabled; uint vlanId = 2; BgpPeeringAccessType accessType = BgpPeeringAccessType.Private; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock <ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var bgpMock = new Mock <IBorderGatewayProtocolPeeringOperations>(); BorderGatewayProtocolPeeringGetResponse expected = new BorderGatewayProtocolPeeringGetResponse() { BgpPeering = new AzureBgpPeering() { AzureAsn = azureAsn, PeerAsn = peerAsn, PrimaryAzurePort = primaryAzurePort, PrimaryPeerSubnet = primaryPeerSubnet, SecondaryAzurePort = secondaryAzurePort, SecondaryPeerSubnet = secondayPeerSubnet, State = state, VlanId = vlanId }, RequestId = "", StatusCode = new HttpStatusCode() }; var t = new Task <BorderGatewayProtocolPeeringGetResponse>(() => expected); t.Start(); BorderGatewayProtocolPeeringGetResponse expected2 = new BorderGatewayProtocolPeeringGetResponse() { BgpPeering = new AzureBgpPeering() { AzureAsn = azureAsn, PeerAsn = peerAsn, PrimaryAzurePort = primaryAzurePort, PrimaryPeerSubnet = newPrimaryPeerSubnet, SecondaryAzurePort = secondaryAzurePort, SecondaryPeerSubnet = secondayPeerSubnet, State = state, VlanId = vlanId }, RequestId = "", StatusCode = new HttpStatusCode() }; var t2 = new Task <BorderGatewayProtocolPeeringGetResponse>(() => expected2); t2.Start(); bgpMock.Setup( f => f.GetAsync(It.Is <string>(x => x == serviceKey), It.Is <BgpPeeringAccessType>( y => y == accessType), It.IsAny <CancellationToken>())) .Returns((string sKey, BgpPeeringAccessType atype, CancellationToken cancellation) => t); bgpMock.Setup( f => f.UpdateAsync(It.Is <string>(x => x == serviceKey), It.Is <BgpPeeringAccessType>( y => y == accessType), It.Is <BorderGatewayProtocolPeeringUpdateParameters>(z => z.PrimaryPeerSubnet == newPrimaryPeerSubnet), It.IsAny <CancellationToken>())) .Returns((string sKey, BgpPeeringAccessType atype, BorderGatewayProtocolPeeringUpdateParameters param, CancellationToken cancellation) => t2); client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object); SetAzureBGPPeeringCommand cmdlet = new SetAzureBGPPeeringCommand() { ServiceKey = serviceKey, AccessType = accessType, PrimaryPeerSubnet = newPrimaryPeerSubnet, CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert AzureBgpPeering actual = mockCommandRuntime.OutputPipeline[0] as AzureBgpPeering; Assert.Equal <string>(expected2.BgpPeering.PrimaryPeerSubnet, actual.PrimaryPeerSubnet); Assert.Equal(expected.BgpPeering.PrimaryAzurePort, actual.PrimaryAzurePort); }
private void PerformCollectionTestWithAdInfoHelper( RdsCmdlet mockCmdlet, string collectionName, Collection expectedCollection, String trackingId, CollectionUpdateDetails reqestData, bool forceRedeploy) { ISetup <IRemoteAppManagementClient, Task <CollectionResult> > setupGet = null; ISetup <IRemoteAppManagementClient, Task <OperationResultWithTrackingId> > setupSetApi = null; MockCommandRuntime cmdRuntime = null; IEnumerable <TrackingResult> trackingIds = null; // Setup the environment for testing this cmdlet setupGet = remoteAppManagementClientMock.Setup(c => c.Collections.GetAsync(collectionName, It.IsAny <CancellationToken>())); setupGet.Returns(Task.Factory.StartNew( () => new CollectionResult() { Collection = expectedCollection, StatusCode = System.Net.HttpStatusCode.OK })); setupSetApi = remoteAppManagementClientMock.Setup( c => c.Collections.SetAsync( collectionName, forceRedeploy, false, It.Is <CollectionUpdateDetails>(col => col.CustomRdpProperty == reqestData.CustomRdpProperty && col.Description == reqestData.Description && col.PlanName == reqestData.PlanName && col.TemplateImageName == reqestData.TemplateImageName && (col.AdInfo == null || (reqestData.AdInfo != null && col.AdInfo.DomainName == reqestData.AdInfo.DomainName && col.AdInfo.OrganizationalUnit == reqestData.AdInfo.OrganizationalUnit && col.AdInfo.UserName == reqestData.AdInfo.UserName && col.AdInfo.Password == reqestData.AdInfo.Password) ) ), It.IsAny <CancellationToken>())); setupSetApi.Returns(Task.Factory.StartNew(() => new OperationResultWithTrackingId() { TrackingId = trackingId })); mockCmdlet.ResetPipelines(); mockCmdlet.ExecuteCmdlet(); cmdRuntime = mockCmdlet.runTime(); if (cmdRuntime.ErrorStream.Count > 0) { Assert.True(cmdRuntime.ErrorStream.Count == 0, String.Format("Set-AzureRemoteAppCollection returned the following error {0}", mockCmdlet.runTime().ErrorStream[0].Exception.Message)); } trackingIds = LanguagePrimitives.GetEnumerable(mockCmdlet.runTime().OutputPipeline).Cast <TrackingResult>(); Assert.NotNull(trackingIds); Assert.Equal(1, trackingIds.Count()); Assert.True(trackingIds.Any(t => t.TrackingId == trackingId), "The actual result does not match the expected."); }
public void AddEnvironmentUpdatesContext() { var cmdlet = new AddAzureRMEnvironmentCommand() { CommandRuntime = commandRuntimeMock, Name = "Katal", ARMEndpoint = "https://management.azure.com/", AzureKeyVaultDnsSuffix = "vault.local.azurestack.external", AzureKeyVaultServiceEndpointResourceId = "https://vault.local.azurestack.external" }; var dict = new Dictionary <string, object> { { "ARMEndpoint", "https://management.azure.com/" }, { "AzureKeyVaultDnsSuffix", "vault.local.azurestack.external" }, { "AzureKeyVaultServiceEndpointResourceId", "https://vault.local.azurestack.external" } }; cmdlet.SetBoundParameters(dict); cmdlet.SetParameterSet("ARMEndpoint"); cmdlet.InvokeBeginProcessing(); cmdlet.ExecuteCmdlet(); cmdlet.InvokeEndProcessing(); commandRuntimeMock = new MockCommandRuntime(); var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>()); IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase)); Assert.Equal(env.Name, cmdlet.Name); Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix), dict["AzureKeyVaultDnsSuffix"]); Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId), dict["AzureKeyVaultServiceEndpointResourceId"]); var cmdlet1 = new ConnectAzureRmAccountCommand(); cmdlet1.CommandRuntime = commandRuntimeMock; cmdlet1.Environment = "Katal"; dict.Clear(); dict = new Dictionary <string, object> { { "Environment", cmdlet1.Environment } }; cmdlet1.SetBoundParameters(dict); cmdlet1.InvokeBeginProcessing(); cmdlet1.ExecuteCmdlet(); cmdlet1.InvokeEndProcessing(); commandRuntimeMock = new MockCommandRuntime(); Assert.NotNull(AzureRmProfileProvider.Instance.Profile.DefaultContext); Assert.Equal(AzureRmProfileProvider.Instance.Profile.DefaultContext.Environment.Name, cmdlet1.Environment); var cmdlet2 = new AddAzureRMEnvironmentCommand() { CommandRuntime = commandRuntimeMock, Name = "Katal", ARMEndpoint = "https://management.azure.com/", AzureKeyVaultDnsSuffix = "adminvault.local.azurestack.external", AzureKeyVaultServiceEndpointResourceId = "https://adminvault.local.azurestack.external" }; dict.Clear(); dict = new Dictionary <string, object> { { "ARMEndpoint", "https://management.azure.com/" }, { "AzureKeyVaultDnsSuffix", "adminvault.local.azurestack.external" }, { "AzureKeyVaultServiceEndpointResourceId", "https://adminvault.local.azurestack.external" } }; cmdlet2.SetBoundParameters(dict); cmdlet2.SetParameterSet("ARMEndpoint"); cmdlet2.InvokeBeginProcessing(); cmdlet2.ExecuteCmdlet(); cmdlet2.InvokeEndProcessing(); profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>()); env = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase)); Assert.Equal(env.Name, cmdlet.Name); Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix), dict["AzureKeyVaultDnsSuffix"]); Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId), dict["AzureKeyVaultServiceEndpointResourceId"]); var context = AzureRmProfileProvider.Instance.Profile.DefaultContext; Assert.NotNull(context); Assert.NotNull(context.Environment); Assert.Equal(context.Environment.Name, env.Name); Assert.Equal(context.Environment.AzureKeyVaultDnsSuffix, env.AzureKeyVaultDnsSuffix); Assert.Equal(context.Environment.AzureKeyVaultServiceEndpointResourceId, env.AzureKeyVaultServiceEndpointResourceId); }
public void ListAzureDedicatedCircuitSuccessful() { // Setup string circuitName1 = "TestCircuit"; uint bandwidth1 = 10; string serviceProviderName1 = "TestProvider"; string location1 = "us-west"; string serviceKey1 = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; BillingType billingType1 = BillingType.MeteredData; string circuitName2 = "TestCircuit2"; uint bandwidth2 = 10; string serviceProviderName2 = "TestProvider"; string location2 = "us-north"; string serviceKey2 = "bc28cd19-b10a-41ff-981b-53c6bbf15ead"; BillingType billingType2 = BillingType.UnlimitedData; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock <ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var dcMock = new Mock <IDedicatedCircuitOperations>(); List <AzureDedicatedCircuit> dedicatedCircuits = new List <AzureDedicatedCircuit>() { new AzureDedicatedCircuit() { Bandwidth = bandwidth1, BillingType = billingType1.ToString(), CircuitName = circuitName1, ServiceKey = serviceKey1, Location = location1, ServiceProviderName = serviceProviderName1, ServiceProviderProvisioningState = ProviderProvisioningState.NotProvisioned, Status = DedicatedCircuitState.Enabled }, new AzureDedicatedCircuit() { Bandwidth = bandwidth2, BillingType = billingType2.ToString(), CircuitName = circuitName2, ServiceKey = serviceKey2, Location = location2, ServiceProviderName = serviceProviderName2, ServiceProviderProvisioningState = ProviderProvisioningState.Provisioned, Status = DedicatedCircuitState.Enabled } }; DedicatedCircuitListResponse expected = new DedicatedCircuitListResponse() { DedicatedCircuits = dedicatedCircuits, StatusCode = HttpStatusCode.OK }; var t = new Task <DedicatedCircuitListResponse>(() => expected); t.Start(); dcMock.Setup(f => f.ListAsync(It.IsAny <CancellationToken>())).Returns((CancellationToken cancellation) => t); client.SetupGet(f => f.DedicatedCircuits).Returns(dcMock.Object); GetAzureDedicatedCircuitCommand cmdlet = new GetAzureDedicatedCircuitCommand() { CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert IEnumerable <AzureDedicatedCircuit> actual = LanguagePrimitives.GetEnumerable(mockCommandRuntime.OutputPipeline).Cast <AzureDedicatedCircuit>(); Assert.Equal(actual.Count(), 2); }
public void TestSetup() { mockCommandRuntime = new MockCommandRuntime(); }
public ReservedIPTest() { this.networkingClientMock = new Mock <NetworkManagementClient>(); this.computeClientMock = new Mock <ComputeManagementClient>(); this.managementClientMock = new Mock <ManagementClient>(); this.storageClientMock = new Mock <StorageManagementClient>(); this.mockCommandRuntime = new MockCommandRuntime(); testClientProvider = new TestClientProvider(this.managementClientMock.Object, this.computeClientMock.Object, this.storageClientMock.Object, this.networkingClientMock.Object); this.computeClientMock .Setup(c => c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Production, It.IsAny <CancellationToken>())) .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse() { Name = DeploymentName })); this.computeClientMock .Setup( c => c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Staging, It.IsAny <CancellationToken>())) .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse() { Name = DeploymentName })); // Reserve IP simple this.networkingClientMock .Setup(c => c.ReservedIPs.CreateAsync( It.Is <NetworkReservedIPCreateParameters>( p => string.Equals(p.Name, ReservedIPName) && string.IsNullOrEmpty(p.ServiceName) && string.IsNullOrEmpty(p.VirtualIPName) && string.IsNullOrEmpty(p.DeploymentName)), It.IsAny <CancellationToken>())) .Returns(Task.Factory.StartNew(() => new OperationStatusResponse() { Status = OperationStatus.Succeeded })); // Reserve in use IP single vip this.networkingClientMock .Setup(c => c.ReservedIPs.CreateAsync( It.Is <NetworkReservedIPCreateParameters>( p => string.Equals(p.Name, ReservedIPName) && string.Equals(p.ServiceName, ServiceName) && string.IsNullOrEmpty(p.VirtualIPName) && string.Equals(p.DeploymentName, DeploymentName)), It.IsAny <CancellationToken>())) .Returns(Task.Factory.StartNew(() => new OperationStatusResponse() { Status = OperationStatus.Succeeded })); // Reserve in use IP named vip this.networkingClientMock .Setup(c => c.ReservedIPs.CreateAsync( It.Is <NetworkReservedIPCreateParameters>( p => string.Equals(p.Name, ReservedIPName) && string.Equals(p.ServiceName, ServiceName) && string.Equals(p.VirtualIPName, VipName) && string.Equals(p.DeploymentName, DeploymentName)), It.IsAny <CancellationToken>())) .Returns(Task.Factory.StartNew(() => new OperationStatusResponse() { Status = OperationStatus.Succeeded })); // Associate a reserved IP with a deployment this.networkingClientMock .Setup(c => c.ReservedIPs.AssociateAsync( ReservedIPName, It.Is <NetworkReservedIPMobilityParameters>( p => string.Equals(p.ServiceName, ServiceName) && string.IsNullOrEmpty(p.VirtualIPName) && string.Equals(p.DeploymentName, DeploymentName)), It.IsAny <CancellationToken>())) .Returns(Task.Factory.StartNew(() => new OperationStatusResponse() { Status = OperationStatus.Succeeded })); // Associate a reserved IP with a vip this.networkingClientMock .Setup(c => c.ReservedIPs.AssociateAsync( ReservedIPName, It.Is <NetworkReservedIPMobilityParameters>( p => string.Equals(p.ServiceName, ServiceName) && string.Equals(p.VirtualIPName, VipName) && string.Equals(p.DeploymentName, DeploymentName)), It.IsAny <CancellationToken>())) .Returns(Task.Factory.StartNew(() => new OperationStatusResponse() { Status = OperationStatus.Succeeded })); // Remove Azure Reserved IP this.networkingClientMock .Setup(c => c.ReservedIPs.DeleteAsync( ReservedIPName, It.IsAny <CancellationToken>())) .Returns(Task.Factory.StartNew(() => new OperationStatusResponse() { Status = OperationStatus.Succeeded })); }
public void SetupTest() { GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir; CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager(); mockCommandRuntime = new MockCommandRuntime(); }
public void HandlesExceptionError() { var runtime = new MockCommandRuntime(); var request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://www.contoso.com/resource?api-version-1.0")); request.Headers.Add("x-ms-request-id", "HyakRequestId"); var response = new HttpResponseMessage(HttpStatusCode.BadRequest); var hyakException = new TestHyakException("exception message", CloudHttpRequestErrorInfo.Create(request), CloudHttpResponseErrorInfo.Create(response)) { Error = new Hyak.Common.CloudError { Code = "HyakCode", Message = "HyakError" } }; var autorestException = new Microsoft.Rest.Azure.CloudException("exception message") { Body = new Microsoft.Rest.Azure.CloudError { Code = "AutorestCode", Message = "Autorest message" }, Request = new Rest.HttpRequestMessageWrapper(request, ""), Response = new Rest.HttpResponseMessageWrapper(response, ""), RequestId = "AutoRestRequestId" }; var cmdlet = new ResolveError { Error = new [] { new ErrorRecord(new Exception("exception message"), "errorCode", ErrorCategory.AuthenticationError, this), new ErrorRecord(hyakException, "errorCode", ErrorCategory.ConnectionError, this), new ErrorRecord(autorestException, "errorCode", ErrorCategory.InvalidOperation, this), }, CommandRuntime = runtime }; cmdlet.ExecuteCmdlet(); Assert.NotNull(runtime.OutputPipeline); Assert.Equal(3, runtime.OutputPipeline.Count); var errorResult = runtime.OutputPipeline[0] as AzureExceptionRecord; Assert.NotNull(errorResult); Assert.Equal(ErrorCategory.AuthenticationError, errorResult.ErrorCategory.Category); Assert.NotNull(errorResult.Exception); Assert.Equal(typeof(Exception), errorResult.Exception.GetType()); Assert.Equal("exception message", errorResult.Exception.Message); var hyakResult = runtime.OutputPipeline[1] as AzureRestExceptionRecord; Assert.NotNull(hyakResult); Assert.Equal(ErrorCategory.ConnectionError, hyakResult.ErrorCategory.Category); Assert.NotNull(errorResult.Exception); Assert.Equal(typeof(TestHyakException), hyakResult.Exception.GetType()); Assert.Equal("exception message", hyakResult.Exception.Message); Assert.NotNull(hyakResult.RequestMessage); Assert.Equal(HttpMethod.Get.ToString(), hyakResult.RequestMessage.Verb); Assert.Equal(new Uri("https://www.contoso.com/resource?api-version-1.0"), hyakResult.RequestMessage.Uri); Assert.NotNull(hyakResult.ServerResponse); Assert.Equal(HttpStatusCode.BadRequest.ToString(), hyakResult.ServerResponse.ResponseStatusCode); var autorestResult = runtime.OutputPipeline[2] as AzureRestExceptionRecord; Assert.NotNull(autorestResult); Assert.Equal(ErrorCategory.InvalidOperation, autorestResult.ErrorCategory.Category); Assert.NotNull(autorestResult.Exception); Assert.Equal(typeof(Microsoft.Rest.Azure.CloudException), autorestResult.Exception.GetType()); Assert.Equal("exception message", autorestResult.Exception.Message); Assert.NotNull(autorestResult.RequestMessage); Assert.Equal(HttpMethod.Get.ToString(), autorestResult.RequestMessage.Verb); Assert.Equal(new Uri("https://www.contoso.com/resource?api-version-1.0"), autorestResult.RequestMessage.Uri); Assert.NotNull(autorestResult.ServerResponse); Assert.Equal(HttpStatusCode.BadRequest.ToString(), autorestResult.ServerResponse.ResponseStatusCode); Assert.Equal("AutoRestRequestId", autorestResult.RequestId); Assert.Contains("AutorestCode", autorestResult.ServerMessage); Assert.Contains("Autorest message", autorestResult.ServerMessage); }
public void NewAzureDedicatedCircuitSuccessful() { // Setup string circuitName = "TestCircuit"; uint bandwidth = 10; string serviceProviderName = "TestProvider"; string location = "us-west"; string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock <ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var dcMock = new Mock <IDedicatedCircuitOperations>(); DedicatedCircuitGetResponse expected = new DedicatedCircuitGetResponse() { DedicatedCircuit = new AzureDedicatedCircuit() { CircuitName = circuitName, Bandwidth = bandwidth, Location = location, ServiceProviderName = serviceProviderName, ServiceKey = serviceKey, ServiceProviderProvisioningState = ProviderProvisioningState.NotProvisioned, Status = DedicatedCircuitState.Enabled, }, RequestId = "", StatusCode = new HttpStatusCode() }; var tGet = new Task <DedicatedCircuitGetResponse>(() => expected); tGet.Start(); ExpressRouteOperationStatusResponse expectedStatus = new ExpressRouteOperationStatusResponse() { HttpStatusCode = HttpStatusCode.OK, Data = serviceKey }; var tNew = new Task <ExpressRouteOperationStatusResponse>(() => expectedStatus); tNew.Start(); dcMock.Setup(f => f.NewAsync(It.Is <DedicatedCircuitNewParameters>(x => x.Bandwidth == bandwidth && x.CircuitName == circuitName && x.Location == location && x.ServiceProviderName == serviceProviderName), It.IsAny <CancellationToken>())).Returns((DedicatedCircuitNewParameters param, CancellationToken cancellation) => tNew); dcMock.Setup(f => f.GetAsync(It.Is <string>(sKey => sKey == serviceKey), It.IsAny <CancellationToken>())).Returns((string sKey, CancellationToken cancellation) => tGet); client.SetupGet(f => f.DedicatedCircuits).Returns(dcMock.Object); NewAzureDedicatedCircuitCommand cmdlet = new NewAzureDedicatedCircuitCommand() { CircuitName = circuitName, Bandwidth = bandwidth, Location = location, ServiceProviderName = serviceProviderName, CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert AzureDedicatedCircuit actual = mockCommandRuntime.OutputPipeline[0] as AzureDedicatedCircuit; Assert.Equal <string>(expected.DedicatedCircuit.CircuitName, actual.CircuitName); Assert.Equal <uint>(expected.DedicatedCircuit.Bandwidth, actual.Bandwidth); Assert.Equal <string>(expected.DedicatedCircuit.Location, actual.Location); Assert.Equal <string>(expected.DedicatedCircuit.ServiceProviderName, actual.ServiceProviderName); Assert.Equal(expected.DedicatedCircuit.ServiceProviderProvisioningState, actual.ServiceProviderProvisioningState); Assert.Equal(expected.DedicatedCircuit.Status, actual.Status); Assert.Equal <string>(expected.DedicatedCircuit.ServiceKey, actual.ServiceKey); }
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 = UnitTestHelpers.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 = UnitTestHelpers.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 = UnitTestHelpers.CreateUnitTestSubscription(); removeAzureSqlDatabaseServer.CommandRuntime = commandRuntime; var removeServerContext = removeAzureSqlDatabaseServer.RemoveAzureSqlDatabaseServerProcess("TestServer0"); // Verify only one server is left getAzureSqlDatabaseServer = new GetAzureSqlDatabaseServer(channel) { ShareChannel = true }; getAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelpers.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.ErrorRecords.Count); // Remove TestServer0 again removeAzureSqlDatabaseServer = new RemoveAzureSqlDatabaseServer(channel) { ShareChannel = true }; removeAzureSqlDatabaseServer.CurrentSubscription = UnitTestHelpers.CreateUnitTestSubscription(); removeAzureSqlDatabaseServer.CommandRuntime = commandRuntime; removeServerContext = removeAzureSqlDatabaseServer.RemoveAzureSqlDatabaseServerProcess("TestServer0"); Assert.AreEqual(1, commandRuntime.ErrorRecords.Count); Assert.IsTrue(commandRuntime.WarningOutput.Length > 0); }
public void ProcessNewWebsiteTest() { const string websiteName = "website1"; const string webspaceName = "webspace1"; const string suffix = "azurewebsites.com"; // Setup Mock <IWebsitesClient> clientMock = new Mock <IWebsitesClient>(); clientMock.Setup(c => c.GetWebsiteDnsSuffix()).Returns(suffix); clientMock.Setup(f => f.GetWebsite(websiteName)).Returns(new Site() { Name = websiteName }); clientMock.Setup(f => f.GetWebsiteConfiguration(websiteName, null)).Returns(new SiteConfig() { PublishingUsername = "******" }); clientMock.Setup(c => c.ListWebSpaces()) .Returns(new[] { new WebSpace { Name = "webspace1", GeoRegion = "webspace1" }, new WebSpace { Name = "webspace2", GeoRegion = "webspace2" } }); clientMock.Setup(c => c.GetWebsiteConfiguration("website1")) .Returns(new SiteConfig { PublishingUsername = "******" }); string createdSiteName = null; string createdWebspaceName = null; clientMock.Setup(c => c.CreateWebsite(webspaceName, It.IsAny <SiteWithWebSpace>(), null)) .Returns((string space, SiteWithWebSpace site, string slot) => site) .Callback((string space, SiteWithWebSpace site, string slot) => { createdSiteName = site.Name; createdWebspaceName = space; }); // Test MockCommandRuntime mockRuntime = new MockCommandRuntime(); NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand { ShareChannel = true, CommandRuntime = mockRuntime, Name = websiteName, Location = webspaceName, WebsitesClient = clientMock.Object }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(base.subscriptionId) }, null, null); newAzureWebsiteCommand.ExecuteCmdlet(); Assert.Equal(websiteName, createdSiteName); Assert.Equal(webspaceName, createdWebspaceName); Assert.Equal <string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name); }
public void SetupTest() { GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir; mockCommandRuntime = new MockCommandRuntime(); }
public void TestSetup() { mockCommandRuntime = new MockCommandRuntime(); newServiceCmdlet = new NewAzureServiceProjectCommand(); newServiceCmdlet.CommandRuntime = mockCommandRuntime; }
public StorageTableStorageTestBase() { tableMock = new MockStorageTableManagement(); MockCmdRunTime = new MockCommandRuntime(); }
public void ProcessNewWebsiteTest() { const string websiteName = "website1"; const string webspaceName = "webspace1"; const string suffix = "azurewebsites.com"; // Setup Mock <IWebsitesClient> clientMock = new Mock <IWebsitesClient>(); clientMock.Setup(f => f.GetWebsiteDnsSuffix()).Returns(suffix); bool created = true; SimpleWebsitesManagement channel = new SimpleWebsitesManagement(); channel.GetWebSpacesThunk = ar => new WebSpaces(new List <WebSpace> { new WebSpace { Name = "webspace1", GeoRegion = "webspace1" }, new WebSpace { Name = "webspace2", GeoRegion = "webspace2" } }); channel.GetSiteConfigThunk = ar => { if (ar.Values["name"].Equals("website1") && ar.Values["webspaceName"].Equals("webspace1")) { return(new SiteConfig { PublishingUsername = "******" }); } return(null); }; channel.CreateSiteThunk = ar => { Assert.AreEqual(webspaceName, ar.Values["webspaceName"]); Site website = ar.Values["site"] as Site; Assert.IsNotNull(website); Assert.AreEqual(websiteName, website.Name); Assert.IsNotNull(website.HostNames.FirstOrDefault(hostname => hostname.Equals(string.Format("{0}.{1}", websiteName, suffix)))); created = true; return(website); }; // Test MockCommandRuntime mockRuntime = new MockCommandRuntime(); NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand(channel) { ShareChannel = true, CommandRuntime = mockRuntime, Name = websiteName, Location = webspaceName, CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionId }, WebsitesClient = clientMock.Object }; newAzureWebsiteCommand.ExecuteCmdlet(); Assert.IsTrue(created); Assert.AreEqual <string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name); }
public void InitMock() { queueMock = new MockStorageQueueManagement(); MockCmdRunTime = new MockCommandRuntime(); }
public void NewAzureBgpPeeringSuccessful() { // Setup string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; UInt32 peerAsn = 64496; string primaryPeerSubnet = "aaa"; string secondayPeerSubnet = "bbb"; UInt32 azureAsn = 64494; string primaryAzurePort = "8081"; string secondaryAzurePort = "8082"; var state = BgpPeeringState.Enabled; uint vlanId = 2; var accessType = BgpPeeringAccessType.Private; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock <ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var bgpMock = new Mock <IBorderGatewayProtocolPeeringOperations>(); BorderGatewayProtocolPeeringGetResponse expectedBgp = new BorderGatewayProtocolPeeringGetResponse { BgpPeering = new AzureBgpPeering() { AzureAsn = azureAsn, PeerAsn = peerAsn, PrimaryAzurePort = primaryAzurePort, PrimaryPeerSubnet = primaryPeerSubnet, SecondaryAzurePort = secondaryAzurePort, SecondaryPeerSubnet = secondayPeerSubnet, State = state, VlanId = vlanId }, RequestId = "", StatusCode = new HttpStatusCode() }; ExpressRouteOperationStatusResponse expectedStatus = new ExpressRouteOperationStatusResponse() { HttpStatusCode = HttpStatusCode.OK }; var tGet = new Task <BorderGatewayProtocolPeeringGetResponse>(() => expectedBgp); tGet.Start(); var tNew = new Task <ExpressRouteOperationStatusResponse>(() => expectedStatus); tNew.Start(); bgpMock.Setup( f => f.NewAsync(It.Is <string>(x => x == serviceKey), It.Is <BgpPeeringAccessType>( y => y == accessType), It.Is <BorderGatewayProtocolPeeringNewParameters>( z => z.PeerAutonomousSystemNumber == peerAsn && z.PrimaryPeerSubnet == primaryPeerSubnet && z.SecondaryPeerSubnet == secondayPeerSubnet && z.VirtualLanId == vlanId), It.IsAny <CancellationToken>())) .Returns((string sKey, BgpPeeringAccessType atype, BorderGatewayProtocolPeeringNewParameters param, CancellationToken cancellation) => tNew); client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object); bgpMock.Setup( f => f.GetAsync(It.Is <string>(x => x == serviceKey), It.Is <BgpPeeringAccessType>( y => y == accessType), It.IsAny <CancellationToken>())) .Returns((string sKey, BgpPeeringAccessType atype, CancellationToken cancellation) => tGet); client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object); NewAzureBGPPeeringCommand cmdlet = new NewAzureBGPPeeringCommand() { ServiceKey = Guid.Parse(serviceKey), AccessType = accessType, PeerAsn = peerAsn, PrimaryPeerSubnet = primaryPeerSubnet, SecondaryPeerSubnet = secondayPeerSubnet, SharedKey = null, VlanId = vlanId, CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert AzureBgpPeering actual = mockCommandRuntime.OutputPipeline[0] as AzureBgpPeering; Assert.Equal(expectedBgp.BgpPeering.State, actual.State); Assert.Equal(expectedBgp.BgpPeering.PrimaryAzurePort, actual.PrimaryAzurePort); }
public AzureServiceTests() { AzureTool.IgnoreMissingSDKError = true; AzurePowerShell.ProfileDirectory = Test.Utilities.Common.Data.AzureSdkAppDir; mockCommandRuntime = new MockCommandRuntime(); }