Пример #1
0
        public void GivenEventStoreWithEvents_WhenQueried_ThenQueriedSuccessful()
        {
            Guid userId = Guid.NewGuid();

            //Given
            Sut.Store(userId,
                      new UserCreated {
                UserId = userId, UserName = "******"
            },
                      new UserUpdated {
                UserId = userId, UserName = "******"
            }
                      );

            Guid secondUserId = Guid.NewGuid();

            Sut.Store(secondUserId,
                      new UserCreated {
                UserId = secondUserId, UserName = "******"
            }
                      );

            Sut.SaveChanges();

            //When
            Sut.Query().OfType <UserCreated>().ToList().Should().HaveCount(2);
            Sut.Query <UserCreated>().ToList().Should().HaveCount(2);

            Sut.Query(userId).ToList().Should().HaveCount(2);
            Sut.Query(userId).OfType <UserUpdated>().ToList().Should().HaveCount(1);
        }
Пример #2
0
        public void Test()
        {
            var userId     = Guid.NewGuid();
            var schemaName = GenerateSchemaName();

            using (var uow = new TransactionScopeUnitOfWork())
            {
                uow.Begin();

                using (var session = CreateSession(opt => opt.Events.DatabaseSchemaName = opt.DatabaseSchemaName = schemaName))
                {
                    var eventStore = new MartenEventStore(session);
                    //Given
                    eventStore.Store(userId,
                                     new UserCreated {
                        UserId = userId, UserName = "******"
                    }
                                     );

                    eventStore.SaveChanges();

                    //When
                    eventStore.Query().OfType <UserCreated>().ToList().Should().HaveCount(1);
                }
            }

            using (var session = CreateSession(opt => opt.Events.DatabaseSchemaName = opt.DatabaseSchemaName = schemaName))
            {
                //Given
                var eventStore = new MartenEventStore(session);

                //When
                eventStore.Query().OfType <UserCreated>().ToList().Should().HaveCount(0);
            }
        }