public void Can_add_child_entity_to_parent_entity() { var dateTime = DateTime.UtcNow; var parent = new ParentEntity(ParentEntityId.Generate(), "test parent"); var child = new ChildEntity(parent, Guid.NewGuid().ToString(), "test child"); child.Rename("test child renamed"); parent.FixDateTime(dateTime); var createdEvents = parent.AsIEventSourcedEntity().UncommittedEvents.ToList(); createdEvents[0].Should().Be(new ParentCreated(parent.Id, "test parent", dateTime)); createdEvents[1].Should().Be(new ChildCreated(parent.Id, child.Id, "test child", dateTime)); createdEvents[2].Should().Be(new ChildRenamed(parent.Id, child.Id, "test child renamed", dateTime)); child.StateModel.Id.Should().Be(child.Id); child.StateModel.Name.Should().Be("test child renamed"); var childStates = parent.StateModel.ChildStates.ToList(); childStates[0].Should().Be(child.StateModel); (childStates[0] as ChildState).Name.Should().Be("test child renamed"); }
public void SetAggregateRoot_cannot_be_used_twice() { var child = new ChildEntity(); ((IChildEntityInternal)child).SetAggregateRoot(new ParentEntity(ParentEntityId.Generate(), "name"), ChildEntityId.Generate()); ((Action)(() => ((IChildEntityInternal)child).SetAggregateRoot(new ParentEntity(ParentEntityId.Generate(), "name"), ChildEntityId.Generate()))).Should().Throw <InvalidOperationException>() .And.Message.Should().Be("AggregateRoot cannot be reassigned in ChildEntity!"); }