Microsoft.Azure.Commands.DataFactories.NewAzureDataFactoryEncryptValueCommand.ExecuteCmdlet C# (CSharp) Method

ExecuteCmdlet() private method

private ExecuteCmdlet ( ) : void
return void
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ByFactoryObject)
            {
                if (DataFactory == null)
                {
                    throw new PSArgumentNullException(string.Format(CultureInfo.InvariantCulture,
                        Resources.DataFactoryArgumentInvalid));
                }

                DataFactoryName = DataFactory.DataFactoryName;
                ResourceGroupName = DataFactory.ResourceGroupName;
            }

            string encryptedValue = String.Empty;

            if (String.IsNullOrWhiteSpace(GatewayName))
            {
                // Cloud encryption without Gateway
                WriteWarning("Cloud encryption has already been deprecated. Please run get-help new-azuredatafactoryencryptvalue to see other option of this command");
            }
            else
            {
                // On-premises encryption with Gateway
                encryptedValue = DataFactoryClient.OnPremisesEncryptString(Value, ResourceGroupName, DataFactoryName,
                    GatewayName, Credential, Type, NonCredentialValue, AuthenticationType, Server, Database);
            }

            WriteObject(encryptedValue);
        }
    }

Usage Example

        public void TestOnPremDatasourceEncryptionSQLAuth()
        {
            SecureString secureString = new SecureString();
            string expectedOutput = "My encrypted string " + Guid.NewGuid();
            string linkedServiceType = "OnPremisesSqlLinkedService";
            string nonCredentialValue = "Driver=mydriver;server=myserver";
            string authenticationType = "Basic";
            string serverName = null;
            string databaseName = null;

            var cmdlet = new NewAzureDataFactoryEncryptValueCommand
            {
                CommandRuntime = this.commandRuntimeMock.Object,
                DataFactoryClient = this.dataFactoriesClientMock.Object,
                Value = secureString,
                ResourceGroupName = ResourceGroupName,
                DataFactoryName = DataFactoryName,
                GatewayName = GatewayName,
                Type = linkedServiceType,
                NonCredentialValue = nonCredentialValue,
                AuthenticationType = authenticationType,
                Server = serverName,
                Database = databaseName
            };

            // Arrange
            this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType, nonCredentialValue, authenticationType, serverName, databaseName)).Returns(expectedOutput);

            // Action
            cmdlet.ExecuteCmdlet();

            // Assert
            this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType, nonCredentialValue, authenticationType, serverName, databaseName), Times.Once());
            this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
        }
All Usage Examples Of Microsoft.Azure.Commands.DataFactories.NewAzureDataFactoryEncryptValueCommand::ExecuteCmdlet
NewAzureDataFactoryEncryptValueCommand