public void GetRelationshipBetweenChildAndChild()
        {
            var communicatorParent = new MockParentEventCommunicator();
            var communicatorChild1 = new MockChildEventCommunicator(communicatorParent);
            var communicatorChild2 = new MockChildEventCommunicator(communicatorParent);

            var addressChild1 = new EventCommunicatorAddress(communicatorChild1);
            var addressChild2 = new EventCommunicatorAddress(communicatorChild2);

            var relationshipChild2ToChild1 = addressChild1.RecognizeRelationship(addressChild2);
            var relationshipChild1ToChild2 = addressChild2.RecognizeRelationship(addressChild1);

            Assert.Equal(EventCommunicatorsRelationship.Sibling, relationshipChild2ToChild1);
            Assert.Equal(EventCommunicatorsRelationship.Sibling, relationshipChild1ToChild2);
        }
        public void GetRelationshipBetweenChildAndThreeLevelChildSameBranch()
        {
            var communicatorParent = new MockParentEventCommunicator();
            var communicatorChild1 = new MockChildEventCommunicator(communicatorParent);
            var communicatorChild2 = new MockChildEventCommunicator(communicatorParent);
            var communicatorChild2Child = new MockChildEventCommunicator(communicatorChild2);
            var communicatorChild2ChildChild = new MockChildEventCommunicator(communicatorChild2Child);

            var addressChild1 = new EventCommunicatorAddress(communicatorChild2);
            var addressChild2 = new EventCommunicatorAddress(communicatorChild2ChildChild);

            var relationshipChild2ToChild1 = addressChild1.RecognizeRelationship(addressChild2);
            var relationshipChild1ToChild2 = addressChild2.RecognizeRelationship(addressChild1);

            Assert.Equal(EventCommunicatorsRelationship.Child, relationshipChild2ToChild1);
            Assert.Equal(EventCommunicatorsRelationship.Parent, relationshipChild1ToChild2);
        }
        public void GoodPerformance()
        {
            var communicatorParent = new MockParentEventCommunicator();
            var communicatorChild2 = new MockChildEventCommunicator(communicatorParent);
            var communicatorChild2Child = new MockChildEventCommunicator(communicatorChild2);
            var communicatorChild2ChildChild = new MockChildEventCommunicator(communicatorChild2Child);

            var rootAddr = new EventCommunicatorAddress(communicatorParent);

            var sw = Stopwatch.StartNew();
            for (int i = 0; i < 10000; i++)
            {
                var addr = new EventCommunicatorAddress(communicatorChild2ChildChild);
                var relToRoot = addr.RecognizeRelationship(rootAddr);
                var relFromRoot = rootAddr.RecognizeRelationship(addr);
            }
            sw.Stop();
            Assert.True(sw.ElapsedMilliseconds < 150);
        }
        public void GetRelationshipBetweenSameCommunicators()
        {
            var communicator = new MockParentEventCommunicator();

            var address = new EventCommunicatorAddress(communicator);

            var relationship = address.RecognizeRelationship(address);

            Assert.Equal(EventCommunicatorsRelationship.Same, relationship);
        }
        public void GetRelationshipBetweenParentAndChildClosest()
        {
            var communicatorParent = new MockParentEventCommunicator();
            var communicatorChild = new MockChildEventCommunicator(communicatorParent);

            var addressParent = new EventCommunicatorAddress(communicatorParent);
            var addressChild = new EventCommunicatorAddress(communicatorChild);

            var relationshipChildToParent = addressParent.RecognizeRelationship(addressChild);
            var relationshipParentToChild = addressChild.RecognizeRelationship(addressParent);

            Assert.Equal(EventCommunicatorsRelationship.ClosestChild | EventCommunicatorsRelationship.Child, relationshipChildToParent);
            Assert.Equal(EventCommunicatorsRelationship.Parent | EventCommunicatorsRelationship.ClosestParent, relationshipParentToChild);
        }
        public void GetRelationshipBetweenNullCommunicator()
        {
            var communicator = new MockParentEventCommunicator();

            var address = new EventCommunicatorAddress(communicator);

            Assert.Throws<ArgumentNullException>(() =>
            {
                var tmp = address.RecognizeRelationship(null);
            });
        }
        public void GetRelationshipBetweenNotRelatedCommunicators()
        {
            var communicatorParent1 = new MockParentEventCommunicator();
            var communicatorParent2 = new MockParentEventCommunicator();

            var addressParent1 = new EventCommunicatorAddress(communicatorParent1);
            var addressParent2 = new EventCommunicatorAddress(communicatorParent2);

            var relationshipParent2ToParent1 = addressParent1.RecognizeRelationship(addressParent2);
            var relationshipParent1ToParent2 = addressParent2.RecognizeRelationship(addressParent1);

            Assert.Equal(EventCommunicatorsRelationship.Other, relationshipParent2ToParent1);
            Assert.Equal(EventCommunicatorsRelationship.Other, relationshipParent1ToParent2);
        }
        public void GetRelationshipBetweenChildAndTwoLevelChildOtherBranch()
        {
            var communicatorParent1 = new MockParentEventCommunicator();
            var communicatorParent2 = new MockParentEventCommunicator();
            var communicatorChild1 = new MockChildEventCommunicator(communicatorParent1);
            var communicatorChild2 = new MockChildEventCommunicator(communicatorParent2);
            var communicatorChild2Child = new MockChildEventCommunicator(communicatorChild2);

            var addressChild1 = new EventCommunicatorAddress(communicatorChild1);
            var addressChild2 = new EventCommunicatorAddress(communicatorChild2Child);

            var relationshipChild2ToChild1 = addressChild1.RecognizeRelationship(addressChild2);
            var relationshipChild1ToChild2 = addressChild2.RecognizeRelationship(addressChild1);

            Assert.Equal(EventCommunicatorsRelationship.Other, relationshipChild2ToChild1);
            Assert.Equal(EventCommunicatorsRelationship.Other, relationshipChild1ToChild2);
        }