コード例 #1
0
        public void TestToCreateTwoCustomerAndChangeOneOfThem()
        {
            var aggregateStore = new InMemoryAggregateStore();
            var modelsStore = new InMemoryReadModel();

            var reciever = new CustomerCommandsHandler(aggregateStore);
            var queries = new CustomerQueriesHandler(modelsStore);

            var api = new CustomerApi(reciever, queries);

            var id1 = Guid.NewGuid();
            var id2 = Guid.NewGuid();

            api.Process(new CreateCustomer { Id = id1, Name = "Customer One" });
            api.Process(new CreateCustomer { Id = id2, Name = "Customer Two" });

            api.Process(new ChangeCustomer { Id = id2, Name = "Customer Two Changed" });

            var customer = api.Retrieve<CustomerModel>(new GetCustomer
            {
                Id = id2
            });

            customer.Name.ShouldBeEquivalentTo("Customer Two Changed");
        }
コード例 #2
0
        public void TestToCreateCustomerAndReadIt()
        {
            var aggregateStore = new InMemoryAggregateStore();
            var readModel = new InMemoryReadModel();

            var commands = new CustomerCommandsHandler(aggregateStore);
            var queries = new CustomerQueriesHandler(readModel);

            var api = new CustomerApi(commands, queries);
            var id = Guid.NewGuid();

            api.Process(new CreateCustomer{Id = id, Name = "My Customer"});

            var customerModel = api.Retrieve<CustomerModel>(new GetCustomer {Id = id});

            customerModel.Name.ShouldBeEquivalentTo("My Customer");
        }
コード例 #3
0
        public void TestToCreateAndChangeKundeViaApi()
        {
            var aggregateStore = new InMemoryAggregateStore();
            var queriesStore = new InMemoryReadModel();

            var reciever = new CustomerCommandsHandler(aggregateStore);
            var queries = new CustomerQueriesHandler(queriesStore);

            var api = new CustomerApi(reciever, queries);
            var id = Guid.NewGuid();

            api.Process(new CreateCustomer { Id = id, Name = "My Customer" });
            api.Process(new ChangeCustomer { Id = id, Name = "New Name" });

            var customer = api.Retrieve<CustomerModel>(new GetCustomer
                {
                    Id = id
                });

            customer.Name.ShouldBeEquivalentTo("New Name");
        }
コード例 #4
0
        public void TestToRemoveACustomer()
        {
            var aggregateStore = new InMemoryAggregateStore();
            var modelsStore = new InMemoryReadModel();

            var reciever = new CustomerCommandsHandler(aggregateStore);
            var queries = new CustomerQueriesHandler(modelsStore);

            var api = new CustomerApi(reciever, queries);

            var id = Guid.NewGuid();

            api.Process(new CreateCustomer { Id = id, Name = "Customer To Remove" });

            var customer = api.Retrieve<CustomerModel>(new GetCustomer
            {
                Id = id
            });

            customer.Should().NotBeNull();

            api.Process(new RemoveCustomer { Id = id });

            customer = api.Retrieve<CustomerModel>(new GetCustomer
            {
                Id = id
            });

            customer.Should().BeNull();
        }