Пример #1
0
        public Specification()
        {
            var eventpublisher  = new SpecEventPublisher();
            var eventstorage    = new SpecEventStorage(eventpublisher, Given().ToList());
            var snapshotstorage = new SpecSnapShotStorage(Snapshot);

            var snapshotStrategy = new DefaultSnapshotStrategy();
            var repository       = new SnapshotRepository(snapshotstorage, snapshotStrategy, new Repository(eventstorage), eventstorage);

            Session   = new Session(repository);
            Aggregate = GetAggregate().Result;

            dynamic handler = BuildHandler();

            if (handler is ICancellableCommandHandler <TCommand> )
            {
                handler.Handle(When(), new CancellationToken());
            }
            else if (handler is ICommandHandler <TCommand> )
            {
                handler.Handle(When());
            }
            else
            {
                throw new InvalidCastException($"{nameof(handler)} is not a command handler of type {typeof(TCommand)}");
            }

            Snapshot         = snapshotstorage.Snapshot;
            PublishedEvents  = eventpublisher.PublishedEvents;
            EventDescriptors = eventstorage.Events;
        }
Пример #2
0
        public ConditionalWhenSpecification()
        {
            var eventpublisher  = new SpecEventPublisher();
            var eventstorage    = new SpecEventStorage(eventpublisher, Given().ToList());
            var snapshotstorage = new SpecSnapShotStorage(Snapshot);

            var snapshotStrategy = new DefaultSnapshotStrategy();
            var repository       = new SnapshotRepository(snapshotstorage, snapshotStrategy, new Repository(eventstorage), eventstorage);

            Session   = new Session(repository);
            Aggregate = GetAggregate().Result;

            if (this.InvokeBuildWhenOnConstruct)
            {
                Task.Run(() => this.InvokeBuildWhen()).Wait();
            }

            Snapshot         = snapshotstorage.Snapshot;
            PublishedEvents  = eventpublisher.PublishedEvents;
            EventDescriptors = eventstorage.Events;
        }