示例#1
0
        public void LoadFromSnapshotTest1()
        {
            var aggregateRootId       = Guid.NewGuid();
            var employee              = new Employee(aggregateRootId);
            var localSnapshotProvider = new InMemorySnapshotProvider();
            var localRepository       = new EventSourcingDomainRepository(eventStore, eventPublisher, localSnapshotProvider);

            for (var i = 0; i < 31; i++)
            {
                employee.ChangeName($"daxnet_{i}");
            }
            localRepository.Save <Guid, Employee>(employee);

            var employee2 = localRepository.GetById <Guid, Employee>(aggregateRootId);

            Assert.Equal(employee.Name, employee2.Name);
        }
        public void LoadAggregateRootTest()
        {
            using (var eventPublisher = new EventBus(connectionFactory, messageSerializer, this.GetType().Name))
                using (var eventStore = new PostgreSqlEventStore(new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()), eventStoreSerializer))
                    using (var repository = new EventSourcingDomainRepository(eventStore, eventPublisher, snapshotProvider))
                    {
                        var aggregateRootId = Guid.NewGuid();
                        var employee        = new Employee(aggregateRootId);
                        employee.ChangeName("daxnet");
                        employee.ChangeTitle("developer");
                        repository.Save <Guid, Employee>(employee);

                        var employee2 = repository.GetById <Guid, Employee>(aggregateRootId);
                        Assert.Equal("daxnet", employee2.Name);
                        Assert.Equal("Sr. developer", employee2.Title);
                        Assert.Equal(3, employee2.Version);
                    }
        }
        public void GetByVersionTest1()
        {
            using (var eventPublisher = new EventBus(connectionFactory, messageSerializer, this.GetType().Name))
                using (var eventStore = new PostgreSqlEventStore(new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()), eventStoreSerializer))
                    using (var repository = new EventSourcingDomainRepository(eventStore, eventPublisher, snapshotProvider))
                    {
                        var aggregateRootId = Guid.NewGuid();
                        var employee        = new Employee(aggregateRootId);
                        employee.ChangeName("daxnet");
                        employee.ChangeTitle("developer");
                        employee.Register();
                        repository.Save <Guid, Employee>(employee);

                        var employee2 = repository.GetById <Guid, Employee>(aggregateRootId, 2); // Load 2 events as the first one is the aggregate created event.
                        Assert.Equal(employee.Name, employee2.Name);
                        Assert.Null(employee2.Title);
                        Assert.Equal(DateTime.MinValue, employee2.DateRegistered);
                    }
        }
        public void GetByVersionTest2()
        {
            var serviceCollection = new ServiceCollection();
            var executionContext  = new ServiceProviderMessageHandlerExecutionContext(serviceCollection);

            using (var eventPublisher = new RabbitEventBus(connectionFactory, messageSerializer, executionContext, this.GetType().Name))
                using (var eventStore = new PostgreSqlEventStore(new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()), eventStoreSerializer))
                    using (var repository = new EventSourcingDomainRepository(eventStore, eventPublisher, snapshotProvider))
                    {
                        var aggregateRootId = Guid.NewGuid();
                        var employee        = new Employee(aggregateRootId);
                        employee.ChangeName("daxnet");
                        employee.ChangeTitle("developer");
                        employee.Register();
                        repository.Save <Guid, Employee>(employee);

                        var employee2 = repository.GetById <Guid, Employee>(aggregateRootId, 3);
                        Assert.Equal(employee.Name, employee2.Name);
                        Assert.Equal(employee.Title, employee2.Title);
                        Assert.Equal(DateTime.MinValue, employee2.DateRegistered);
                    }
        }