// Test cmdlet.ExecuteCmdlet(); // Assert mockStoreClient.Verify(f => f.UpdateAddOn(name, plan, null), Times.Once()); mockConfirmation.Verify(f => f.ShouldProcess(Resources.SetAddOnConformation, message), Times.Once()); mockCommandRuntime.Verify(f => f.WriteObject(expected), Times.Never()); } [TestMethod] public void SetAzureStoreAddOnWithPassThru() { // Setup bool expected = true; string name = "TestAddOn"; string addonId = "Search"; string plan = "free"; string message = "Expected message for set"; cmdlet.Name = name; cmdlet.Plan = plan; cmdlet.PassThru = true; WindowsAzureAddOn addon = new WindowsAzureAddOn(new Resource() { Type = addonId }, "West US", null); mockConfirmation.Setup(f => f.ShouldProcess(Resources.SetAddOnConformation, message)).Returns(true); mockStoreClient.Setup(f => f.TryGetAddOn(name, out addon)).Returns(true);
/// <summary> /// Removes given Add-On /// </summary> /// <param name="name">The add-on name</param> public virtual void RemoveAddOn(string name) { List <WindowsAzureAddOn> addOns = GetAddOn(new AddOnSearchOptions(name, null, null)); if (addOns.Count != 1) { throw new Exception(string.Format(Resources.AddOnNotFound, name)); } WindowsAzureAddOn addon = addOns[0]; string type; string cloudService; string addonId; addonId = GetResourceInformation(addon.AddOn, addon.Location, out type, out cloudService); storeChannel.DeleteResource( subscriptionId, cloudService, type, addonId, name ); WaitForOperation(headersInspector.ResponseHeaders[ServiceManagementConstants.OperationTrackingIdHeader]); }
/// <summary> /// Tries to get an add-on using it's name. /// </summary> /// <param name="name">The add-on name</param> /// <param name="addon">The add-on instance. Will be null if not found</param> /// <returns>Boolean if the add-on is found, false otherwise</returns> public virtual bool TryGetAddOn(string name, out WindowsAzureAddOn addon) { List <WindowsAzureAddOn> addons = GetAddOn(new AddOnSearchOptions(name, null, null)); if (addons.Count == 1) { addon = addons[0]; return(true); } addon = null; return(false); }
/// <summary> /// Updates an add-on plan. /// </summary> /// <param name="name">The add-on name</param> /// <param name="plan">The add-on new plan id</param> /// <param name="promotionCode">The plan promotion code</param> public virtual void UpdateAddOn(string name, string plan, string promotionCode) { List <WindowsAzureAddOn> addons = GetAddOn(new AddOnSearchOptions(name)); if (addons.Count != 1) { throw new Exception(string.Format(Resources.AddOnNotFound, name)); } WindowsAzureAddOn addon = addons[0]; if (!string.IsNullOrEmpty(promotionCode) && addon.Plan.Equals(plan, StringComparison.OrdinalIgnoreCase)) { throw new Exception(Resources.PromotionCodeWithCurrentPlanMessage); } headersInspector.RequestHeaders.Add(IfMatchHeader, addon.ETag); NewAddOn(name, addon.AddOn, plan, addon.Location, promotionCode); }
public void RemoveAzureStoreAddOnWithNo() { // Setup bool expected = true; string name = "TestAddOn"; string addonId = "Search"; string message = "Expected message for remove"; cmdlet.Name = name; WindowsAzureAddOn addon = new WindowsAzureAddOn(new Resource() { Type = addonId }, "West US", null); mockConfirmation.Setup(f => f.ShouldProcess(Resources.RemoveAddOnConformation, message)).Returns(false); mockStoreClient.Setup(f => f.TryGetAddOn(name, out addon)).Returns(true); mockStoreClient.Setup(f => f.RemoveAddOn(name)); mockStoreClient.Setup(f => f.GetConfirmationMessage(OperationType.Remove, null, null)).Returns(message); // Test cmdlet.ExecuteCmdlet(); // Assert mockStoreClient.Verify(f => f.RemoveAddOn(name), Times.Never()); mockConfirmation.Verify(f => f.ShouldProcess(Resources.RemoveAddOnConformation, message), Times.Once()); mockCommandRuntime.Verify(f => f.WriteObject(expected), Times.Never()); }
/// <summary> /// Tries to get an add-on using it's name. /// </summary> /// <param name="name">The add-on name</param> /// <param name="addon">The add-on instance. Will be null if not found</param> /// <returns>Boolean if the add-on is found, false otherwise</returns> public virtual bool TryGetAddOn(string name, out WindowsAzureAddOn addon) { List<WindowsAzureAddOn> addons = GetAddOn(new AddOnSearchOptions(name, null, null)); if (addons.Count == 1) { addon = addons[0]; return true; } addon = null; return false; }