Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HandleSendNotificationProtocol"/> class.
        /// </summary>
        /// <param name="eventStream">The Notification Event Stream.</param>
        /// <param name="sagaStream">The Notification Saga Stream.</param>
        /// <param name="getAudienceProtocol">Executes a <see cref="GetAudienceOp"/>.</param>
        /// <param name="getDeliveryChannelConfigsProtocol">Executes a <see cref="GetDeliveryChannelConfigsOp"/>.</param>
        /// <param name="prepareToSendOnChannelProtocol">Executes a <see cref="PrepareToSendOnChannelOp"/>.</param>
        /// <param name="cannotPrepareToSendOnChannelAction">Specifies what to do when we encounter a situation where we cannot prepare to send on a channel.</param>
        /// <param name="channelToOperationStreamMap">A map of delivery channel to the channel's operation stream.</param>
        /// <param name="buildSendNotificationRequestedEventTagsProtocol">OPTIONAL protocol to builds the tags to use when putting the <see cref="SendNotificationRequestedEvent"/> into the Notification Event Stream.  DEFAULT is to not add any tags; tags will be null.  Consider using <see cref="UseInheritableTagsProtocol{TEvent}"/> to just use the inheritable tags.</param>
        /// <param name="buildCouldNotGetOrUseAudienceEventTagsProtocol">OPTIONAL protocol to builds the tags to use when putting the <see cref="CouldNotGetOrUseAudienceEvent"/> into the Notification Event Stream.  DEFAULT is to not add any tags; tags will be null.  Consider using <see cref="UseInheritableTagsProtocol{TEvent}"/> to just use the inheritable tags.</param>
        /// <param name="buildCouldNotGetOrUseDeliveryChannelConfigsEventTagsProtocol">OPTIONAL protocol to builds the tags to use when putting the <see cref="CouldNotGetOrUseDeliveryChannelConfigsEvent"/> into the Notification Event Stream.  DEFAULT is to not add any tags; tags will be null.  Consider using <see cref="UseInheritableTagsProtocol{TEvent}"/> to just use the inheritable tags.</param>
        /// <param name="buildPrepareToSendNotificationEventTagsProtocol">OPTIONAL protocol to builds the tags to use when putting the <see cref="PrepareToSendNotificationEventBase"/> into the Notification Event Stream.  DEFAULT is to not add any tags; tags will be null.  Consider using <see cref="UseInheritableTagsProtocol{TEvent}"/> to just use the inheritable tags.</param>
        /// <param name="buildExecuteProcessSendNotificationSagaEventTagsProtocol">OPTIONAL protocol to builds the tags to use when putting the <see cref="ProcessSendNotificationSagaOp"/> into the Notification Saga Stream.  DEFAULT is to not add any tags; tags will be null.  Consider using <see cref="UseInheritableTagsProtocol{TEvent}"/> to just use the inheritable tags.</param>
        public HandleSendNotificationProtocol(
            IWriteOnlyStream eventStream,
            IWriteOnlyStream sagaStream,
            IGetAudienceProtocol getAudienceProtocol,
            IGetDeliveryChannelConfigsProtocol getDeliveryChannelConfigsProtocol,
            IPrepareToSendOnChannelProtocol prepareToSendOnChannelProtocol,
            CannotPrepareToSendOnChannelAction cannotPrepareToSendOnChannelAction,
            IReadOnlyDictionary <IDeliveryChannel, IWriteOnlyStream> channelToOperationStreamMap,
            IBuildTagsProtocol <SendNotificationRequestedEvent> buildSendNotificationRequestedEventTagsProtocol = null,
            IBuildTagsProtocol <CouldNotGetOrUseAudienceEvent> buildCouldNotGetOrUseAudienceEventTagsProtocol   = null,
            IBuildTagsProtocol <CouldNotGetOrUseDeliveryChannelConfigsEvent> buildCouldNotGetOrUseDeliveryChannelConfigsEventTagsProtocol = null,
            IBuildTagsProtocol <PrepareToSendNotificationEventBase> buildPrepareToSendNotificationEventTagsProtocol = null,
            IBuildTagsProtocol <ExecuteOpRequestedEvent <long, ProcessSendNotificationSagaOp> > buildExecuteProcessSendNotificationSagaEventTagsProtocol = null)
        {
            new { eventStream }.AsArg().Must().NotBeNull();
            new { sagaStream }.AsArg().Must().NotBeNull();
            new { getAudienceProtocol }.AsArg().Must().NotBeNull();
            new { getDeliveryChannelConfigsProtocol }.AsArg().Must().NotBeNull();
            new { prepareToSendOnChannelProtocol }.AsArg().Must().NotBeNull();
            new { cannotPrepareToSendOnChannelAction }.AsArg().Must().NotBeEqualTo(CannotPrepareToSendOnChannelAction.Unknown);
            new { channelToOperationStreamMap }.AsArg().Must().NotBeNullNorEmptyDictionaryNorContainAnyNullValues();

            this.eventStream         = eventStream;
            this.sagaStream          = sagaStream;
            this.getAudienceProtocol = getAudienceProtocol;
            this.getDeliveryChannelConfigsProtocol  = getDeliveryChannelConfigsProtocol;
            this.prepareToSendOnChannelProtocol     = prepareToSendOnChannelProtocol;
            this.cannotPrepareToSendOnChannelAction = cannotPrepareToSendOnChannelAction;
            this.channelToOperationStreamMap        = channelToOperationStreamMap;
            this.buildSendNotificationRequestedEventTagsProtocol = buildSendNotificationRequestedEventTagsProtocol;
            this.buildCouldNotGetOrUseAudienceEventTagsProtocol  = buildCouldNotGetOrUseAudienceEventTagsProtocol;
            this.buildCouldNotGetOrUseDeliveryChannelConfigsEventTagsProtocol = buildCouldNotGetOrUseDeliveryChannelConfigsEventTagsProtocol;
            this.buildPrepareToSendNotificationEventTagsProtocol          = buildPrepareToSendNotificationEventTagsProtocol;
            this.buildExecuteProcessSendNotificationSagaEventTagsProtocol = buildExecuteProcessSendNotificationSagaEventTagsProtocol;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PrepareToSendNotificationResult"/> class.
        /// </summary>
        /// <param name="channelToPrepareToSendOnChannelResultMap">A map of channel to the result of executing a <see cref="PrepareToSendOnChannelOp"/>.</param>
        /// <param name="cannotPrepareToSendOnChannelAction">The action taken when the system could not prepare the notification to be sent on a channel.</param>
        /// <param name="channelsToSendOn">The channels that the notification is prepared to be sent on.</param>
        public PrepareToSendNotificationResult(
            IReadOnlyDictionary <IDeliveryChannel, PrepareToSendOnChannelResult> channelToPrepareToSendOnChannelResultMap,
            CannotPrepareToSendOnChannelAction cannotPrepareToSendOnChannelAction,
            IReadOnlyCollection <IDeliveryChannel> channelsToSendOn)
        {
            new { channelToPrepareToSendOnChannelResultMap }.AsArg().Must().NotBeNull().And().NotContainAnyKeyValuePairsWithNullValue();
            var prepareToSendOnChannelResult = channelToPrepareToSendOnChannelResultMap?.Values.ToList();

            new { prepareToSendOnChannelResult }.AsArg().Must().ContainOnlyDistinctElementsWhenNotNull();
            new { cannotPrepareToSendOnChannelAction }.AsArg().Must().NotBeEqualTo(CannotPrepareToSendOnChannelAction.Unknown);
            new { channelsToSendOn }.AsArg().Must().NotBeNull().And().NotContainAnyNullElements().And().ContainOnlyDistinctElements();

            foreach (var channelToSendOn in channelsToSendOn)
            {
                new { channelToPrepareToSendOnChannelResultMap }.AsArg().Must().ContainKey(channelToSendOn);
            }

            this.ChannelToPrepareToSendOnChannelResultMap = channelToPrepareToSendOnChannelResultMap;
            this.CannotPrepareToSendOnChannelAction       = cannotPrepareToSendOnChannelAction;
            this.ChannelsToSendOn = channelsToSendOn;
        }
Ejemplo n.º 3
0
        public PrepareToSendNotificationResult DeepCloneWithCannotPrepareToSendOnChannelAction(CannotPrepareToSendOnChannelAction cannotPrepareToSendOnChannelAction)
        {
            var result = new PrepareToSendNotificationResult(
                this.ChannelToPrepareToSendOnChannelResultMap?.DeepClone(),
                cannotPrepareToSendOnChannelAction,
                this.ChannelsToSendOn?.DeepClone());

            return(result);
        }