Exemple #1
0
 internal static void VerifyCollectionIsNotNull(IDirectedConnectedNodeCollection <T> collection)
 {
     if (collection == null)
     {
         throw new ArgumentNullException("collection", "Operation is not valid on a null set of nodes.");
     }
 }
Exemple #2
0
        void IDirectedConnectedNode <T> .AddToCollection(IDirectedConnectedNodeCollection <T> newParentCollection)
        {
            Helpers <T> .Verify_AddToCollection_ConditionsAreSatisfied(this, newParentCollection);

            var typedCollection = TypedHelpers.GetCollectionAsValidType <PointerDCNC <T>, T>(newParentCollection);

            typedCollection.InternalAddNodeRequest(this);
            this.InternalSetParentCollectionRequest(typedCollection);
        }
Exemple #3
0
 internal static void VerifyAtLeastOneNodeIsInCollection(
     IDirectedConnectedNode <T> firstNode,
     IDirectedConnectedNode <T> secondNode,
     IDirectedConnectedNodeCollection <T> collection)
 {
     if (NodeIsNotInCollection(firstNode, collection) && NodeIsNotInCollection(secondNode, collection))
     {
         throw new InvalidOperationException("Cannot report on connection between two nodes not in collection.");
     }
 }
Exemple #4
0
            public void InputOfWrongTypeThrows()
            {
                var arrayCollection = IDCNCFactory.NewArrayCollection <int>();
                IDirectedConnectedNodeCollection <int> deTypedArrayCollection = arrayCollection;

                Assert.Throws <InvalidCastException>(
                    () => TypedHelpers.GetCollectionAsValidType <PointerDCNC <int>, int>(deTypedArrayCollection));

                var pointerCollection = IDCNCFactory.NewPointerCollection <string>();
                IDirectedConnectedNodeCollection <string> deTypedPointerCollection = pointerCollection;

                Assert.Throws <InvalidCastException>(
                    () => TypedHelpers.GetCollectionAsValidType <ArrayDCNC <string>, string>(deTypedPointerCollection));
            }
Exemple #5
0
            public void OutputIsOfExpectedType()
            {
                var arrayCollection = IDCNCFactory.NewArrayCollection <int>();
                IDirectedConnectedNodeCollection <int> deTypedArrayCollection = arrayCollection;
                var hopefullyArrayOutput = TypedHelpers.GetCollectionAsValidType <ArrayDCNC <int>, int>(deTypedArrayCollection);

                Assert.IsTrue(hopefullyArrayOutput is ArrayDCNC <int>);

                var pointerCollection = IDCNCFactory.NewPointerCollection <string>();
                IDirectedConnectedNodeCollection <string> deTypedPointerCollection = pointerCollection;
                var hopefullyPointerOutput = TypedHelpers.GetCollectionAsValidType <PointerDCNC <string>, string>(deTypedPointerCollection);

                Assert.IsTrue(hopefullyPointerOutput is PointerDCNC <string>);
            }
Exemple #6
0
        internal static S GetCollectionAsValidType <S, T>(IDirectedConnectedNodeCollection <T> collection) where S : class, IDirectedConnectedNodeCollection <T>
        {
            if (collection == null)
            {
                return(null);
            }

            var typedCollection = collection as S;

            if (typedCollection == null)
            {
                throw new InvalidCastException($"Given collection is not a '{typeof(S)}' collection. Collection Type is actually: '{collection.GetType()}'");
            }

            return(typedCollection);
        }
Exemple #7
0
 private static bool NodeIsNotInCollection(IDirectedConnectedNode <T> node, IDirectedConnectedNodeCollection <T> collection)
 {
     return(node.ParentCollection != collection);
 }
Exemple #8
0
 internal static void VerifyNodeIsInCollection(IDirectedConnectedNode <T> node, IDirectedConnectedNodeCollection <T> collection)
 {
     if (NodeIsNotInCollection(node, collection))
     {
         throw new InvalidOperationException("Operation is not valid on a node in a different Collection.");
     }
 }
Exemple #9
0
        internal static bool CheckNodesHaveConnectionConditions(IDirectedConnectedNode <T> firstNode, IDirectedConnectedNode <T> secondNode, IDirectedConnectedNodeCollection <T> collection)
        {
            if (firstNode == null || secondNode == null)
            {
                return(true);
            }

            VerifyAtLeastOneNodeIsInCollection(firstNode, secondNode, collection);

            if (NodeIsNotInCollection(firstNode, collection) || NodeIsNotInCollection(secondNode, collection))
            {
                return(true);
            }

            return(false);
        }
Exemple #10
0
 internal static bool CheckWhether_RemoveNode_IsNeeded(IDirectedConnectedNode <T> node, IDirectedConnectedNodeCollection <T> collection)
 {
     return(node == null || NodeIsNotInCollection(node, collection));
 }
Exemple #11
0
 internal static void Verify_AddToCollection_ConditionsAreSatisfied(IDirectedConnectedNode <T> node, IDirectedConnectedNodeCollection <T> collection)
 {
     VerifyCollectionIsNotNull(collection);
     VerifyNodeIsNotInAnyCollection(node);
 }
Exemple #12
0
        internal static void Verify_ConnectNodes_ConditionsAreSatisfied(IDirectedConnectedNode <T> firstNode, IDirectedConnectedNode <T> secondNode, IDirectedConnectedNodeCollection <T> collection)
        {
            VerifyNodeIsNotNull(firstNode);
            VerifyNodeIsNotNull(secondNode);

            VerifyNodeIsInCollection(firstNode, collection);
            VerifyNodeIsInCollection(secondNode, collection);

            VerifyNodesAreNotTheSameNode(firstNode, secondNode);
        }
Exemple #13
0
 internal static void Verify_GetNodesConnected_ConditionsAreSatisfied(IDirectedConnectedNode <T> node, IDirectedConnectedNodeCollection <T> collection)
 {
     VerifyNodeIsNotNull(node);
     VerifyNodeIsInCollection(node, collection);
 }