public void UpdatesRemote() { // Setup var mockClient = new Mock <IWebsitesClient>(); string slot = WebsiteSlotName.Staging.ToString(); SiteProperties props = new SiteProperties() { Properties = new List <NameValuePair>() { new NameValuePair() { Name = "RepositoryUri", Value = "https://[email protected]:443/website.git" }, new NameValuePair() { Name = "PublishingUsername", Value = "test" } } }; mockClient.Setup(c => c.GetWebsiteSlots("website1")) .Returns( new List <Site> { new Site { Name = "website1", WebSpace = "webspace1", SiteProperties = props }, new Site { Name = "website1(staging)", WebSpace = "webspace1", SiteProperties = props } }); mockClient.Setup(c => c.GetSlotName("website1")) .Returns(WebsiteSlotName.Production.ToString()) .Verifiable(); mockClient.Setup(c => c.GetSlotName("website1(staging)")) .Returns(WebsiteSlotName.Staging.ToString()) .Verifiable(); // Test UpdateAzureWebsiteRepositoryCommand cmdlet = new UpdateAzureWebsiteRepositoryCommand { CommandRuntime = new MockCommandRuntime(), WebsitesClient = mockClient.Object, Name = "website1", }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(base.subscriptionId) }, null, null); // Switch existing website cmdlet.ExecuteCmdlet(); mockClient.Verify(c => c.GetSlotName("website1(staging)"), Times.Once()); mockClient.Verify(c => c.GetSlotName("website1"), Times.Once()); }
public void CreateStageSlot() { string slot = "staging"; 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(c => c.ListWebSpaces()) .Returns(new[] { new WebSpace { Name = "webspace1", GeoRegion = "webspace1" }, new WebSpace { Name = "webspace2", GeoRegion = "webspace2" } }); clientMock.Setup(c => c.GetWebsiteConfiguration("website1", slot)) .Returns(new SiteConfig { PublishingUsername = "******" }); clientMock.Setup(f => f.WebsiteExists(websiteName)).Returns(true); clientMock.Setup(f => f.GetWebsite(websiteName)).Returns(new Site() { Name = websiteName, Sku = SkuOptions.Standard, WebSpace = webspaceName }); // Test MockCommandRuntime mockRuntime = new MockCommandRuntime(); NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand { ShareChannel = true, CommandRuntime = mockRuntime, Name = websiteName, Location = webspaceName, WebsitesClient = clientMock.Object, Slot = slot }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(base.subscriptionId) }, null, null); newAzureWebsiteCommand.ExecuteCmdlet(); clientMock.Verify(c => c.CreateWebsite(webspaceName, It.IsAny <SiteWithWebSpace>(), slot), Times.Once()); }
public void ProcessGetWebsiteWithNullSubscription() { // Test var getAzureWebsiteCommand = new GetAzureWebsiteCommand { CommandRuntime = new MockCommandRuntime() }; AzureSession.SetCurrentContext(null, null, null); Testing.AssertThrows <Exception>(getAzureWebsiteCommand.ExecuteCmdlet, Resources.InvalidCurrentSubscription); }
public void GetsWebsiteDefaultLocation() { const string websiteName = "website1"; const string suffix = "azurewebsites.com"; const string location = "West US"; bool created = false; // Setup Mock <IWebsitesClient> clientMock = new Mock <IWebsitesClient>(); clientMock.Setup(c => c.GetWebsiteDnsSuffix()).Returns(suffix); clientMock.Setup(c => c.GetDefaultLocation()).Returns(location); clientMock.Setup(c => c.ListWebSpaces()).Returns(new WebSpaces()); clientMock.Setup(c => c.GetWebsite(websiteName)).Returns(new Site() { Name = websiteName }); clientMock.Setup(c => c.GetWebsiteConfiguration(websiteName, null)) .Returns(new SiteConfig { PublishingUsername = "******" }); clientMock.Setup(c => c.CreateWebsite(It.IsAny <string>(), It.IsAny <SiteWithWebSpace>(), null)) .Returns((string space, SiteWithWebSpace site, string slot) => site) .Callback((string space, SiteWithWebSpace site, string slot) => { created = true; }); // Test MockCommandRuntime mockRuntime = new MockCommandRuntime(); NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand() { ShareChannel = true, CommandRuntime = mockRuntime, Name = websiteName, WebsitesClient = clientMock.Object }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(base.subscriptionId) }, null, null); newAzureWebsiteCommand.ExecuteCmdlet(); Assert.True(created); Assert.Equal <string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name); clientMock.Verify(f => f.GetDefaultLocation(), Times.Once()); }
public void ProcessGetWebsiteTest() { // Setup var clientMock = new Mock <IWebsitesClient>(); clientMock.Setup(c => c.ListWebSpaces()) .Returns(new[] { new WebSpace { Name = "webspace1" }, new WebSpace { Name = "webspace2" } }); clientMock.Setup(c => c.ListSitesInWebSpace("webspace1")) .Returns(new[] { new Site { Name = "website1", WebSpace = "webspace1" } }); clientMock.Setup(c => c.ListSitesInWebSpace("webspace2")) .Returns(new[] { new Site { Name = "website2", WebSpace = "webspace2" } }); clientMock.Setup(c => c.ListWebsites()) .Returns(new List <Site> { new Site { Name = "website1", WebSpace = "webspace1" }, new Site { Name = "website2", WebSpace = "webspace2" } }); // Test var getAzureWebsiteCommand = new GetAzureWebsiteCommand { CommandRuntime = new MockCommandRuntime(), WebsitesClient = clientMock.Object }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(subscriptionId) }, null, null); getAzureWebsiteCommand.ExecuteCmdlet(); Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count); var sites = (IEnumerable <Site>)((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.NotNull(sites); Assert.True(sites.Any(website => (website).Name.Equals("website1") && (website).WebSpace.Equals("webspace1"))); Assert.True(sites.Any(website => (website).Name.Equals("website2") && (website).WebSpace.Equals("webspace2"))); }
private async void LogSessionStatus(AzureSession session) { if (session != null) { var sessionProperties = await session.GetPropertiesAsync().AsTask(); LogSessionStatus(sessionProperties); } else { var sessionProperties = arrService.LastProperties; Debug.Log($"Session ended: Id={sessionProperties.Id}"); } }
public void GetsSlots() { // Setup string slot = "staging"; var clientMock = new Mock <IWebsitesClient>(); clientMock.Setup(c => c.ListWebsites(slot)) .Returns(new List <Site> { new Site { Name = "website1(stage)", WebSpace = "webspace1" }, new Site { Name = "website2(stage)", WebSpace = "webspace1" } }); clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>(), slot)) .Returns(new SiteConfig { PublishingUsername = "******" }); // Test var getAzureWebsiteCommand = new GetAzureWebsiteCommand { CommandRuntime = new MockCommandRuntime(), WebsitesClient = clientMock.Object, Slot = slot }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(subscriptionId) }, null, null); getAzureWebsiteCommand.ExecuteCmdlet(); IEnumerable <Site> sites = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as IEnumerable <Site>; var website1 = sites.ElementAt(0); var website2 = sites.ElementAt(1); Assert.NotNull(website1); Assert.NotNull(website2); Assert.Equal("website1(stage)", website1.Name); Assert.Equal("website2(stage)", website2.Name); }
public void GetsWebsiteSlot() { // Setup string slot = "staging"; var clientMock = new Mock <IWebsitesClient>(); clientMock.Setup(c => c.GetWebsite(It.IsAny <string>(), slot)) .Returns(new Site { Name = "website1(stage)", WebSpace = "webspace1" }); clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>())) .Returns(new SiteConfig { PublishingUsername = "******" }); clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>(), slot)) .Returns(new SiteConfig { PublishingUsername = "******" }); // Test var getAzureWebsiteCommand = new GetAzureWebsiteCommand { CommandRuntime = new MockCommandRuntime(), Name = "website1", WebsitesClient = clientMock.Object, Slot = slot }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(subscriptionId) }, null, null); getAzureWebsiteCommand.ExecuteCmdlet(); Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count); var website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig; Assert.NotNull(website); Assert.Equal("website1(stage)", website.Name); Assert.Equal("webspace1", website.WebSpace); Assert.Equal("user1", website.PublishingUsername); }
public void ProcessGetMediaServicesTest() { // Setup Mock <IMediaServicesClient> clientMock = new Mock <IMediaServicesClient>(); Guid id1 = Guid.NewGuid(); Guid id2 = Guid.NewGuid(); MediaServicesAccountListResponse response = new MediaServicesAccountListResponse(); response.Accounts.Add(new MediaServicesAccountListResponse.MediaServiceAccount { AccountId = id1.ToString(), Name = "WAMS Account 1" }); response.Accounts.Add(new MediaServicesAccountListResponse.MediaServiceAccount { AccountId = id2.ToString(), Name = "WAMS Account 2" }); clientMock.Setup(f => f.GetMediaServiceAccountsAsync()).Returns(Task.Factory.StartNew(() => response)); // Test GetAzureMediaServiceCommand getAzureMediaServiceCommand = new GetAzureMediaServiceCommand { CommandRuntime = new MockCommandRuntime(), MediaServicesClient = clientMock.Object, }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(SubscriptionId) }, null, null); getAzureMediaServiceCommand.ExecuteCmdlet(); Assert.Equal(1, ((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.Count); IEnumerable <MediaServiceAccount> accounts = (IEnumerable <MediaServiceAccount>)((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.NotNull(accounts); Assert.True(accounts.Any(mediaservice => (mediaservice).AccountId == id1)); Assert.True(accounts.Any(mediaservice => (mediaservice).AccountId == id2)); Assert.True(accounts.Any(mediaservice => (mediaservice).Name.Equals("WAMS Account 1"))); Assert.True(accounts.Any(mediaservice => (mediaservice).Name.Equals("WAMS Account 2"))); }
public void ListWebHostingPlansTest() { // Setup var clientMock = new Mock <IWebsitesClient>(); clientMock.Setup(c => c.ListWebSpaces()) .Returns(new[] { new WebSpace { Name = "webspace1" }, new WebSpace { Name = "webspace2" } }); clientMock.Setup(c => c.ListWebHostingPlans()) .Returns(new List <WebHostingPlan> { new WebHostingPlan { Name = "Plan1", WebSpace = "webspace1" }, new WebHostingPlan { Name = "Plan2", WebSpace = "webspace2" } }); // Test var command = new GetAzureWebHostingPlanCommand { CommandRuntime = new MockCommandRuntime(), WebsitesClient = clientMock.Object }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(subscriptionId) }, null, null); command.ExecuteCmdlet(); Assert.Equal(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count); var plans = (IEnumerable <WebHostingPlan>)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.NotNull(plans); Assert.True(plans.Any(p => (p).Name.Equals("Plan1") && (p).WebSpace.Equals("webspace1"))); Assert.True(plans.Any(p => (p).Name.Equals("Plan2") && (p).WebSpace.Equals("webspace2"))); }
public LoginTests() { AzureSessionInitializer.InitializeAzureSession(); ProtectedProfileProvider.InitializeResourceManagerProfile(); ContextAutosaveSettings settings = null; AzureSession.Modify((session) => EnableAutosave(session, true, out settings)); ProtectedProfileProvider.InitializeResourceManagerProfile(true); _cmdlet = new ConnectAccount(); _cmdlet.TenantId = _tenantId; _cmdlet.SubscriptionId = _subscriptionId; _cmdlet.SubscriptionName = _subscriptionName; _cmdlet.UserName = _userName; _cmdlet.Password = _password; _cmdlet.ApplicationId = _applicationId; _cmdlet.CertificateThumbprint = _certificateThumbprint; _cmdlet.CommandRuntime = new MockCommandRuntime(); }
public void TestGetAzureWebsiteWithDiagnosticsSettings() { // Setup string slot = "production"; var websitesClientMock = new Mock <IWebsitesClient>(); websitesClientMock.Setup(c => c.GetWebsite(It.IsAny <string>(), slot)) .Returns(new Site { Name = "website1", WebSpace = "webspace1", State = "Running" }); websitesClientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>())) .Returns(new SiteConfig { PublishingUsername = "******" }); websitesClientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>(), slot)) .Returns(new SiteConfig { PublishingUsername = "******" }); var getAzureWebsiteCommand = new GetAzureWebsiteCommand { CommandRuntime = new MockCommandRuntime(), Name = "website1", WebsitesClient = websitesClientMock.Object, Slot = slot }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(subscriptionId) }, null, null); // Test getAzureWebsiteCommand.ExecuteCmdlet(); // Assert Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count); websitesClientMock.Verify(f => f.GetApplicationDiagnosticsSettings("website1"), Times.Once()); }
public override void ExecuteCmdlet() { if (IsDirectory()) { ImportDirectory(); } else { ImportFile(); } AzureSubscription defaultSubscription = ProfileClient.Profile.DefaultSubscription; Debug.Assert(AzureSession.CurrentContext != null); if (defaultSubscription != null && AzureSession.CurrentContext.Subscription == null) { AzureSession.SetCurrentContext( defaultSubscription, ProfileClient.Profile.Environments[defaultSubscription.Environment], ProfileClient.Profile.Accounts[defaultSubscription.Account]); } }
public void EnableAzureWebsiteApplicationDiagnosticApplicationTableLog() { // Setup string storageName = "MyStorage"; string tableName = "MyTable"; properties[DiagnosticProperties.StorageAccountName] = storageName; properties[DiagnosticProperties.StorageTableName] = tableName.ToLowerInvariant(); websitesClientMock.Setup(f => f.EnableApplicationDiagnostic( websiteName, WebsiteDiagnosticOutput.StorageTable, properties, null)); enableAzureWebsiteApplicationDiagnosticCommand = new EnableAzureWebsiteApplicationDiagnosticCommand() { CommandRuntime = commandRuntimeMock.Object, Name = websiteName, WebsitesClient = websitesClientMock.Object, TableStorage = true, LogLevel = LogEntryType.Information, StorageAccountName = storageName, StorageTableName = tableName }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new System.Guid(base.subscriptionId) }, null, null); // Test enableAzureWebsiteApplicationDiagnosticCommand.ExecuteCmdlet(); // Assert websitesClientMock.Verify(f => f.EnableApplicationDiagnostic( websiteName, WebsiteDiagnosticOutput.StorageTable, properties, null), Times.Once()); commandRuntimeMock.Verify(f => f.WriteObject(true), Times.Never()); }
public void SwitchesSlots() { // Setup var mockClient = new Mock <IWebsitesClient>(); string slot1 = WebsiteSlotName.Production.ToString(); string slot2 = "staging"; mockClient.Setup(c => c.GetWebsiteSlots("website1")) .Returns(new List <Site> { new Site { Name = "website1", WebSpace = "webspace1" }, new Site { Name = "website1(staging)", WebSpace = "webspace1" } }); mockClient.Setup(f => f.GetSlotName("website1")).Returns(slot1); mockClient.Setup(f => f.GetSlotName("website1(staging)")).Returns(slot2); mockClient.Setup(f => f.SwitchSlots("webspace1", "website1(staging)", slot1, slot2)).Verifiable(); mockClient.Setup(f => f.GetWebsiteNameFromFullName("website1")).Returns("website1"); // Test SwitchAzureWebsiteSlotCommand switchAzureWebsiteCommand = new SwitchAzureWebsiteSlotCommand { CommandRuntime = new MockCommandRuntime(), WebsitesClient = mockClient.Object, Name = "website1", Force = true }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(base.subscriptionId) }, null, null); // Switch existing website switchAzureWebsiteCommand.ExecuteCmdlet(); mockClient.Verify(c => c.SwitchSlots("webspace1", "website1", slot1, slot2), Times.Once()); }
public void InitializerCreatesTokenCacheFile() { AzureSessionInitializer.InitializeAzureSession(); IAzureSession oldSession = null; try { oldSession = AzureSession.Instance; } catch { } try { var store = new MemoryDataStore(); AzureSessionInitializer.CreateOrReplaceSession(store); var session = AzureSession.Instance; var tokenCacheFile = Path.Combine(session.ProfileDirectory, session.TokenCacheFile); Assert.True(store.FileExists(tokenCacheFile)); } finally { AzureSession.Initialize(() => oldSession, true); } }
public LoginTests() { AzureSessionInitializer.InitializeAzureSession(); ProtectedProfileProvider.InitializeResourceManagerProfile(); IServicePrincipalKeyStore keyStore = new AzureRmServicePrincipalKeyStore(AzureRmProfileProvider.Instance.Profile); AzureSession.Instance.RegisterComponent(ServicePrincipalKeyStore.Name, () => keyStore); ContextAutosaveSettings settings = null; AzureSession.Modify((session) => EnableAutosave(session, true, out settings)); ProtectedProfileProvider.InitializeResourceManagerProfile(true); _cmdlet = new ConnectAccount(); _cmdlet.TenantId = _tenantId; _cmdlet.SubscriptionId = _subscriptionId; _cmdlet.SubscriptionName = _subscriptionName; _cmdlet.UserName = _userName; _cmdlet.Password = _password; _cmdlet.ApplicationId = _applicationId; _cmdlet.CertificateThumbprint = _certificateThumbprint; _cmdlet.CommandRuntime = new MockCommandRuntime(); }
public void EnableApplicationDiagnosticOnSlot() { string slot = "staging"; // Setup websitesClientMock.Setup(f => f.EnableApplicationDiagnostic( websiteName, WebsiteDiagnosticOutput.FileSystem, properties, slot)); enableAzureWebsiteApplicationDiagnosticCommand = new EnableAzureWebsiteApplicationDiagnosticCommand() { CommandRuntime = commandRuntimeMock.Object, Name = websiteName, WebsitesClient = websitesClientMock.Object, File = true, LogLevel = LogEntryType.Information, Slot = slot }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new System.Guid(base.subscriptionId) }, null, null); // Test enableAzureWebsiteApplicationDiagnosticCommand.ExecuteCmdlet(); // Assert websitesClientMock.Verify(f => f.EnableApplicationDiagnostic( websiteName, WebsiteDiagnosticOutput.FileSystem, properties, slot), Times.Once()); commandRuntimeMock.Verify(f => f.WriteObject(true), Times.Never()); }
public override void ExecuteCmdlet() { AzureSubscription azureSubscription = null; switch (ParameterSetName) { case SelectSubscriptionByNameParameterSet: azureSubscription = ProfileClient.SetSubscriptionAsCurrent(SubscriptionName, Account); break; case SelectSubscriptionByIdParameterSet: azureSubscription = ProfileClient.SetSubscriptionAsCurrent(SubscriptionIdAsGuid(), Account); break; case SelectDefaultSubscriptionByNameParameterSet: azureSubscription = ProfileClient.SetSubscriptionAsDefault(SubscriptionName, Account); break; case SelectDefaultSubscriptionByIdParameterSet: azureSubscription = ProfileClient.SetSubscriptionAsDefault(SubscriptionIdAsGuid(), Account); break; case NoCurrentSubscriptionParameterSet: AzureSession.SetCurrentContext(null, null, null); break; case NoDefaultSubscriptionParameterSet: ProfileClient.ClearDefaultSubscription(); break; } if (PassThru.IsPresent && azureSubscription != null) { WriteObject(azureSubscription); } }
public override void ExecuteCmdlet() { if (MyInvocation.BoundParameters.ContainsKey(nameof(Scope)) && Scope == ContextModificationScope.Process) { ConfirmAction("Autosave the context in the current session", "Current session", () => { ContextAutosaveSettings settings = null; AzureSession.Modify((session) => EnableAutosave(session, false, out settings)); ProtectedProfileProvider.InitializeResourceManagerProfile(true); WriteObject(settings); }); } else { ConfirmAction("Always autosave the context for the current user", "Current user", () => { ContextAutosaveSettings settings = null; AzureSession.Modify((session) => EnableAutosave(session, true, out settings)); ProtectedProfileProvider.InitializeResourceManagerProfile(true); WriteObject(settings); }); } }
private void ARRService_OnSessionStatusChanged(ARRServiceUnity caller, AzureSession session) { LogSessionStatus(session); var status = caller.LastProperties.Status; // Capture the session id for the starting/ready session so it can be reused if (status == RenderingSessionStatus.Ready || status == RenderingSessionStatus.Starting) { SessionId = session.SessionUUID; // If our session properties are 'Ready' we are ready to start connecting to the runtime of the service. if (status == RenderingSessionStatus.Ready) { session.ConnectionStatusChanged += AzureSession_OnConnectionStatusChanged; } } // Our session is stopped, expired, or in an error state. else { SessionId = null; session.ConnectionStatusChanged -= AzureSession_OnConnectionStatusChanged; } }
public void ProcessRestartWebsiteTest() { // Setup const string websiteName = "website1"; Mock <IWebsitesClient> websitesClientMock = new Mock <IWebsitesClient>(); websitesClientMock.Setup(f => f.RestartWebsite(websiteName, null)); // Test RestartAzureWebsiteCommand restartAzureWebsiteCommand = new RestartAzureWebsiteCommand() { CommandRuntime = new MockCommandRuntime(), Name = websiteName, WebsitesClient = websitesClientMock.Object }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(base.subscriptionId) }, null, null); restartAzureWebsiteCommand.ExecuteCmdlet(); websitesClientMock.Verify(f => f.RestartWebsite(websiteName, null), Times.Once()); }
public void GetWebsiteProcessShowTest() { // Setup var clientMock = new Mock <IWebsitesClient>(); clientMock.Setup(c => c.GetWebsiteSlots(It.IsAny <string>())) .Returns(new Sites() { new Site { Name = "website1", WebSpace = "webspace1" } }); clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>())) .Returns(new SiteConfig { PublishingUsername = "******" } ); clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>(), null)) .Returns(new SiteConfig { PublishingUsername = "******" } ); // Test var getAzureWebsiteCommand = new GetAzureWebsiteCommand { CommandRuntime = new MockCommandRuntime(), Name = "website1", WebsitesClient = clientMock.Object }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(subscriptionId) }, null, null); getAzureWebsiteCommand.ExecuteCmdlet(); Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count); SiteWithConfig website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig; Assert.NotNull(website); Assert.NotNull(website); Assert.Equal("website1", website.Name); Assert.Equal("webspace1", website.WebSpace); // Run with mixed casing getAzureWebsiteCommand = new GetAzureWebsiteCommand { CommandRuntime = new MockCommandRuntime(), Name = "WEBSiTe1", WebsitesClient = clientMock.Object }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(subscriptionId) }, null, null); getAzureWebsiteCommand.ExecuteCmdlet(); Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count); website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig; Assert.NotNull(website); Assert.NotNull(website); Assert.Equal("website1", website.Name); Assert.Equal("webspace1", website.WebSpace); }
public void Cleanup() { AzureSession.SetCurrentContext(null, null, null); }
public void RestoreAzureWebsiteDeploymentTest() { // Setup var site1 = new Site { Name = "website1", WebSpace = "webspace1", SiteProperties = new SiteProperties { Properties = new List <NameValuePair> { new NameValuePair { Name = "repositoryuri", Value = "http" }, new NameValuePair { Name = "PublishingUsername", Value = "user1" }, new NameValuePair { Name = "PublishingPassword", Value = "password1" } } } }; var clientMock = new Mock <IWebsitesClient>(); clientMock.Setup(c => c.ListWebSpaces()) .Returns(new[] { new WebSpace { Name = "webspace1" }, new WebSpace { Name = "webspace2" } }); clientMock.Setup(c => c.GetWebsite("website1", null)) .Returns(site1); SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement(); var deployments = new List <DeployResult> { new DeployResult { Id = "id1", Current = false }, new DeployResult { Id = "id2", Current = true } }; deploymentChannel.GetDeploymentsThunk = ar => deployments; deploymentChannel.DeployThunk = ar => { // Keep track of currently deployed id DeployResult newDeployment = deployments.FirstOrDefault(d => d.Id.Equals(ar.Values["commitId"])); if (newDeployment != null) { // Make all inactive deployments.ForEach(d => d.Complete = false); // Set new to active newDeployment.Complete = true; } }; // Test RestoreAzureWebsiteDeploymentCommand restoreAzureWebsiteDeploymentCommand = new RestoreAzureWebsiteDeploymentCommand(deploymentChannel) { Name = "website1", CommitId = "id2", ShareChannel = true, WebsitesClient = clientMock.Object, CommandRuntime = new MockCommandRuntime(), }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(base.subscriptionId) }, null, null); restoreAzureWebsiteDeploymentCommand.ExecuteCmdlet(); Assert.Equal(1, ((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count); var responseDeployments = (IEnumerable <DeployResult>)((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.NotNull(responseDeployments); Assert.Equal(2, responseDeployments.Count()); Assert.True(responseDeployments.Any(d => d.Id.Equals("id2") && d.Complete)); Assert.True(responseDeployments.Any(d => d.Id.Equals("id1") && !d.Complete)); // Change active deployment to id1 restoreAzureWebsiteDeploymentCommand = new RestoreAzureWebsiteDeploymentCommand(deploymentChannel) { Name = "website1", CommitId = "id1", ShareChannel = true, WebsitesClient = clientMock.Object, CommandRuntime = new MockCommandRuntime(), }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(base.subscriptionId) }, null, null); restoreAzureWebsiteDeploymentCommand.ExecuteCmdlet(); Assert.Equal(1, ((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count); responseDeployments = (IEnumerable <DeployResult>)((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.NotNull(responseDeployments); Assert.Equal(2, responseDeployments.Count()); Assert.True(responseDeployments.Any(d => d.Id.Equals("id1") && d.Complete)); Assert.True(responseDeployments.Any(d => d.Id.Equals("id2") && !d.Complete)); }
/// <summary> /// Setup certificates required for the unit tests /// </summary> public static void SetupCertificates() { TestingTracingInterceptor.AddToContext(); ProfileClient.DataStore = new MockDataStore(); AzureSession.AuthenticationFactory = new MockAuthenticationFactory(); var newGuid = Guid.NewGuid(); ProfileClient client = new ProfileClient(); client.Profile.Subscriptions[newGuid] = new AzureSubscription { Id = newGuid, Name = "test", Environment = EnvironmentName.AzureCloud, Account = "test" }; client.Profile.Accounts["test"] = new AzureAccount { Id = "test", Type = AzureAccount.AccountType.User, Properties = new Dictionary <AzureAccount.Property, string> { { AzureAccount.Property.Subscriptions, newGuid.ToString() } } }; client.Profile.Accounts[UnitTestHelper.GetUnitTestClientCertificate().Thumbprint] = new AzureAccount { Id = UnitTestHelper.GetUnitTestClientCertificate().Thumbprint, Type = AzureAccount.AccountType.Certificate, Properties = new Dictionary <AzureAccount.Property, string> { { AzureAccount.Property.Subscriptions, newGuid.ToString() } } }; client.Profile.Accounts[UnitTestHelper.GetUnitTestSSLCertificate().Thumbprint] = new AzureAccount { Id = UnitTestHelper.GetUnitTestSSLCertificate().Thumbprint, Type = AzureAccount.AccountType.Certificate, Properties = new Dictionary <AzureAccount.Property, string> { { AzureAccount.Property.Subscriptions, newGuid.ToString() } } }; AzureSession.SetCurrentContext(client.Profile.Subscriptions[newGuid], null, client.Profile.Accounts["test"]); client.Profile.Save(); // Check if the cert has been installed Process proc = ExecuteProcess( "netsh", string.Format( CultureInfo.InvariantCulture, "http show sslcert ipport=0.0.0.0:{0}", DefaultHttpsServerPrefixUri.Port)); if (proc.ExitCode != 0) { // Install the SSL and client certificates to the LocalMachine store X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadWrite); store.Add(UnitTestHelper.GetUnitTestSSLCertificate()); store.Add(UnitTestHelper.GetUnitTestClientCertificate()); store.Close(); store = new X509Store(StoreName.Root, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadWrite); store.Add(UnitTestHelper.GetUnitTestSSLCertificate()); store.Add(UnitTestHelper.GetUnitTestClientCertificate()); store.Close(); // Remove any existing certs on the default port proc = ExecuteProcess( "netsh", string.Format( CultureInfo.InvariantCulture, "http delete sslcert ipport=0.0.0.0:{0}", DefaultHttpsServerPrefixUri.Port)); // Install the ssl cert on the default port proc = ExecuteProcess( "netsh", string.Format( CultureInfo.InvariantCulture, "http add sslcert ipport=0.0.0.0:{0} certhash={1} appid={2:B}", DefaultHttpsServerPrefixUri.Port, UnitTestHelper.GetUnitTestSSLCertificate().Thumbprint, MockHttpServer.HttpsAppId)); if (proc.ExitCode != 0) { throw new InvalidOperationException(string.Format( CultureInfo.InvariantCulture, "Unable to add ssl certificate: {0}", proc.StandardOutput.ReadToEnd())); } } }
public void SetAzureWebsiteProcess() { const string websiteName = "website1"; const string webspaceName = "webspace"; const string suffix = "azurewebsites.com"; // Setup Mock <IWebsitesClient> clientMock = new Mock <IWebsitesClient>(); clientMock.Setup(f => f.GetWebsiteDnsSuffix()).Returns(suffix); bool updatedSite = false; bool updatedSiteConfig = false; clientMock.Setup(c => c.GetWebsite(websiteName, null)) .Returns(new Site { Name = websiteName, WebSpace = webspaceName }); clientMock.Setup(c => c.GetWebsiteConfiguration(websiteName, null)) .Returns(new SiteConfig { NumberOfWorkers = 1 }); clientMock.Setup(c => c.UpdateWebsiteConfiguration(websiteName, It.IsAny <SiteConfig>(), null)) .Callback((string name, SiteConfig config, string slot) => { Assert.NotNull(config); Assert.Equal(config.NumberOfWorkers, 3); updatedSiteConfig = true; }).Verifiable(); clientMock.Setup(c => c.UpdateWebsiteHostNames(It.IsAny <Site>(), It.IsAny <IEnumerable <string> >(), null)) .Callback((Site site, IEnumerable <string> names, string slot) => { Assert.Equal(websiteName, site.Name); Assert.True(names.Any(hostname => hostname.Equals(string.Format("{0}.{1}", websiteName, suffix)))); Assert.True(names.Any(hostname => hostname.Equals("stuff.com"))); updatedSite = true; }); clientMock.Setup(f => f.GetHostName(websiteName, null)).Returns(string.Format("{0}.{1}", websiteName, suffix)); // Test SetAzureWebsiteCommand setAzureWebsiteCommand = new SetAzureWebsiteCommand { CommandRuntime = new MockCommandRuntime(), Name = websiteName, NumberOfWorkers = 3, WebsitesClient = clientMock.Object }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(base.subscriptionId) }, null, null); setAzureWebsiteCommand.ExecuteCmdlet(); Assert.True(updatedSiteConfig); Assert.False(updatedSite); // Test updating site only and not configurations updatedSite = false; updatedSiteConfig = false; setAzureWebsiteCommand = new SetAzureWebsiteCommand { CommandRuntime = new MockCommandRuntime(), Name = websiteName, HostNames = new [] { "stuff.com" }, WebsitesClient = clientMock.Object }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(base.subscriptionId) }, null, null); setAzureWebsiteCommand.ExecuteCmdlet(); Assert.False(updatedSiteConfig); Assert.True(updatedSite); }
// [Test] public void Azure() { UInt64 id = 42949738497; AllSupported allSuported, allSupported2; string connectionString = null; using (StreamReader sr = new StreamReader("c:/AzureConnectionString.txt")) { connectionString = sr.ReadToEnd(); } // A better way of using Azure files is to mount cloud directory as a local drive. // Such as: net use f: \\veleocitydb.file.core.windows.net\azure /u:veleocitydb [access key] // Add access key and update for your case. // Then you can use the mounted Azure directory just like you use any local drive! /*using (SessionBase session = new SessionNoServer("v:/azure", 99999, false)) * { * session.BeginUpdate(); * allSuported = new AllSupported(3); * allSuported.Persist(session, allSuported); * id = allSuported.Id; * session.Commit(); * } * * using (SessionNoServer session = new SessionNoServer("v:/azure", 99999, false)) * { * session.BeginRead(); * allSupported2 = (AllSupported)session.Open(id); * session.Commit(); * }*/ using (SessionBase session = new AzureSession(connectionString, "azure", "azure", 99999, false)) { session.BeginUpdate(); allSuported = new AllSupported(3, session); session.Persist(allSuported); id = allSuported.Id; session.Commit(); } using (SessionNoServer session = new AzureSession(connectionString, "azure", "azure", 99999, false)) { session.BeginRead(); allSupported2 = (AllSupported)session.Open(id); Assert.NotNull(allSupported2); session.Commit(); } /* Not yet working. Challenge is that an Azure Stream can only be Read only or Update only - not both. Another challenge is required calls to Flush() and resizing of files have to be explicit. * * using (SessionBase session = new AzureSession(connectionString, "azure", "azure", 99999, true)) * { * session.BeginUpdate(); * foreach (Database db in session.OpenAllDatabases(true)) * if (db.DatabaseNumber >= 10 || db.DatabaseNumber == SessionBase.IndexDescriptorDatabaseNumber) * session.DeleteDatabase(db); * session.Commit(); * session.BeginUpdate(); * DatabaseLocation defaultLocation = session.DatabaseLocations.Default(); * List<Database> dbList = session.OpenLocationDatabases(defaultLocation, true); * foreach (Database db in dbList) * if (db.DatabaseNumber > Database.InitialReservedDatabaseNumbers) * session.DeleteDatabase(db); * session.DeleteLocation(defaultLocation); * session.Commit(); * }*/ }
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); }
private void ARRService_OnSessionStatusChanged(ARRServiceUnity service, AzureSession session) { LogSessionStatus(session); }