コード例 #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));
        }
コード例 #2
0
        public async Task WriteAsync(ExpectEventsScenario scenario)
        {
            if (scenario == null)
            {
                throw new ArgumentNullException(nameof(scenario));
            }

            await Writer.WriteLineAsync("Given");

            await Writer.WriteLineAsync("");

            foreach (var given in scenario.Givens)
            {
                await Writer.WriteLineAsync(string.Format("\t[{0}] {1}", given.Stream, Translator.Translate(given.Event)));
            }

            await Writer.WriteLineAsync("When");

            await Writer.WriteLineAsync("");

            await Writer.WriteLineAsync(string.Format("\t{0}", Translator.Translate(scenario.When.Body)));

//            foreach (var header in scenario.When.Head)
//            {
//                await Writer.WriteLineAsync(string.Format("\t{0}", Translator.Translate(header)));
//            }

            await Writer.WriteLineAsync("Then");

            await Writer.WriteLineAsync("");

            foreach (var then in scenario.Thens)
            {
                await Writer.WriteLineAsync(string.Format("\t[{0}] {1}", then.Stream, Translator.Translate(then.Event)));
            }
        }
コード例 #3
0
 public ScenarioExpectedEventsButThrewException(ExpectEventsScenario scenario, Exception actual)
 {
     Scenario = scenario ?? throw new ArgumentNullException(nameof(scenario));
     Actual   = actual ?? throw new ArgumentNullException(nameof(actual));
 }
コード例 #4
0
 public ScenarioExpectedEventsButRecordedOtherEvents(ExpectEventsScenario scenario, RecordedEvent[] actual)
 {
     Scenario = scenario ?? throw new ArgumentNullException(nameof(scenario));
     Actual   = actual ?? throw new ArgumentNullException(nameof(actual));
 }
コード例 #5
0
 public ExpectEventsScenarioPassed(ExpectEventsScenario scenario)
 {
     Scenario = scenario ?? throw new ArgumentNullException(nameof(scenario));
 }