public void AggregateRootReplayEventsTest() { Given("a Customer AggregateRoot", context => { var customer = new Customer { Name = "Mister X" }; context.State.Customer = customer; var address = new Address(customer, Uuid.NewId()) { Street = "Berliner Allee" }; context.State.Address = address; }) .When("a list of 3 events was replayed", context => ((Customer)context.State.Customer).ReplayEvents(new List <DomainEvent> { new CustomerCreated { Name = "Hans Wurst" }, new AddressStreetChanged { Street = "Industriestraße", EntityId = context.State.Address.Id }, new CustomerNameChanged { Name = "Karl Obst" } })) .Then("the Customer AggregateRoot should have the Name property set to the same of the last domain event", context => (((Customer)context.State.Customer).Name == "Karl Obst")); }
public void WennIchDieSnapshotentitatInDenMySqlSnapshotStoreSpeichere() { var id = Uuid.NewId(); ScenarioContext.Current.Set(id); var store = ScenarioContext.Current.Get <ISnapshotStore>(); var customer = ScenarioContext.Current.Get <Customer>(); store.SaveSnapshot(new Snapshot <Customer>(id, 0, customer)); }
public void Two_Uuids_initialized_by_NewId_are_different() { Given("a first Uuid initialized with 'NewId'", context => context.State.uuid1 = Uuid.NewId()) .And("a second Uuid initialized with 'NewId'", context => context.State.uuid2 = Uuid.NewId()) .When("both Uuids will be compared", context => context.State.result = (((Uuid)context.State.uuid1) == ((Uuid)context.State.uuid2))) .Then("they should be different", context => !context.State.result); }
public void GetById_returns_the_right_aggregate_with_the_defined_Id_and_type() { Given("a set of events with different aggregate ids in an event store", testContext => { var aggregateId = Uuid.NewId(); testContext.State.AggregateId = aggregateId; var eventStore = new InMemoryEventStore(); eventStore.Insert(aggregateId, "Customer", new List <DomainEvent> { new CustomerCreated(), new CustomerNameChanged() }); eventStore.Insert(aggregateId, "Customer", new List <DomainEvent> { new AddressStreetChanged() }); eventStore.Insert(Uuid.NewId(), "Customer", new List <DomainEvent> { new CustomerCreated() }); eventStore.Insert(Uuid.NewId(), "Customer", new List <DomainEvent> { new CustomerCreated() }); testContext.State.EventStore = eventStore; }) .And("an empty snapshot store", testContext => { testContext.State.SnapshotStore = new InMemorySnapshotStore(); }) .And("a configured domain context", testContext => { var eventBus = new Mock <IEventBus>().Object; IEventStore eventStore = testContext.State.EventStore; ISnapshotStore snapshotStore = testContext.State.SnapshotStore; var domainRepository = new DomainRepository(eventStore, snapshotStore); var domainContext = new DomainContext(eventBus, eventStore, snapshotStore, domainRepository); testContext.State.DomainContext = domainContext; }) .When("GetById for a defined aggregate type with and events contained in the event store with the defined aggregate id is called", testContext => { var aggregate = ((DomainContext)testContext.State.DomainContext).GetById <Customer>( testContext.State.AggregateId); testContext.State.Aggregate = aggregate; }) .Then("it should return a valid aggregate", testContext => { object obj = testContext.State.Aggregate; obj.Should().NotBeNull(); obj.Should().BeOfType <Customer>(); }); }
public void GetById_returns_no_aggregate_with_a_different_ID_than_defined() { Given("a set of events with different aggregate ids in an event store", testContext => { var eventStore = new InMemoryEventStore(); eventStore.Insert(Uuid.NewId(), "Customer", new List <DomainEvent> { new CustomerCreated(), new CustomerNameChanged() }); eventStore.Insert(Uuid.NewId(), "Customer", new List <DomainEvent> { new CustomerCreated() }); eventStore.Insert(Uuid.NewId(), "Customer", new List <DomainEvent> { new CustomerCreated() }); testContext.State.EventStore = eventStore; }) .And("an empty snapshot store", testContext => { testContext.State.SnapshotStore = new InMemorySnapshotStore(); }) .And("a configured domain context", testContext => { var eventBus = new Mock <IEventBus>().Object; IEventStore eventStore = testContext.State.EventStore; ISnapshotStore snapshotStore = testContext.State.SnapshotStore; var domainRepository = new DomainRepository(eventStore, snapshotStore); var domainContext = new DomainContext(eventBus, eventStore, snapshotStore, domainRepository); testContext.State.DomainContext = domainContext; }) .When("GetById for an aggregate with unknown id is called", testContext => { var aggregate = ((DomainContext)testContext.State.DomainContext).GetById <Customer>(Uuid.NewId()); testContext.State.Aggregate = aggregate; }) .Then("it should return null", testContext => { object obj = testContext.State.Aggregate; obj.Should().BeNull(); }); }
public void AngenommenEineDefinierteAggregat_ID() { ScenarioContext.Current.Set(Uuid.NewId()); }
/// <summary> /// Creates a new aggregate root with a new ID /// </summary> protected AggregateRoot() : this(Uuid.NewId()) { }