public void Equals_should_call_equals_of_state() { var dateTime = DateTime.UtcNow; var parentId = "parent1"; var childId = "child1"; var parentState = new ParentState().Apply(new ParentCreated(parentId, "test parent", dateTime)); var childState = new ChildState().Apply(new ChildCreated(parentId, childId, "test child", dateTime)) .Apply(new ChildRenamed(parentId, childId, "test child renamed", dateTime)); parentState.AsIAggregateRootStateInternal().AddChildState(childState); var parent = new ParentEntity(Array.Empty <IEvent>(), parentState); parent.FixDateTime(dateTime); var child = parent.GetChildEntity <ChildEntity>(childId); child.Equals(child.StateModel).Should().Be(true); var child2 = parent.GetChildEntity <ChildEntity>(childId); ReferenceEquals(child, child2).Should().Be(false); child.Equals(child2).Should().Be(true); child.Equals(null).Should().Be(false); }
public void Can_add_child_entity_to_parent_entity_per_initial_state() { var dateTime = DateTime.UtcNow; var parentId = "parent1"; var childId = "child1"; var parentState = new ParentState().Apply(new ParentCreated(parentId, "test parent", dateTime)); var childState = new ChildState().Apply(new ChildCreated(parentId, childId, "test child", dateTime)) .Apply(new ChildRenamed(parentId, childId, "test child renamed", dateTime)); parentState.AsIAggregateRootStateInternal().AddChildState(childState); var parent = new ParentEntity(Array.Empty <IEvent>(), parentState); parent.FixDateTime(dateTime); var child = parent.GetChildEntity <ChildEntity>(childId); 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 GetHashCode_should_be_the_state_hashcode() { var dateTime = DateTime.UtcNow; var parentId = "parent1"; var childId = "child1"; var parentState = new ParentState().Apply(new ParentCreated(parentId, "test parent", dateTime)); var childState = new ChildState().Apply(new ChildCreated(parentId, childId, "test child", dateTime)) .Apply(new ChildRenamed(parentId, childId, "test child renamed", dateTime)); parentState.AsIAggregateRootStateInternal().AddChildState(childState); var parent = new ParentEntity(Array.Empty <IEvent>(), parentState); parent.FixDateTime(dateTime); var child = parent.GetChildEntity <ChildEntity>(childId); child.GetHashCode().Should().Be(child.StateModel.GetHashCode()); }