Esempio n. 1
0
        public void SimpleStorageTest()
        {
            var streamId            = Guid.NewGuid().ToString();
            var storage             = new TransitionStorage(GetRepository());
            var originalTransitions = new List <Transition> {
                CreatedTransition(streamId, 1),
                CreatedTransition(streamId, 2),
                CreatedTransition(streamId, 3)
            };

            using (var stream = storage.OpenStream(streamId))
            {
                stream.Write(originalTransitions[0]);
                stream.Write(originalTransitions[1]);
                stream.Write(originalTransitions[2]);
            }

            List <Transition> storedTransitions = new List <Transition>();

            using (var stream = storage.OpenStream(streamId))
            {
                foreach (var transition in stream.Read())
                {
                    storedTransitions.Add(transition);
                }
            }

            TransitionAsserter.AssertTransitions(originalTransitions, storedTransitions);

            GetRepository().RemoveStream(streamId);
        }
Esempio n. 2
0
        public void ShouldSaveThreeTransitionsTest()
        {
            var streamId = Guid.NewGuid().ToString();

            var repository = new MongoTransitionRepository(
                new AssemblyQualifiedDataTypeRegistry(),
                Helper.GetConnectionString());

            var events = new List <TransitionEvent> {
                new TransitionEvent(typeof(StreamCreatedEvent).AssemblyQualifiedName, TransitionAsserter.CreatedStreamCreatedEvent(1), null),
                new TransitionEvent(typeof(StreamCreatedEvent).AssemblyQualifiedName, TransitionAsserter.CreatedStreamCreatedEvent(2), null),
                new TransitionEvent(typeof(StreamCreatedEvent).AssemblyQualifiedName, TransitionAsserter.CreatedStreamCreatedEvent(3), null)
            };

            var transitions = new List <Transition> {
                new Transition(new TransitionId(streamId, 1), DateTime.UtcNow, events, null),
                new Transition(new TransitionId(streamId, 2), DateTime.UtcNow, events, null),
                new Transition(new TransitionId(streamId, 3), DateTime.UtcNow, events, null)
            };

            repository.SaveTransition(transitions[0]);
            repository.SaveTransition(transitions[1]);
            repository.SaveTransition(transitions[2]);

            var storedTransitions = repository.GetTransitions(streamId, 0, int.MaxValue);

            TransitionAsserter.AssertTransitions(transitions, storedTransitions);

            repository.RemoveStream(streamId);
        }