Ejemplo n.º 1
0
 public void Apply(QuestStarted started)
 {
     Name = started.Name;
 }
Ejemplo n.º 2
0
        public void open_persisted_stream_in_new_store_with_same_settings(TenancyStyle tenancyStyle, string[] tenants)
        {
            var store   = InitStore(tenancyStyle);
            var questId = Guid.NewGuid();

            When.CalledForEach(tenants, (tenantId, index) =>
            {
                using (var session = store.OpenSession(tenantId, DocumentTracking.None))
                {
                    //Note "Id = questId" @see live_aggregate_equals_inlined_aggregate...
                    var started = new QuestStarted {
                        Id = questId, Name = "Destroy the One Ring"
                    };
                    var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry");

                    session.Events.StartStream <Quest>(questId, started, joined1);
                    session.SaveChanges();
                }

                // events-aggregate-on-the-fly - works with same store
                using (var session = store.OpenSession(tenantId, DocumentTracking.None))
                {
                    // questId is the id of the stream
                    var party = session.Events.AggregateStream <QuestParty>(questId);

                    party.Id.ShouldBe(questId);
                    party.ShouldNotBeNull();

                    var party_at_version_3 = session.Events
                                             .AggregateStream <QuestParty>(questId, 3);

                    party_at_version_3.ShouldNotBeNull();

                    var party_yesterday = session.Events
                                          .AggregateStream <QuestParty>(questId, timestamp: DateTimeOffset.UtcNow.AddDays(-1));
                    party_yesterday.ShouldBeNull();
                }

                using (var session = store.OpenSession(tenantId, DocumentTracking.None))
                {
                    var party = session.Load <QuestParty>(questId);
                    party.Id.ShouldBe(questId);
                }

                var newStore = InitStore(tenancyStyle, false);

                //Inline is working
                using (var session = store.OpenSession(tenantId, DocumentTracking.None))
                {
                    var party = session.Load <QuestParty>(questId);
                    SpecificationExtensions.ShouldNotBeNull(party);
                }
                //GetAll
                using (var session = store.OpenSession(tenantId, DocumentTracking.None))
                {
                    var parties = session.Events.QueryRawEventDataOnly <QuestParty>().ToArray();
                    foreach (var party in parties)
                    {
                        SpecificationExtensions.ShouldNotBeNull(party);
                    }
                }
                //This AggregateStream fail with NPE
                using (var session = store.OpenSession(tenantId, DocumentTracking.None))
                {
                    // questId is the id of the stream
                    var party = session.Events.AggregateStream <QuestParty>(questId);//Here we get NPE
                    party.Id.ShouldBe(questId);

                    var party_at_version_3 = session.Events
                                             .AggregateStream <QuestParty>(questId, 3);
                    party_at_version_3.Id.ShouldBe(questId);

                    var party_yesterday = session.Events
                                          .AggregateStream <QuestParty>(questId, timestamp: DateTimeOffset.UtcNow.AddDays(-1));
                    party_yesterday.ShouldBeNull();
                }
            }).ShouldThrowIf(
                (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants))
                );
        }
Ejemplo n.º 3
0
        public void open_persisted_stream_in_new_store_with_same_settings()
        {
            var questId = "Sixth";

            using (var session = theStore.LightweightSession())
            {
                //Note "Id = questId" @see live_aggregate_equals_inlined_aggregate...
                var started = new QuestStarted {
                    Name = "Destroy the One Ring"
                };
                var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry");

                session.Events.StartStream <Quest>(questId, started, joined1);
                session.SaveChanges();
            }

            // events-aggregate-on-the-fly - works with same store
            using (var session = theStore.LightweightSession())
            {
                // questId is the id of the stream
                var party = session.Events.AggregateStream <QuestPartyWithStringIdentifier>(questId);

                party.ShouldNotBeNull();

                var party_at_version_3 = session.Events
                                         .AggregateStream <QuestPartyWithStringIdentifier>(questId, 3);

                party_at_version_3.ShouldNotBeNull();

                var party_yesterday = session.Events
                                      .AggregateStream <QuestPartyWithStringIdentifier>(questId, timestamp: DateTime.UtcNow.AddDays(-1));
                party_yesterday.ShouldBeNull();
            }

            using (var session = theStore.LightweightSession())
            {
                var party = session.Load <QuestPartyWithStringIdentifier>(questId);
                SpecificationExtensions.ShouldNotBeNull(party);
            }

            var newStore = new DocumentStore(theStore.Options);

            //Inline is working
            using (var session = newStore.LightweightSession())
            {
                var party = session.Load <QuestPartyWithStringIdentifier>(questId);
                party.ShouldNotBeNull();
            }
            //GetAll
            using (var session = theStore.LightweightSession())
            {
                var parties = session.Events.QueryRawEventDataOnly <QuestPartyWithStringIdentifier>().ToArray();
                foreach (var party in parties)
                {
                    party.ShouldNotBeNull();
                }
            }
            //This AggregateStream fail with NPE
            using (var session = newStore.LightweightSession())
            {
                // questId is the id of the stream
                var party = session.Events.AggregateStream <QuestPartyWithStringIdentifier>(questId);//Here we get NPE
                party.ShouldNotBeNull();

                var party_at_version_3 = session.Events
                                         .AggregateStream <QuestPartyWithStringIdentifier>(questId, 3);
                party_at_version_3.ShouldNotBeNull();

                var party_yesterday = session.Events
                                      .AggregateStream <QuestPartyWithStringIdentifier>(questId, timestamp: DateTime.UtcNow.AddDays(-1));
                party_yesterday.ShouldBeNull();
            }
        }