Exemple #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");
            });
        }
Exemple #2
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);
            });
        }
Exemple #3
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);
            }
        }
        public void ItShouldWriteEventsProperly()
        {
            var eventStoreConnection = EventStoreConnection.Create();
            eventStoreConnection.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1113));

            var getEventStore = new GetEventStore(eventStoreConnection);

            var testAggregate = new TestAggregate() {Id = Guid.NewGuid()};
            getEventStore.SaveEventsFor<TestAggregate>(testAggregate.Id, ExpectedVersion.Any, new List<Event>(){new Tested(Guid.NewGuid()){Prop = 1}});

            var readEvents = getEventStore.LoadEventsFor<TestAggregate>(testAggregate.Id);

            Assert.AreEqual(1, readEvents.Count());

            var resolvedEvent = readEvents.First();
            Assert.AreEqual(1, ((Tested) resolvedEvent).Prop);
        }
Exemple #5
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));
                }
            });
        }
        Import_test_data_for_temporal_queries_and_projections_example_in_the_book()
        {
            using (var con = EventStoreConnection.Create(connectionString))
            {
                await con.ConnectAsync();

                var es   = new GetEventStore(con);
                var repo = new PayAsYouGoRepository(es);

                Create5EmptyAccounts();

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

                await PersistAllUncommittedEvents(repo);
            }
        }
Exemple #7
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);
            });
        }