private static ExpectedMarble CreateUnorderedGroupExpectedMarble <TEvent>( Moment moment, Func <FSharpOption <TEvent> > eventProducer, Action <string, TEvent> assertion) => new ExpectedMarble( moment.Time, moment.ToString(), () => { var produced = moment.Marbles.Select(_ => eventProducer()).ToList(); var received = produced.Where(FSharpOption <TEvent> .get_IsSome).Select(t => t.Value).ToList(); if (received.Count != moment.Marbles.Length) { throw new Exception( $"At time {moment.Time}, expecting an unordered group {moment} with {moment.Marbles.Length} elements but got {received.Count} events: [{string.Join(" ", received)}]"); } var table = FillAssertionResultTable(moment, assertion, received); var success = table.AllRowsAtLeastOneSuccess() && table.AllColumnsAtLeastOneSuccess(); if (!success) { throw new Exception(table.ToString()); } });
private static IEnumerable <ExpectedMarble> CreateLooseExpectations <TEvent>( Moment moment, Func <FSharpOption <TEvent> > eventProducer, Action <string, TEvent> assertion) { var momentMarbles = new List <ExpectedMarble>(); switch (moment.Type) { case Moment.MomentType.Empty: break; case Moment.MomentType.Single: var marble = moment.Marbles[0]; momentMarbles.Add(CreateSingleLooselyExpectedMarble(moment, eventProducer, assertion, marble)); break; case Moment.MomentType.OrderedGroup: momentMarbles.Add(CreateOrderedGroupLooselyExpectedMarble(moment, eventProducer, assertion)); break; case Moment.MomentType.UnorderedGroup: momentMarbles.Add(CreateSingleLooselyExpectedMarble(moment, eventProducer, assertion, moment.ToString())); break; default: throw new ArgumentOutOfRangeException(); } momentMarbles.Add( new ExpectedMarble( moment.Time, null, () => ExhaustProducer(eventProducer))); return(momentMarbles); }