Beispiel #1
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();
        }
Beispiel #2
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");
        }
Beispiel #3
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);
        }