public void RegisterCustomer_CustomerRegistered()
        {
            IEventStorage eventStorage = new InMemoryEventStorage();
            var           repository   = new Repository <Customer.State>(eventStorage);
            var           useCases     = new CustomerUseCases(repository);

            var stories = Stories.OfUseCases(useCases);

            var customerId  = Guid.NewGuid().ToString();
            var firstName   = "Mohsen";
            var lastName    = "Bazmi";
            var address     = "Customer Address";
            var phoneNumber = "09100000000";
            var command     = new RegisterCustomer(customerId
                                                   , firstName
                                                   , lastName
                                                   , address
                                                   , phoneNumber);
            var expectedEvents = new IDomainEvent[]
            {
                new CustomerRegistered(customerId, firstName, lastName, address, phoneNumber)
            };

//            var envelopedCommand = new CommandEnvelope(MessageChainInfo.Init(), command);
            stories.Tell(command);

            var events = eventStorage
                         .ReadEvents(new Customer.State(customerId).StreamNameForId(customerId))
                         .Result
                         .Select(e => e.Body);

            Assert.Equal(events, expectedEvents);
        }
        public static void Test(IStorySpecification spec, Func <IEventStorage, IUseCase[]> setupUseCases)
        {
            var eventStore = new InMemoryEventStorage();
            var adapter    = new TestAdapter(eventStore, Stories.OfUseCases(setupUseCases(eventStore)));

            adapter.Given(spec.Given);
            adapter.When(spec.When);
            adapter.Then(spec.Then);
        }
Пример #3
0
 public void Setup()
 {
     var scoreCalculator = new SimpleScoreCalculator();
     _scoreQuery = new ScoreQuery(new Mock<ISignaler>().Object, scoreCalculator);
     var eventBus = new DomainBus();
     eventBus.RegisterHandler(() => new GameHandler(_scoreQuery));
     var eventStorage = new InMemoryEventStorage();
     var sessionFactory = new SessionFactory(eventStorage);
     var gameService = new GameService(sessionFactory, eventBus);
     _commandbus = new DomainBus();
     _commandbus.RegisterHandler(() => gameService);
 }
        public void ReadsTheAppendedEvents(string streamName, int version)
        {
            var sut = new InMemoryEventStorage();

            var expectedEvents = CreateManyUntypedEventEnvelopes(10);


            sut.AppendEvents(streamName, version, expectedEvents);

            var actualEvents = sut.ReadEvents(streamName).Result;

            Assert.Equal(expectedEvents, actualEvents);
        }
Пример #5
0
        public void Setup()
        {
            var scoreCalculator = new SimpleScoreCalculator();

            _scoreQuery = new ScoreQuery(new Mock <ISignaler>().Object, scoreCalculator);
            var eventBus = new DomainBus();

            eventBus.RegisterHandler(() => new GameHandler(_scoreQuery));
            var eventStorage   = new InMemoryEventStorage();
            var sessionFactory = new SessionFactory(eventStorage);
            var gameService    = new GameService(sessionFactory, eventBus);

            _commandbus = new DomainBus();
            _commandbus.RegisterHandler(() => gameService);
        }
        public void DoesNotThrowStreamNotFoundException(string writeStreamName, string readStreamName)
        {
            var sut            = new InMemoryEventStorage();
            var expectedEvents = CreateManyUntypedEventEnvelopes(10);

            sut.AppendEvents(writeStreamName
                             , 1
                             , expectedEvents);

            var actualEvents = sut.ReadEvents(readStreamName).Result;

            Assert.Equal(expectedEvents, actualEvents);
//            Assert.ThrowsAsync<InMemoryEventStorage.StreamNotFoundException>(() =>
//                sut.ReadEvents(readStreamName));
        }
Пример #7
0
        public async Task HandlesMultipleEventsOK()
        {
            // SETUP
            var es       = new InMemoryEventStream();
            var eStorage = new InMemoryEventStorage();
            var sStorage = new InMemorySnapShotStorage();
            var buildup  = BuildUp.Initialize(t =>
            {
                t.SetEventStream(es);
                t.SetEventProvider(eStorage);
                t.SetEventStorage(eStorage);
                t.SetSnapshotProvider(sStorage);
                t.SetSnapshotStorage(sStorage);
            });
            var @event = new BuildUpEvent <RandomEvent>
            {
                StreamId = Guid.NewGuid(),
                Data     = new RandomEvent {
                    I = 5
                },
                EventDate = DateTime.UtcNow,
                Version   = 1
            };
            var eventTwo = new BuildUpEvent <RandomEvent>
            {
                StreamId = @event.StreamId,
                Data     = new RandomEvent {
                    I = 72
                },
                EventDate = DateTime.UtcNow,
                Version   = 2
            };

            //ACT
            es.PublishEvent(@event);
            es.PublishEvent(eventTwo);
            es.EndStream();
            Thread.Sleep(25);
            //ASSERT
            var projections = await sStorage.GetSnapshots(@event.StreamId);

            var buildUpSnapshots = projections as IBuildUpSnapshot[] ?? projections.ToArray();

            Assert.Single(buildUpSnapshots);
            var projection = (RandomProjection)buildUpSnapshots.First().Snapshot;

            Assert.Equal(72, projection.I);
        }
Пример #8
0
 public InMemoryQueueStorage(InMemoryEventStorage eventStorage)
 {
     _eventStorage = eventStorage;
 }