コード例 #1
0
        public void Optimistic_concurrency_is_supported()
        {
            NewConnection(con =>
            {
                var eventStore = new GetEventStore(con);
                var streamName = CreateDisposableStreamName();

                // version number will be 2 (3 events, 0 based)
                eventStore.AppendEventsToStream(streamName, testEvents, null);

                var newEvnt = new TestEvent(Guid.NewGuid())
                {
                    Handle = "New",
                    Name   = "Newnew"
                };

                try
                {
                    var expectedVersion = 1; // we know the version is already 2
                    eventStore.AppendEventsToStream(streamName, new List <TestEvent> {
                        newEvnt
                    }, expectedVersion);
                }
                catch (AggregateException e)
                {
                    var extype = e.InnerExceptions.First().GetType();
                    Assert.AreEqual(typeof(WrongExpectedVersionException), extype);
                    return;
                }

                Assert.Fail("Optimistic concurrency violation was not detected");
            });
        }
コード例 #2
0
        public void Snapshots_are_persisted_and_the_latest_one_is_always_returned()
        {
            NewConnection(con =>
            {
                var eventStore = new GetEventStore(con);
                var streamName = CreateDisposableStreamName();

                var snapshot1 = new TestSnapshot {
                    Version = 1
                };
                var snapshot2 = new TestSnapshot {
                    Version = 2
                };
                var snapshot3 = new TestSnapshot {
                    Version = 3
                };

                eventStore.AddSnapshot <TestSnapshot>(streamName, snapshot1);
                eventStore.AddSnapshot <TestSnapshot>(streamName, snapshot2);
                eventStore.AddSnapshot <TestSnapshot>(streamName, snapshot3);

                var fromEs = eventStore.GetLatestSnapshot <TestSnapshot>(streamName);

                Assert.AreEqual(snapshot3, fromEs);
            });
        }
コード例 #3
0
        public void A_subset_of_events_can_be_retrieved_by_querying_on_version_numbers()
        {
            NewConnection(con =>
            {
                var eventStore = new GetEventStore(con);
                var streamName = CreateDisposableStreamName();
                eventStore.AppendEventsToStream(streamName, testEvents, null);

                var fromEs = eventStore.GetStream(streamName, 1, 1);

                Assert.AreEqual(1, fromEs.Count());
                Assert.AreEqual("Trevor", ((TestEvent)fromEs.Single()).Handle);
            });
        }
コード例 #4
0
        public void Events_are_persisted_and_can_be_retrieved()
        {
            NewConnection(con =>
            {
                var eventStore = new GetEventStore(con);
                var streamName = CreateDisposableStreamName();
                eventStore.AppendEventsToStream(streamName, testEvents, null);

                var fromEs = eventStore.GetStream(streamName, 0, Int32.MaxValue - 1);

                Assert.AreEqual(fromEs.Count(), testEvents.Count());
                foreach (var e in testEvents)
                {
                    Assert.IsTrue(fromEs.Contains(e));
                }
            });
        }
コード例 #5
0
        public void Import_test_data_for_temporal_queries_and_projections_example_in_the_book()
        {
            using (var con = EventStoreConnection.Create(endpoint))
            {
                con.Connect();
                var es   = new GetEventStore(con);
                var repo = new PayAsYouGoAccountRepository(es);

                Create5EmptyAccounts();

                SimulateCustomerActivityFor3rdJune();
                SimulateCustomerActivityFor4thJune();
                SimulateCustomerActivityFor5thJune();

                PersistAllUncommittedEvents(repo);
            }
        }