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

            var envelope = scenario.When is CommandEnvelope
                ? (CommandEnvelope)scenario.When
                : new CommandEnvelope()
                           .SetCommand(scenario.When)
                           .SetCommandId(Guid.NewGuid())
                           .SetCorrelationId(Guid.NewGuid())
                           .SetSourceId(Guid.NewGuid());
            var exception = await Catch.Exception(() => _invoker.Invoke(envelope, ct));

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

            var recordedEvents = await ReadThens(checkpoint);

            if (scenario.Givens.Length != 0 && recordedEvents.Length != 0)
            {
                recordedEvents = recordedEvents.Skip(1).ToArray();
            }
            var config = new ComparisonConfig
            {
                MaxDifferences  = int.MaxValue,
                MaxStructDepth  = 5,
                MembersToIgnore = new List <string>
                {
                    "MsgId"
                }
            };
            var comparer       = new CompareLogic(config);
            var expectedEvents = Array.ConvertAll(scenario.Thens,
                                                  then => new ReactiveDomain.Testing.RecordedEvent(_converter(new StreamName(then.Stream)), then.Event));
            var result = comparer.Compare(expectedEvents, recordedEvents);

            if (result.AreEqual)
            {
                return(scenario.Pass());
            }
            return(scenario.ButRecordedOtherEvents(recordedEvents)); //, result.Differences.ToArray()
        }
コード例 #2
0
ファイル: Show.cs プロジェクト: dipdapdop/reactive-domain
        public static void Usage()
        {
            var groupId   = new GroupIdentifier(Guid.NewGuid());
            var groupName = new GroupName("Elvis Fanclub");
            var john      = new GroupAdministratorIdentifier(Guid.NewGuid());
            var jane      = new GroupAdministratorIdentifier(Guid.NewGuid());

            //Start a group (imagine a command)
            var group = Group.Start(groupId, groupName, john);

            PrintRecords(group);

            //Stop a group (imagine a command)
            group.Stop(jane);
            PrintRecords(group);

            //Take a snapshot of the group
            var source   = (ISnapshotSource)group;
            var snapshot = source.TakeSnapshot();

            //Restore another instance from the snapshot
            var groupFromStore = Group.Factory();
            var destination    = (ISnapshotSource)groupFromStore;

            destination.RestoreFromSnapshot(snapshot);

            //Here's an example of a composition root
            var settings = new JsonSerializerSettings();
            var invoker  = new CommandHandlerInvoker(
                new CommandHandlerModule[]
            {
                new GroupModule(
                    new GroupRepository(
                        null,     /* todo - connection to embedded eventstore */
                        new EventSourceReaderConfiguration(
                            StreamNameConversions.PassThru,
                            () =>
                            new StreamEventsSliceTranslator(
                                typeName => Type.GetType(typeName, true),
                                settings),
                            new SliceSize(100)),
                        new EventSourceWriterConfiguration(
                            StreamNameConversions.PassThru,
                            new EventSourceChangesetTranslator(type => type.FullName, settings))))
            });

            // Somewhere in the infrastructure, probably as part of an IHandleCommand<> (see below)
            var command =
                /* typically comes from the wire, here in deserialized shape. */
                new StartGroup(Guid.NewGuid(), "Fans of Elvis", Guid.NewGuid());

            invoker.Invoke(new CommandEnvelope().SetCommand(command)).Wait(); //Don't block obviously, go full async.
        }