Example #1
0
        public async Task find_when_stream_is_new_async()
        {
            var finder = new AggregateFinder <QuestParty>();

            var id = Guid.NewGuid();

            (await finder.FindAsync(StreamAction.Start(id, new AEvent()), theSession, new CancellationToken()))
            .ShouldNotBeNull();
        }
            public StreamAction CreateNewStream()
            {
                var events = new IEvent[] { new Event <AEvent>(new AEvent()) };
                var stream = Store.Events.StreamIdentity == StreamIdentity.AsGuid ? StreamAction.Start(Guid.NewGuid(), events) : StreamAction.Start(Guid.NewGuid().ToString(), events, true);

                stream.TenantId = TenantId;
                stream.Version  = 1;

                return(stream);
            }
Example #3
0
        public void find_when_stream_is_new()
        {
            var session = Substitute.For <IDocumentSession>();

            var finder = new AggregateFinder <QuestParty>();

            var id = Guid.NewGuid();

            finder.Find(StreamAction.Start(id, new AEvent()), session)
            .ShouldNotBeNull();

            session.DidNotReceive().Load <QuestParty>(id);
        }
Example #4
0
        public StreamAction StartStream(string streamKey, params object[] events)
        {
            var step = action(e => e.StartStream(streamKey, events));

            if (events.Count() > 3)
            {
                step.Description = $"StartStream(\"{streamKey}\", events)";
            }
            else
            {
                step.Description = $"StartStream(\"{streamKey}\", {events.Select(x => x.ToString()).Join(", ")})";
            }

            return(StreamAction.Start(_store.Events, streamKey, events));
        }
Example #5
0
        public StreamAction StartStream(Guid id, params object[] events)
        {
            var step = action(e => e.StartStream(id, events));

            if (events.Count() > 3)
            {
                step.Description = $"StartStream({id}, events)";
            }
            else
            {
                step.Description = $"StartStream({id}, {events.Select(x => x.ToString()).Join(", ")})";
            }

            return(StreamAction.Start(_store.Events, id, events));
        }
Example #6
0
        public StreamAction StartStream(params object[] events)
        {
            var streamId = Guid.NewGuid();
            var step     = action(e => e.StartStream(streamId, events));

            if (events.Count() > 3)
            {
                step.Description = "StartStream(events)";
            }
            else
            {
                step.Description = $"StartStream({events.Select(x => x.ToString()).Join(", ")})";
            }

            return(StreamAction.Start(_store.Events, streamId, events));
        }
Example #7
0
        public StreamAction StartStream(Type aggregateType, string streamKey, params object[] events)
        {
            var step = action(e => e.StartStream(aggregateType, streamKey, events));

            if (events.Count() > 3)
            {
                step.Description = $"StartStream({aggregateType.FullNameInCode()}>(\"{streamKey}\", events)";
            }
            else
            {
                step.Description =
                    $"StartStream({aggregateType.FullNameInCode()}, \"{streamKey}\", {events.Select(x => x.ToString()).Join(", ")})";
            }

            return(StreamAction.Start(_store.Events, streamKey, events));
        }
Example #8
0
        public StreamAction StartStream <TAggregate>(string streamKey, params object[] events) where TAggregate : class
        {
            var step = action(e => e.StartStream <TAggregate>(streamKey, events));

            if (events.Count() > 3)
            {
                step.Description = $"StartStream<{typeof(TAggregate).FullNameInCode()}>(\"{streamKey}\", events)";
            }
            else
            {
                step.Description =
                    $"StartStream<{typeof(TAggregate).FullNameInCode()}>(\"{streamKey}\", {events.Select(x => x.ToString()).Join(", ")})";
            }

            return(StreamAction.Start(_store.Events, streamKey, events));
        }
Example #9
0
        public StreamAction StartStream(Type aggregateType, Guid id, IEnumerable <object> events)
        {
            var step = action(e => e.StartStream(aggregateType, id, events));

            if (events.Count() > 3)
            {
                step.Description = $"StartStream({aggregateType.FullNameInCode()}>({id}, events)";
            }
            else
            {
                step.Description =
                    $"StartStream({aggregateType.FullNameInCode()}, {id}, {events.Select(x => x.ToString()).Join(", ")})";
            }

            return(StreamAction.Start(_store.Events, id, events));
        }
        public void can_set_aggregator_through_extension_methods_and_strategy()
        {
            var theGraph = new EventGraph(new StoreOptions());

            theGraph.UseAggregatorLookup(AggregationLookupStrategy.UsePublicApply);

            var aggregator = theGraph.AggregateFor <QuestParty>();

            var stream = StreamAction.Start(Guid.NewGuid(), new object[] { new QuestStarted {
                                                                               Name = "Destroy the Ring"
                                                                           } });

            var party = aggregator.Build(stream.Events, null);

            party.Name.ShouldBe("Destroy the Ring");
        }
Example #11
0
            public StreamAction ToEventStream()
            {
                if (Store.Events.StreamIdentity == StreamIdentity.AsGuid)
                {
                    var stream = StreamAction.Start(StreamId, new AEvent());
                    stream.TenantId = TenantId;

                    return(stream);
                }
                else
                {
                    var stream = StreamAction.Start(StreamId.ToString(), new AEvent());
                    stream.TenantId = TenantId;

                    return(stream);
                }
            }
Example #12
0
        public StreamAction StartStream <TAggregate>(IEnumerable <object> events) where TAggregate : class
        {
            var streamId = Guid.NewGuid();
            var step     = action(e => e.StartStream <TAggregate>(streamId, events));

            if (events.Count() > 3)
            {
                step.Description = $"StartStream<{typeof(TAggregate).FullNameInCode()}>(events)";
            }
            else
            {
                step.Description =
                    $"StartStream<{typeof(TAggregate).FullNameInCode()}>({events.Select(x => x.ToString()).Join(", ")})";
            }

            return(StreamAction.Start(_store.Events, streamId, events));
        }
Example #13
0
        public void ApplyServerVersion_for_new_streams()
        {
            var action = StreamAction.Start(theEvents, Guid.NewGuid(), new AEvent(), new BEvent(), new CEvent(), new DEvent());

            var queue = new Queue<long>();
            queue.Enqueue(11);
            queue.Enqueue(12);
            queue.Enqueue(13);
            queue.Enqueue(14);
            action.PrepareEvents(0, theEvents, queue, theSession);

            action.Events[0].Version.ShouldBe(1);
            action.Events[1].Version.ShouldBe(2);
            action.Events[2].Version.ShouldBe(3);
            action.Events[3].Version.ShouldBe(4);

            action.Events[0].Sequence.ShouldBe(11);
            action.Events[1].Sequence.ShouldBe(12);
            action.Events[2].Sequence.ShouldBe(13);
            action.Events[3].Sequence.ShouldBe(14);
        }
Example #14
0
            public StreamAction StartNewStream(IMartenSessionLogger logger = null)
            {
                var events = new object[] { new AEvent(), new BEvent(), new CEvent(), new DEvent() };

                using var session = Store.Events.TenancyStyle == TenancyStyle.Conjoined
                    ? Store.LightweightSession(TenantId)
                    : Store.LightweightSession();

                session.Listeners.Add(new EventMetadataChecker());

                if (logger != null)
                {
                    session.Logger = logger;
                }

                if (Store.Events.StreamIdentity == StreamIdentity.AsGuid)
                {
                    session.Events.StartStream(StreamId, events);
                    session.SaveChanges();

                    var stream = StreamAction.Append(StreamId);
                    stream.Version  = 4;
                    stream.TenantId = TenantId;

                    return(stream);
                }
                else
                {
                    session.Events.StartStream(StreamId.ToString(), events);
                    session.SaveChanges();

                    var stream = StreamAction.Start(StreamId.ToString(), new AEvent());
                    stream.Version  = 4;
                    stream.TenantId = TenantId;

                    return(stream);
                }
            }
Example #15
0
 public StreamAction ToAction(EventGraph graph)
 {
     return(StreamAction.Start(graph, StreamId, Events.ToArray()));
 }