Пример #1
0
        static AttemptToSendNotificationResultTest()
        {
            ConstructorArgumentValidationTestScenarios
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <AttemptToSendNotificationResult>
            {
                Name             = "constructor should throw ArgumentException when parameter 'channelToOperationsOutcomeInfoMap' contains a value that is empty",
                ConstructionFunc = () =>
                {
                    var channelToOperationsOutcomeInfoMap =
                        new Dictionary <IDeliveryChannel, IReadOnlyCollection <ChannelOperationOutcomeInfo> >
                    {
                        { new SlackDeliveryChannel(), new ChannelOperationOutcomeInfo[0] },
                    };

                    var result = new AttemptToSendNotificationResult(
                        channelToOperationsOutcomeInfoMap);

                    return(result);
                },
                ExpectedExceptionType            = typeof(ArgumentException),
                ExpectedExceptionMessageContains = new[] { "perChannelOperationsOutcomeInfo", "empty enumerable", },
            })
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <AttemptToSendNotificationResult>
            {
                Name             = "constructor should throw ArgumentException when parameter 'channelToOperationsOutcomeInfoMap' contains a value that contains a null value",
                ConstructionFunc = () =>
                {
                    var channelToOperationsOutcomeInfoMap =
                        new Dictionary <IDeliveryChannel, IReadOnlyCollection <ChannelOperationOutcomeInfo> >
                    {
                        { new SlackDeliveryChannel(), new ChannelOperationOutcomeInfo[] { A.Dummy <ChannelOperationOutcomeInfo>(), null } },
                    };

                    var result = new AttemptToSendNotificationResult(
                        channelToOperationsOutcomeInfoMap);

                    return(result);
                },
                ExpectedExceptionType            = typeof(ArgumentException),
                ExpectedExceptionMessageContains = new[] { "perChannelOperationsOutcomeInfo", "null element", },
            })
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <AttemptToSendNotificationResult>
            {
                Name             = "constructor should throw ArgumentException when parameter 'channelToOperationsOutcomeInfoMap' contains a value having duplicate tracking code ids",
                ConstructionFunc = () =>
                {
                    var channelOperationOutcomeInfo = A.Dummy <ChannelOperationOutcomeInfo>();

                    var channelOperationOutcomeInfo2 = A.Dummy <ChannelOperationOutcomeInfo>().DeepCloneWithChannelOperationTrackingCodeId(channelOperationOutcomeInfo.ChannelOperationTrackingCodeId);

                    var channelToOperationsOutcomeInfoMap =
                        new Dictionary <IDeliveryChannel, IReadOnlyCollection <ChannelOperationOutcomeInfo> >
                    {
                        {
                            new SlackDeliveryChannel(),
                            new[]
                            {
                                channelOperationOutcomeInfo,
                                channelOperationOutcomeInfo2,
                            }
                        },
                    };

                    var result = new AttemptToSendNotificationResult(
                        channelToOperationsOutcomeInfoMap);

                    return(result);
                },
                ExpectedExceptionType            = typeof(ArgumentException),
                ExpectedExceptionMessageContains = new[] { "perChannelOperationTrackingCodeIds", "two or more elements that are equal", },
            });
        }
Пример #2
0
        /// <inheritdoc />
        public override async Task ExecuteAsync(
            HandleRecordOp <ExecuteOpRequestedEvent <long, ProcessSendNotificationSagaOp> > operation)
        {
            new { operation }.AsArg().Must().NotBeNull();

            // Pull some info out of the operation.
            var executeOpRequestedEvent = operation.RecordToHandle.Payload;

            var processSendNotificationSagaOp = executeOpRequestedEvent.Operation;

            var inheritableTags = (operation.RecordToHandle.Metadata.Tags?.DeepClone() ?? new List <NamedValue <string> >()).ToList();

            // Poll for failure event
            var channels = processSendNotificationSagaOp.ChannelToOperationsMonitoringInfoMap.Keys;

            var channelToOperationsOutcomeInfoMap = new Dictionary <IDeliveryChannel, IReadOnlyCollection <ChannelOperationOutcomeInfo> >();

            foreach (var channel in channels)
            {
                new { this.channelToEventStreamMap }.AsOp().Must().ContainKey(channel, Invariant($"Looking for success/failure events on event stream for chanel {channel.GetType().ToStringReadable()} but there is no event stream associated with that channel."));

                var eventStream = this.channelToEventStreamMap[channel];

                var operationsMonitoringInfo = processSendNotificationSagaOp.ChannelToOperationsMonitoringInfoMap[channel];

                var operationsOutcomeInfo = new List <ChannelOperationOutcomeInfo>();

                channelToOperationsOutcomeInfoMap.Add(channel, operationsOutcomeInfo);

                foreach (var operationMonitoringInfo in operationsMonitoringInfo)
                {
                    ChannelOperationOutcomeInfo operationOutcomeInfo;

                    var failureEventMetadata = await eventStream.GetLatestRecordMetadataByIdAsync(
                        operationMonitoringInfo.ChannelOperationTrackingCodeId,
                        operationMonitoringInfo.FailedEventType,
                        recordNotFoundStrategy : RecordNotFoundStrategy.ReturnDefault);

                    if (failureEventMetadata != null)
                    {
                        // Merge-in the tags on the failure event.
                        AddMissingTags(inheritableTags, failureEventMetadata.Tags);

                        operationOutcomeInfo = new ChannelOperationOutcomeInfo(operationMonitoringInfo.ChannelOperationTrackingCodeId, operationMonitoringInfo.FailedEventType, ChannelOperationOutcome.Failed);
                    }
                    else
                    {
                        var successEventMetadata = await eventStream.GetLatestRecordMetadataByIdAsync(
                            operationMonitoringInfo.ChannelOperationTrackingCodeId,
                            operationMonitoringInfo.SucceededEventType,
                            recordNotFoundStrategy : RecordNotFoundStrategy.ReturnDefault);

                        if (successEventMetadata != null)
                        {
                            // Merge-in the tags on the success event.
                            AddMissingTags(inheritableTags, successEventMetadata.Tags);

                            operationOutcomeInfo = new ChannelOperationOutcomeInfo(operationMonitoringInfo.ChannelOperationTrackingCodeId, operationMonitoringInfo.SucceededEventType, ChannelOperationOutcome.Succeeded);
                        }
                        else
                        {
                            // Neither succeeded nor failed, cancel the run and let this handler try again in the future.
                            throw new SelfCancelRunningExecutionException(Invariant($"Notification '{executeOpRequestedEvent.Id}' is being sent on the '{channel.GetType().ToStringReadable()}' channel via channel-operation '{operationMonitoringInfo.ChannelOperationTrackingCodeId}', however the events that indicate whether the operation succeeded ('{operationMonitoringInfo.SucceededEventType}') or failed ('{operationMonitoringInfo.FailedEventType}') do not exist in the channel event stream.  Is the operation still executing?  Cancelling the handling of this Saga operation."));
                        }
                    }

                    operationsOutcomeInfo.Add(operationOutcomeInfo);
                }
            }

            // Write the AttemptToSendNotificationEventBase to the Event Stream.
            var notificationTrackingCodeId = processSendNotificationSagaOp.NotificationTrackingCodeId;

            var attemptToSendNotificationResult = new AttemptToSendNotificationResult(channelToOperationsOutcomeInfoMap);

            var attemptToSendNotificationOutcome = attemptToSendNotificationResult.GetOutcome();

            AttemptToSendNotificationEventBase attemptToSendNotificationEvent;

            switch (attemptToSendNotificationOutcome)
            {
            case AttemptToSendNotificationOutcome.SentOnAllPreparedChannels:
                attemptToSendNotificationEvent = new SentOnAllPreparedChannelsEvent(notificationTrackingCodeId, DateTime.UtcNow, attemptToSendNotificationResult);
                break;

            case AttemptToSendNotificationOutcome.SentOnSomePreparedChannels:
                attemptToSendNotificationEvent = new SentOnSomePreparedChannelsEvent(notificationTrackingCodeId, DateTime.UtcNow, attemptToSendNotificationResult);
                break;

            case AttemptToSendNotificationOutcome.CouldNotSendOnAnyPreparedChannel:
                attemptToSendNotificationEvent = new CouldNotSendOnAnyPreparedChannelEvent(notificationTrackingCodeId, DateTime.UtcNow, attemptToSendNotificationResult);
                break;

            default:
                throw new NotSupportedException(Invariant($"This {nameof(AttemptToSendNotificationOutcome)} is not supported: {attemptToSendNotificationOutcome}."));
            }

            var tags = this.buildAttemptToSendNotificationEventTagsProtocol.ExecuteBuildTags(notificationTrackingCodeId, attemptToSendNotificationEvent, inheritableTags);

            await this.notificationEventStream.PutWithIdAsync(notificationTrackingCodeId, attemptToSendNotificationEvent, tags, ExistingRecordStrategy.DoNotWriteIfFoundByIdAndType);
        }
Пример #3
0
        public NotificationDummyFactory()
        {
            /* Add any overriding or custom registrations here. */

            // enums
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(CannotPrepareToSendOnChannelAction.Unknown);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(DeliveryChannelAction.Unknown);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(FailureAction.Unknown);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(PrepareToSendOnChannelFailureAction.Unknown);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(AttemptToSendNotificationOutcome.Unknown);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(ChannelOperationOutcome.Unknown);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(GetAudienceOutcome.Unknown);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(GetDeliveryChannelConfigsOutcome.Unknown);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(PrepareToSendNotificationOutcome.Unknown);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(PrepareToSendOnChannelOutcome.Unknown);

            // interfaces
            AutoFixtureBackedDummyFactory.AddDummyCreator <IOperation>(A.Dummy <OperationBase>);// remove when moved to Protocol Dummy Factory
            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IAudience>();
            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IDeliveryChannel>();
            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IFailure>();
            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <INotification>();

            // events
            AutoFixtureBackedDummyFactory.AddDummyCreator(() => new CouldNotSendOnAnyPreparedChannelEvent(
                                                              A.Dummy <long>(),
                                                              A.Dummy <UtcDateTime>(),
                                                              A.Dummy <AttemptToSendNotificationResult>().Whose(_ => _.GetOutcome() == AttemptToSendNotificationOutcome.CouldNotSendOnAnyPreparedChannel)));

            AutoFixtureBackedDummyFactory.AddDummyCreator(() => new SentOnAllPreparedChannelsEvent(
                                                              A.Dummy <long>(),
                                                              A.Dummy <UtcDateTime>(),
                                                              A.Dummy <AttemptToSendNotificationResult>().Whose(_ => _.GetOutcome() == AttemptToSendNotificationOutcome.SentOnAllPreparedChannels)));

            AutoFixtureBackedDummyFactory.AddDummyCreator(() => new SentOnSomePreparedChannelsEvent(
                                                              A.Dummy <long>(),
                                                              A.Dummy <UtcDateTime>(),
                                                              A.Dummy <AttemptToSendNotificationResult>().Whose(_ => _.GetOutcome() == AttemptToSendNotificationOutcome.SentOnSomePreparedChannels)));

            AutoFixtureBackedDummyFactory.AddDummyCreator(() => new CouldNotGetOrUseAudienceEvent(
                                                              A.Dummy <long>(),
                                                              A.Dummy <UtcDateTime>(),
                                                              A.Dummy <GetAudienceResult>().Whose(_ => (_.GetOutcome() != GetAudienceOutcome.GotAudienceWithNoFailuresReported) && (_.GetOutcome() != GetAudienceOutcome.GotAudienceWithReportedFailuresIgnored))));

            AutoFixtureBackedDummyFactory.AddDummyCreator(() => new CouldNotGetOrUseDeliveryChannelConfigsEvent(
                                                              A.Dummy <long>(),
                                                              A.Dummy <UtcDateTime>(),
                                                              GetPassingAudienceResult(),
                                                              A.Dummy <GetDeliveryChannelConfigsResult>().Whose(_ => (_.GetOutcome() != GetDeliveryChannelConfigsOutcome.GotDeliveryChannelConfigsWithNoFailuresReported) && (_.GetOutcome() != GetDeliveryChannelConfigsOutcome.GotDeliveryChannelConfigsWithReportedFailuresIgnored))));

            AutoFixtureBackedDummyFactory.AddDummyCreator(() => new AudienceOptedOutOfAllChannelsEvent(
                                                              A.Dummy <long>(),
                                                              A.Dummy <UtcDateTime>(),
                                                              GetPassingAudienceResult(),
                                                              GetPassingDeliveryChannelConfigsResult(),
                                                              A.Dummy <PrepareToSendNotificationResult>().Whose(_ => (_.GetOutcome() == PrepareToSendNotificationOutcome.AudienceOptedOutOfAllChannels))));

            AutoFixtureBackedDummyFactory.AddDummyCreator(() => new CouldNotPrepareToSendOnAnyChannelEvent(
                                                              A.Dummy <long>(),
                                                              A.Dummy <UtcDateTime>(),
                                                              GetPassingAudienceResult(),
                                                              GetPassingDeliveryChannelConfigsResult(),
                                                              A.Dummy <PrepareToSendNotificationResult>().Whose(_ => (_.GetOutcome() == PrepareToSendNotificationOutcome.CouldNotPrepareToSendOnAnyChannelDespiteAttemptingAll) || (_.GetOutcome() == PrepareToSendNotificationOutcome.CouldNotPrepareToSendOnAnyChannelBecauseOneForcedAllToBeDiscarded))));

            AutoFixtureBackedDummyFactory.AddDummyCreator(() => new PreparedToSendOnAllChannelsEvent(
                                                              A.Dummy <long>(),
                                                              A.Dummy <UtcDateTime>(),
                                                              GetPassingAudienceResult(),
                                                              GetPassingDeliveryChannelConfigsResult(),
                                                              A.Dummy <PrepareToSendNotificationResult>().Whose(_ => (_.GetOutcome() == PrepareToSendNotificationOutcome.PreparedToSendOnAllChannels))));

            AutoFixtureBackedDummyFactory.AddDummyCreator(() => new PreparedToSendOnSomeChannelsEvent(
                                                              A.Dummy <long>(),
                                                              A.Dummy <UtcDateTime>(),
                                                              GetPassingAudienceResult(),
                                                              GetPassingDeliveryChannelConfigsResult(),
                                                              A.Dummy <PrepareToSendNotificationResult>().Whose(_ => (_.GetOutcome() == PrepareToSendNotificationOutcome.PreparedToSendOnSomeChannels))));

            AutoFixtureBackedDummyFactory.AddDummyCreator(() => new SendNotificationRequestedEvent(
                                                              A.Dummy <long>(),
                                                              A.Dummy <UtcDateTime>(),
                                                              A.Dummy <SendNotificationOp>()));

            // model classes
            AutoFixtureBackedDummyFactory.AddDummyCreator(() =>
            {
                var channelToOperationsOutcomeInfoMap = new Dictionary <IDeliveryChannel, IReadOnlyCollection <ChannelOperationOutcomeInfo> >();

                var randomIndex = ThreadSafeRandom.Next(1, 4);

                var randomChannels = new IDeliveryChannel[] { new SlackDeliveryChannel(), new EmailDeliveryChannel() }.RandomizeElements().ToArray();

                if (randomIndex == 1)
                {
                    // SentOnAllPreparedChannels
                    randomChannels = randomChannels.Take(ThreadSafeRandom.Next(1, randomChannels.Length + 1)).ToArray();

                    foreach (var randomChannel in randomChannels)
                    {
                        channelToOperationsOutcomeInfoMap.Add(
                            randomChannel,
                            Some.ReadOnlyDummies <ChannelOperationOutcomeInfo>().Whose(_ => _.All(o => o.Outcome == ChannelOperationOutcome.Succeeded)).ToList());
                    }
                }
                else if (randomIndex == 2)
                {
                    // SentOnSomePreparedChannels
                    channelToOperationsOutcomeInfoMap.Add(
                        randomChannels[0],
                        Some.ReadOnlyDummies <ChannelOperationOutcomeInfo>().Whose(_ => _.Select(o => o.Outcome).Distinct().Count() > 1).ToList());

                    channelToOperationsOutcomeInfoMap.Add(
                        randomChannels[1],
                        Some.ReadOnlyDummies <ChannelOperationOutcomeInfo>().Whose(_ => _.All(o => o.Outcome == ChannelOperationOutcome.Succeeded)).ToList());
                }
                else
                {
                    // CouldNotSendOnAnyPreparedChannel
                    channelToOperationsOutcomeInfoMap.Add(
                        randomChannels[0],
                        Some.ReadOnlyDummies <ChannelOperationOutcomeInfo>().Whose(_ => _.Select(o => o.Outcome).Distinct().Count() > 1).ToList());

                    channelToOperationsOutcomeInfoMap.Add(
                        randomChannels[1],
                        Some.ReadOnlyDummies <ChannelOperationOutcomeInfo>().Whose(_ => _.All(o => o.Outcome == ChannelOperationOutcome.Failed)).ToList());
                }


                var result = new AttemptToSendNotificationResult(channelToOperationsOutcomeInfoMap);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(() =>
            {
                var randomIndex = ThreadSafeRandom.Next(1, 6);

                GetAudienceResult result;

                if (randomIndex == 1)
                {
                    // GotAudienceWithNoFailuresReported
                    result = new GetAudienceResult(A.Dummy <IAudience>(), null, A.Dummy <FailureAction>());
                }
                else if (randomIndex == 2)
                {
                    // GotAudienceWithReportedFailuresIgnored
                    result = new GetAudienceResult(A.Dummy <IAudience>(), Some.ReadOnlyDummies <IFailure>().ToList(), FailureAction.IgnoreAndProceedIfPossibleOtherwiseStop);
                }
                else if (randomIndex == 3)
                {
                    // CouldNotGetAudienceAndNoFailuresReported
                    if (ThreadSafeRandom.Next(2) == 0)
                    {
                        result = new GetAudienceResult(null, null, A.Dummy <FailureAction>());
                    }
                    else
                    {
                        result = new GetAudienceResult(null, new IFailure[0], A.Dummy <FailureAction>());
                    }
                }
                else if (randomIndex == 4)
                {
                    // CouldNotGetAudienceWithSomeFailuresReported
                    result = new GetAudienceResult(null, Some.ReadOnlyDummies <IFailure>().ToList(), A.Dummy <FailureAction>());
                }
                else
                {
                    // DespiteGettingAudienceFailuresPreventUsingIt
                    result = new GetAudienceResult(A.Dummy <IAudience>(), Some.ReadOnlyDummies <IFailure>().ToList(), FailureAction.Stop);
                }

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(() =>
            {
                var randomChannels = new IDeliveryChannel[] { new SlackDeliveryChannel(), new EmailDeliveryChannel() };

                randomChannels = randomChannels.RandomizeElements().Take(ThreadSafeRandom.Next(1, randomChannels.Length + 1)).ToArray();

                var deliveryChannelConfigs = randomChannels.Select(_ => new DeliveryChannelConfig(_, A.Dummy <DeliveryChannelAction>())).ToList();

                var randomIndex = ThreadSafeRandom.Next(1, 6);

                GetDeliveryChannelConfigsResult result;

                if (randomIndex == 1)
                {
                    // GotDeliveryChannelConfigsWithNoFailuresReported
                    result = new GetDeliveryChannelConfigsResult(
                        deliveryChannelConfigs,
                        null,
                        A.Dummy <FailureAction>());
                }
                else if (randomIndex == 2)
                {
                    // GotDeliveryChannelConfigsWithReportedFailuresIgnored
                    result = new GetDeliveryChannelConfigsResult(
                        deliveryChannelConfigs,
                        Some.ReadOnlyDummies <IFailure>().ToList(),
                        FailureAction.IgnoreAndProceedIfPossibleOtherwiseStop);
                }
                else if (randomIndex == 3)
                {
                    // CouldNotGetDeliveryChannelConfigsAndNoFailuresReported
                    result = new GetDeliveryChannelConfigsResult(null, null, A.Dummy <FailureAction>());
                }
                else if (randomIndex == 4)
                {
                    // CouldNotGetDeliveryChannelConfigsWithSomeFailuresReported
                    result = new GetDeliveryChannelConfigsResult(null, Some.ReadOnlyDummies <IFailure>().ToList(), A.Dummy <FailureAction>());
                }
                else
                {
                    // DespiteGettingDeliveryChannelConfigsFailuresPreventUsingThem
                    result = new GetDeliveryChannelConfigsResult(
                        deliveryChannelConfigs,
                        Some.ReadOnlyDummies <IFailure>().ToList(),
                        FailureAction.Stop);
                }

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(() =>
            {
                var randomChannels = new IDeliveryChannel[] { new SlackDeliveryChannel(), new EmailDeliveryChannel() }.RandomizeElements().ToArray();

                var randomIndex = ThreadSafeRandom.Next(1, 6);

                PrepareToSendNotificationResult result;

                if (randomIndex == 1)
                {
                    // AudienceOptedOutOfAllChannels
                    result = new PrepareToSendNotificationResult(
                        new Dictionary <IDeliveryChannel, PrepareToSendOnChannelResult>(),
                        A.Dummy <CannotPrepareToSendOnChannelAction>(),
                        new IDeliveryChannel[0]);
                }
                else if (randomIndex == 2)
                {
                    // PreparedToSendOnAllChannels
                    var channelToPrepareToSendOnChannelResultMap = new Dictionary <IDeliveryChannel, PrepareToSendOnChannelResult>();

                    foreach (var randomChannel in randomChannels)
                    {
                        channelToPrepareToSendOnChannelResultMap.Add(
                            randomChannel,
                            new PrepareToSendOnChannelResult(GetChannelOperationInstructions(), null, A.Dummy <PrepareToSendOnChannelFailureAction>()));
                    }

                    result = new PrepareToSendNotificationResult(
                        channelToPrepareToSendOnChannelResultMap,
                        A.Dummy <CannotPrepareToSendOnChannelAction>(),
                        randomChannels);
                }
                else if (randomIndex == 3)
                {
                    // PreparedToSendOnSomeChannels
                    result = new PrepareToSendNotificationResult(
                        new Dictionary <IDeliveryChannel, PrepareToSendOnChannelResult>
                    {
                        {
                            randomChannels[0],
                            new PrepareToSendOnChannelResult(
                                GetChannelOperationInstructions(),
                                Some.ReadOnlyDummies <IFailure>().ToList(),
                                PrepareToSendOnChannelFailureAction.IgnoreAndProceedIfPossibleOtherwiseDoNotSendOnChannel)
                        },
                        {
                            randomChannels[1],
                            new PrepareToSendOnChannelResult(
                                null,
                                null,
                                PrepareToSendOnChannelFailureAction.IgnoreAndProceedIfPossibleOtherwiseDoNotSendOnChannel)
                        },
                    },
                        CannotPrepareToSendOnChannelAction.ContinueAndAttemptPreparingToSendOnNextChannel,
                        new IDeliveryChannel[] { randomChannels[0] });
                }
                else if (randomIndex == 4)
                {
                    // CouldNotPrepareToSendOnAnyChannelDespiteAttemptingAll
                    result = new PrepareToSendNotificationResult(
                        new Dictionary <IDeliveryChannel, PrepareToSendOnChannelResult>
                    {
                        {
                            new SlackDeliveryChannel(),
                            new PrepareToSendOnChannelResult(
                                null,
                                null,
                                PrepareToSendOnChannelFailureAction.IgnoreAndProceedIfPossibleOtherwiseDoNotSendOnChannel)
                        },
                        {
                            new EmailDeliveryChannel(),
                            new PrepareToSendOnChannelResult(
                                GetChannelOperationInstructions(),
                                Some.ReadOnlyDummies <IFailure>().ToList(),
                                PrepareToSendOnChannelFailureAction.DoNotSendOnChannel)
                        },
                    },
                        CannotPrepareToSendOnChannelAction.ContinueAndAttemptPreparingToSendOnNextChannel,
                        new IDeliveryChannel[0]);
                }
                else
                {
                    // CouldNotPrepareToSendOnAnyChannelBecauseOneForcedAllToBeDiscarded
                    result = new PrepareToSendNotificationResult(
                        new Dictionary <IDeliveryChannel, PrepareToSendOnChannelResult>
                    {
                        {
                            randomChannels[0],
                            new PrepareToSendOnChannelResult(
                                GetChannelOperationInstructions(),
                                Some.ReadOnlyDummies <IFailure>().ToList(),
                                PrepareToSendOnChannelFailureAction.DoNotSendOnChannel)
                        },
                    },
                        CannotPrepareToSendOnChannelAction.StopAndNotDoNotSendOnAnyChannel,
                        new IDeliveryChannel[0]);
                }

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(() =>
            {
                var randomIndex = ThreadSafeRandom.Next(1, 6);

                PrepareToSendOnChannelResult result;

                if (randomIndex == 1)
                {
                    // PreparedToSendOnChannelWithNoFailuresReported
                    result = new PrepareToSendOnChannelResult(
                        GetChannelOperationInstructions(),
                        null,
                        A.Dummy <PrepareToSendOnChannelFailureAction>());
                }
                else if (randomIndex == 2)
                {
                    // PreparedToSendOnChannelWithReportedFailuresIgnored
                    result = new PrepareToSendOnChannelResult(
                        GetChannelOperationInstructions(),
                        Some.ReadOnlyDummies <IFailure>().ToList(),
                        PrepareToSendOnChannelFailureAction.IgnoreAndProceedIfPossibleOtherwiseDoNotSendOnChannel);
                }
                else if (randomIndex == 3)
                {
                    // CouldNotPrepareToSendOnChannelAndNoFailuresReported
                    if (ThreadSafeRandom.Next(2) == 0)
                    {
                        result = new PrepareToSendOnChannelResult(
                            null,
                            null,
                            PrepareToSendOnChannelFailureAction.IgnoreAndProceedIfPossibleOtherwiseDoNotSendOnChannel);
                    }
                    else
                    {
                        result = new PrepareToSendOnChannelResult(
                            new ChannelOperationInstruction[0],
                            new IFailure[0],
                            PrepareToSendOnChannelFailureAction.IgnoreAndProceedIfPossibleOtherwiseDoNotSendOnChannel);
                    }
                }
                else if (randomIndex == 4)
                {
                    // CouldNotPrepareToSendOnChannelWithSomeFailuresReported
                    result = new PrepareToSendOnChannelResult(
                        null,
                        Some.ReadOnlyDummies <IFailure>().ToList(),
                        PrepareToSendOnChannelFailureAction.IgnoreAndProceedIfPossibleOtherwiseDoNotSendOnChannel);
                }
                else
                {
                    // DespitePreparingToSendOnChannelFailuresPreventUsingIt
                    result = new PrepareToSendOnChannelResult(
                        GetChannelOperationInstructions(),
                        Some.ReadOnlyDummies <IFailure>().ToList(),
                        PrepareToSendOnChannelFailureAction.DoNotSendOnChannel);
                }

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(() =>
            {
                var succeededEventType = A.Dummy <TypeRepresentation>();

                var failedEventType = A.Dummy <TypeRepresentation>().ThatIsNot(succeededEventType);

                var result = new ChannelOperationMonitoringInfo(A.Dummy <long>(), succeededEventType, failedEventType);

                return(result);
            });
        }