public void Should_be_able_to_remove_an_existing_event_stream()
        {
            IEventStore store = new EventStore();
            var aggregate = new Aggregate(Guid.NewGuid());
            var eventStream = store.Get(aggregate.Id);

            for (var i = 0; i < 100000; i++)
            {
                var moveCommand = new MoveCommand
                {
                    Address = string.Format("Address-{0}", i),
                    DateMoved = DateTime.Now
                };

                eventStream.AddEvent(aggregate.Move(moveCommand));

                if (eventStream.ShouldSnapshot(100))
                {
                    eventStream.AddSnapshot(aggregate.State);
                }
            }

            store.SaveEventStream(eventStream);

            eventStream = store.Get(aggregate.Id);

            Assert.IsFalse(eventStream.IsEmpty);

            store.Remove(aggregate.Id);

            eventStream = store.Get(aggregate.Id);

            Assert.IsTrue(eventStream.IsEmpty);
        }
        public void Should_be_able_to_use_event_stream()
        {
            IEventStore store = new EventStore();
            var aggregate = new Aggregate(Guid.NewGuid());
            var eventStream = store.Get(aggregate.Id);

            var moveCommand = new MoveCommand();

            for (var i = 0; i < 100000; i++)
            {
                moveCommand = new MoveCommand
                {
                    Address = string.Format("Address-{0}", i),
                    DateMoved = DateTime.Now
                };

                eventStream.AddEvent(aggregate.Move(moveCommand));
            }

            store.SaveEventStream(eventStream);

            aggregate = new Aggregate(aggregate.Id);
            eventStream = store.Get(aggregate.Id);

            eventStream.Apply(aggregate);

            Assert.AreEqual(moveCommand.Address, aggregate.State.Location.Address);
            Assert.AreEqual(moveCommand.DateMoved, aggregate.State.Location.DateMoved);
        }
Пример #3
0
		public MovedEvent Move(MoveCommand command)
		{
			var movedEvent = new MovedEvent
			{
				Address = command.Address,
				DateMoved = command.DateMoved
			};

			On(movedEvent);

			return movedEvent;
		}