コード例 #1
0
        public async Task <object> RunAsync(ExpectEventsScenario scenario, CancellationToken ct = default)
        {
            var checkpoint = await WriteGivens(scenario.Givens);

            var exception = await Catch.Exception(() => _resolver(scenario.When)(scenario.When, ct));

            if (exception != null)
            {
                return(scenario.ButThrewException(exception));
            }

            var recordedEvents = await ReadThens(checkpoint);

            var config = new ComparisonConfig
            {
                MaxDifferences = int.MaxValue,
                MaxStructDepth = 5
            };
            var comparer       = new CompareLogic(config);
            var expectedEvents = Array.ConvertAll(scenario.Thens,
                                                  then => new RecordedEvent(_converter(new StreamName(then.Stream)), then.Event));
            var result = comparer.Compare(expectedEvents, recordedEvents);

            if (result.AreEqual)
            {
                return(scenario.Pass());
            }
            return(scenario.ButRecordedOtherEvents(recordedEvents));
        }