Example #1
0
        /// <summary>
        /// Matches to set using the provided <see cref="RecordExistsMatchStrategy"/>.
        /// </summary>
        /// <param name="recordExistsSet">The set to inspect.</param>
        /// <param name="recordExistsMatchStrategy">The strategy to use for evaluating the set.</param>
        /// <returns>
        /// <c>true</c> if the set match, otherwise <c>false</c>.
        /// </returns>
        public static bool MatchesAccordingToStrategy(
            this IReadOnlyCollection <bool> recordExistsSet,
            RecordExistsMatchStrategy recordExistsMatchStrategy)
        {
            recordExistsSet.MustForArg(nameof(recordExistsSet)).NotBeNullNorEmptyEnumerableNorContainAnyNulls();
            recordExistsMatchStrategy.MustForArg(nameof(recordExistsMatchStrategy)).NotBeEqualTo(RecordExistsMatchStrategy.Unknown);

            bool result;

            if (recordExistsMatchStrategy == RecordExistsMatchStrategy.AllFound)
            {
                result = recordExistsSet.All(_ => _);
            }
            else if (recordExistsMatchStrategy == RecordExistsMatchStrategy.SomeFound)
            {
                result = recordExistsSet.Any(_ => _);
            }
            else if (recordExistsMatchStrategy == RecordExistsMatchStrategy.NoneFound)
            {
                result = recordExistsSet.All(_ => !_);
            }
            else
            {
                throw new NotSupportedException(Invariant($"This {nameof(RecordExistsMatchStrategy)} is not supported {recordExistsMatchStrategy}."));
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventToPutWithIdOnRecordFilterMatch{TId}"/> class.
        /// </summary>
        /// <param name="recordExistsMatchStrategy">The <see cref="RecordExistsMatchStrategy"/> to use with supplied filter.</param>
        /// <param name="eventToPut">The event to put on a match.</param>
        /// <param name="chainOfResponsibilityLinkMatchStrategy">OPTIONAL strategy override to determine what to do in the execution on a match; DEFAULT is Halt and Complete.</param>
        public EventToPutWithIdOnRecordFilterMatch(
            RecordExistsMatchStrategy recordExistsMatchStrategy,
            EventToPutWithId <TId> eventToPut,
            ChainOfResponsibilityLinkMatchStrategy chainOfResponsibilityLinkMatchStrategy = ChainOfResponsibilityLinkMatchStrategy.MatchHaltsEvaluationOfChainAndCompletes)
        {
            recordExistsMatchStrategy.MustForArg(nameof(recordExistsMatchStrategy)).NotBeEqualTo(CompositeHandlingStatusMatchStrategy.Unknown);
            eventToPut.MustForArg(nameof(eventToPut)).NotBeNull();
            chainOfResponsibilityLinkMatchStrategy.MustForArg(nameof(chainOfResponsibilityLinkMatchStrategy)).NotBeEqualTo(ChainOfResponsibilityLinkMatchStrategy.Unknown);

            this.RecordExistsMatchStrategy = recordExistsMatchStrategy;
            this.EventToPut = eventToPut;
            this.ChainOfResponsibilityLinkMatchStrategy = chainOfResponsibilityLinkMatchStrategy;
        }
        public EventToPutWithIdOnRecordFilterMatch <TId> DeepCloneWithRecordExistsMatchStrategy(RecordExistsMatchStrategy recordExistsMatchStrategy)
        {
            var result = new EventToPutWithIdOnRecordFilterMatch <TId>(
                recordExistsMatchStrategy,
                this.EventToPut?.DeepClone(),
                this.ChainOfResponsibilityLinkMatchStrategy.DeepClone());

            return(result);
        }