public PrepareToSendOnChannelResult DeepCloneWithFailureAction(PrepareToSendOnChannelFailureAction failureAction)
        {
            var result = new PrepareToSendOnChannelResult(
                this.ChannelOperationInstructions?.DeepClone(),
                this.Failures?.DeepClone(),
                failureAction);

            return(result);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PrepareToSendOnChannelResult"/> class.
        /// </summary>
        /// <param name="channelOperationInstructions">Ordered instructions for putting operations into a channel-specific Operation Stream and monitoring them for success/failure.</param>
        /// <param name="failures">The failures that occurred when executing the operation.</param>
        /// <param name="failureAction">The action to take when <paramref name="failures"/> contains one or more elements.</param>
        public PrepareToSendOnChannelResult(
            IReadOnlyList <ChannelOperationInstruction> channelOperationInstructions,
            IReadOnlyCollection <IFailure> failures,
            PrepareToSendOnChannelFailureAction failureAction)
        {
            new { channelOperationInstructions }.AsArg().Must().NotContainAnyNullElementsWhenNotNull();
            var channelOperationTrackingCodeIds = channelOperationInstructions?.Select(_ => _.MonitoringInfo.ChannelOperationTrackingCodeId).ToArray();

            new { channelOperationTrackingCodeIds }.AsArg().Must().ContainOnlyDistinctElementsWhenNotNull();
            var channelOperations = channelOperationInstructions?.Select(_ => _.Operation).ToList();

            new { channelOperations }.AsArg().Must().ContainOnlyDistinctElementsWhenNotNull();
            new { failures }.AsArg().Must().NotContainAnyNullElementsWhenNotNull();
            new { failureAction }.AsArg().Must().NotBeEqualTo(PrepareToSendOnChannelFailureAction.Unknown);

            this.ChannelOperationInstructions = channelOperationInstructions;
            this.Failures      = failures;
            this.FailureAction = failureAction;
        }