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());
        }
        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());
        }
Esempio n. 3
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;
        }