/// <summary>
        /// Starts PE Test failover.
        /// </summary>
        private void StartPETestFailover()
        {
            var request = new TestFailoverRequest();

            if (this.ProtectionEntity == null)
            {
                var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
                    this.ProtectionEntity.ProtectionContainerId,
                    this.ProtectionEntity.Name);
                this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);

                /* this.ValidateUsageById(
                    this.ProtectionEntity.ReplicationProvider,
                    Constants.ProtectionEntityId); */
            }

            request.ReplicationProviderSettings = string.Empty;

            request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
            request.FailoverDirection = this.Direction;

            request.NetworkID = this.networkId;
            request.NetworkType = this.networkType;

            LongRunningOperationResponse response =
                RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
                this.ProtectionEntity.ProtectionContainerId,
                this.ProtectionEntity.Name,
                request);

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }
 /// <summary>
 /// Starts Azure Site Recovery Unplanned failover.
 /// </summary>
 /// <param name="protectionContainerId">Protection Container ID</param>
 /// <param name="protectionEntityId">Protection entity ID</param>
 /// <param name="testFailoverRequest">Test failover request</param>
 /// <returns>Job response</returns>
 public LongRunningOperationResponse StartAzureSiteRecoveryTestFailover(
     string protectionContainerId,
     string protectionEntityId,
     TestFailoverRequest testFailoverRequest)
 {
     return this.GetSiteRecoveryClient().ProtectionEntity.BeginTestFailover(
         protectionContainerId,
         protectionEntityId,
         testFailoverRequest,
         this.GetRequestHeaders());
 }
        /// <summary>
        /// Starts PE Test failover.
        /// </summary>
        private void StartPETestFailover()
        {
            var request = new TestFailoverRequest();

            if (this.ProtectionEntity == null)
            {
                var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
                    this.ProtectionEntity.ProtectionContainerId,
                    this.ProtectionEntity.Name);
                this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
            }

            request.FailoverDirection = this.Direction;
            request.NetworkID = this.networkId;
            request.NetworkType = this.networkType;

            if (string.IsNullOrEmpty(this.ProtectionEntity.ReplicationProvider))
            {
                // fetch the latest PE object
                // As get PE by name is failing before protection, get all & filter.
                // Once after we fix get pe by name, change the logic to use the same.
                ProtectionEntityListResponse protectionEntityListResponse =
                    RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
                    this.ProtectionEntity.ProtectionContainerId);

                foreach (ProtectionEntity pe in protectionEntityListResponse.ProtectionEntities)
                {
                    if (0 == string.Compare(this.ProtectionEntity.FriendlyName, pe.Properties.FriendlyName, true))
                    {
                        this.ProtectionEntity = new ASRProtectionEntity(pe);
                        break;
                    }
                }
            }

            request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
            request.ReplicationProviderSettings = new FailoverReplicationProviderSpecificInput();

            if (0 == string.Compare(
                this.ProtectionEntity.ReplicationProvider,
                Constants.HyperVReplicaAzure,
                StringComparison.OrdinalIgnoreCase))
            {
                AzureFailoverInput failoverInput = new AzureFailoverInput()
                {
                    PrimaryKekCertificatePfx = string.Empty,
                    SecondaryKekCertificatePfx = string.Empty,
                    VaultLocation = this.GetCurrentValutLocation()
                };
                request.ReplicationProviderSettings = failoverInput;
            }

            LongRunningOperationResponse response =
                RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
                this.ProtectionEntity.ProtectionContainerId,
                this.ProtectionEntity.Name,
                request);

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }
 /// <summary>
 /// Creates a profile
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.SiteRecovery.IProtectionEntityOperations.
 /// </param>
 /// <param name='pcName'>
 /// Required. Parent Protection Container name.
 /// </param>
 /// <param name='name'>
 /// Required. Protection entity name.
 /// </param>
 /// <param name='parameters'>
 /// Required. Test failover request.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// A standard service response for long running operations.
 /// </returns>
 public static Task<LongRunningOperationResponse> TestFailoverAsync(this IProtectionEntityOperations operations, string pcName, string name, TestFailoverRequest parameters, CustomRequestHeaders customRequestHeaders)
 {
     return operations.TestFailoverAsync(pcName, name, parameters, customRequestHeaders, CancellationToken.None);
 }
 /// <summary>
 /// Creates a profile
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.SiteRecovery.IProtectionEntityOperations.
 /// </param>
 /// <param name='pcName'>
 /// Required. Parent Protection Container name.
 /// </param>
 /// <param name='name'>
 /// Required. Protection entity name.
 /// </param>
 /// <param name='parameters'>
 /// Required. Test failover request.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// A standard service response for long running operations.
 /// </returns>
 public static LongRunningOperationResponse TestFailover(this IProtectionEntityOperations operations, string pcName, string name, TestFailoverRequest parameters, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IProtectionEntityOperations)s).TestFailoverAsync(pcName, name, parameters, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }