Exemplo n.º 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");
        }
Exemplo n.º 2
0
        public void TestToCreateCustomerAndVehicle()
        {
            var aggregateStore = new InMemoryAggregateStore();
            var customerId = Guid.NewGuid();
            var vehicleId = Guid.NewGuid();

            var customer = aggregateStore.GetAggregate<Customer>(customerId);
            var vehicle = aggregateStore.GetAggregate<Vehicle>(vehicleId);

            customer.Create(customerId, "My Customer");
            aggregateStore.Save(customer);

            customer.Id.ShouldBeEquivalentTo(customerId);
            customer.Name.Should().BeEquivalentTo("My Customer");
            aggregateStore.GetAggregate<Customer>(customerId)
                .History.OfType<AggregateEventBag<CustomerCreated>>().Any()
                .Should().BeTrue();

            vehicle.Create(vehicleId, "My Vehicle");
            aggregateStore.Save(vehicle);

            vehicle.Typ.ShouldBeEquivalentTo("My Vehicle");

            aggregateStore.GetAggregate<Vehicle>(vehicleId)
                .History.OfType<AggregateEventBag<VehicleCreated>>().Any()
                .Should().BeTrue();
        }
Exemplo n.º 3
0
        public void TestToCreateCustomerViaAggregate()
        {
            var aggregateStore = new InMemoryAggregateStore();
            var id = Guid.NewGuid();
            var customer = aggregateStore.GetAggregate<Customer>(id);

            customer.Create(id, "My Customer");
            aggregateStore.Save(customer);

            customer.Name.Should().BeEquivalentTo("My Customer");
        }
Exemplo n.º 4
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");
        }
Exemplo n.º 5
0
        public void TestToChangeCustomerName()
        {
            var aggregateStore = new InMemoryAggregateStore();
            var customerId = Guid.NewGuid();

            var customer = aggregateStore.GetAggregate<Customer>(customerId);
            customer.Create(customerId, "My Customer");
            aggregateStore.Save(customer);

            customer.Name.Should().BeEquivalentTo("My Customer");
            customer.Id.ShouldBeEquivalentTo(customerId);

            customer.Change("New Name");
            customer.Name.Should().BeEquivalentTo("New Name");
            aggregateStore.Save(customer);

            customer.Changes.Count().ShouldBeEquivalentTo(0);
            customer.History.Count().ShouldBeEquivalentTo(2);
        }
Exemplo n.º 6
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");
        }
Exemplo n.º 7
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();
        }