public void CanGetLinkedService()
        {
            // Arrange
            PSLinkedService expected = new PSLinkedService()
            {
                LinkedServiceName = linkedServiceName,
                DataFactoryName = DataFactoryName,
                ResourceGroupName = ResourceGroupName
            };

            dataFactoriesClientMock
                .Setup(
                    c =>
                        c.FilterPSLinkedServices(
                            It.Is<LinkedServiceFilterOptions>(
                                options =>
                                    options.ResourceGroupName == ResourceGroupName &&
                                    options.DataFactoryName == DataFactoryName && 
                                    options.Name == linkedServiceName)))
                .CallBase()
                .Verifiable();

            dataFactoriesClientMock
                .Setup(c => c.GetLinkedService(ResourceGroupName, DataFactoryName, linkedServiceName))
                .Returns(expected)
                .Verifiable();

            // Action
            cmdlet.Name = "  ";
            Exception whiteSpace = Assert.Throws<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet());

            cmdlet.Name = "";
            Exception empty = Assert.Throws<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet());

            cmdlet.Name = linkedServiceName;
            cmdlet.ExecuteCmdlet();

            // Assert
            dataFactoriesClientMock.VerifyAll();
            Assert.Contains("Value cannot be null", whiteSpace.Message);
            Assert.Contains("Value cannot be null", empty.Message);
            commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once());
        }
        public virtual PSLinkedService CreatePSLinkedService(CreatePSLinkedServiceParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            
            PSLinkedService linkedService = null;
            Action createLinkedService = () =>
            {
                linkedService =
                    new PSLinkedService(CreateOrUpdateLinkedService(parameters.ResourceGroupName,
                        parameters.DataFactoryName,
                        parameters.Name,
                        parameters.RawJsonContent))
                    {
                        ResourceGroupName = parameters.ResourceGroupName,
                        DataFactoryName = parameters.DataFactoryName
                    };

                if (!DataFactoryCommonUtilities.IsSucceededProvisioningState(linkedService.ProvisioningState))
                {
                    string errorMessage = linkedService.Properties == null
                        ? string.Empty
                        : linkedService.Properties.ErrorMessage;
                    throw new ProvisioningFailedException(errorMessage);
                }
            };
            
            if (parameters.Force)
            {
                // If user decides to overwrite anyway, then there is no need to check if the linked service exists or not.
                createLinkedService();
            }
            else
            {
                bool linkedServiceExists = CheckLinkedServiceExists(parameters.ResourceGroupName,
                    parameters.DataFactoryName, parameters.Name);

                parameters.ConfirmAction(
                        !linkedServiceExists,  // prompt only if the linked service exists
                        string.Format(
                            CultureInfo.InvariantCulture,
                            Resources.LinkedServiceExists,
                            parameters.Name,
                            parameters.DataFactoryName),
                        string.Format(
                            CultureInfo.InvariantCulture,
                            Resources.LinkedServiceCreating,
                            parameters.Name,
                            parameters.DataFactoryName),
                        parameters.Name,
                        createLinkedService);
            }

            return linkedService;
        }