Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);

            storeClient.AddOns.Delete(cloudService, type, addonId, name);
        }
        public void RemoveAzureStoreAddOnWithSuccessful()
        {
            // 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(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.Once());
            mockConfirmation.Verify(f => f.ShouldProcess(Resources.RemoveAddOnConformation, message), Times.Once());
            mockCommandRuntime.Verify(f => f.WriteObject(expected), Times.Never());
        }
Example #4
0
        /// <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);
            }

            string type;
            string cloudServiceName;

            addon.AddOn = GetResourceInformation(addon.AddOn, addon.Location, out type, out cloudServiceName);

            AddOnUpdateParameters parameters = new AddOnUpdateParameters()
            {
                Plan          = plan,
                Type          = type,
                PromotionCode = promotionCode
            };

            try
            {
                storeClient.AddOns.Update(cloudServiceName, addon.AddOn, name, parameters);
            }
            catch (Exception ex)
            {
                if (ex.Message.Equals(Resources.FirstPurchaseErrorMessage, StringComparison.OrdinalIgnoreCase))
                {
                    throw new Exception(Resources.FirstPurchaseMessage);
                }
            }
        }
Example #5
0
        /// <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;
        }
        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);
            mockStoreClient.Setup(f => f.UpdateAddOn(name, plan, null));
            mockStoreClient.Setup(f => f.GetConfirmationMessage(OperationType.Set, addonId, plan)).Returns(message);

            // 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.Once());
        }