Exemple #1
0
 // checks that a given STON path segment has a correct canonical form
 private void ExpectValidPathSegment(IStonPathSegment segment, string canonicalForm)
 {
     try
     {
         Assert.AreEqual(canonicalForm, new StonReferenceEntity(new StonAddress(new StonAncestorInitialContext(0), new IStonPathSegment[] { segment })).ToCanonicalForm().Substring(1));
     }
     catch (StonException ex)
     {
         Assert.Fail(ex.Message);
     }
 }
Exemple #2
0
 // checks that a given path segment is invalid
 // and causes an error with a specific message
 private void ExpectInvalidPathSegment(IStonPathSegment segment, string message)
 {
     try
     {
         new StonReferenceEntity(new StonAddress(new StonAncestorInitialContext(0), new IStonPathSegment[] { segment }));
         Assert.Fail("The reference is valid. This should *not* have happened.");
     }
     catch (StonException ex)
     {
         Assert.AreEqual(message, ex.Message);
     }
 }
Exemple #3
0
 /// <summary>
 /// Creates a structurally equivalent path segment from a given segment.
 /// </summary>
 /// <param name="segment">The segment to copy the structure of.</param>
 /// <returns>A structurally equivalent copy of the given segment.</returns>
 public static IStonPathSegment Copy(IStonPathSegment segment)
 {
     if (segment == null)
     {
         throw new ArgumentNullException("segment");
     }
     if (segment is IStonAncestorPathSegment)
     {
         return(StonAncestorPathSegment.Copy(segment as IStonAncestorPathSegment));
     }
     if (segment is IStonMemberPathSegment)
     {
         return(StonMemberPathSegment.Copy(segment as IStonMemberPathSegment));
     }
     if (segment is IStonCollectionElementPathSegment)
     {
         return(StonCollectionElementPathSegment.Copy(segment as IStonCollectionElementPathSegment));
     }
     throw new StonImplementationException(segment.GetType(), typeof(IStonPathSegment), typeof(IStonAncestorPathSegment), typeof(IStonMemberPathSegment), typeof(IStonCollectionElementPathSegment));
 }
Exemple #4
0
 /// <summary>
 /// Checks the validity of a given STON path segment.
 /// </summary>
 /// <param name="segment">The path segment to check the validity of.</param>
 public static void ValidatePathSegment(IStonPathSegment segment)
 {
     if (segment == null)
     {
         throw new ArgumentNullException("segment");
     }
     else if (segment is IStonAncestorPathSegment)
     {
         ValidatePathSegment(segment as IStonAncestorPathSegment);
     }
     else if (segment is IStonMemberPathSegment)
     {
         ValidatePathSegment(segment as IStonMemberPathSegment);
     }
     else if (segment is IStonCollectionElementPathSegment)
     {
         ValidatePathSegment(segment as IStonCollectionElementPathSegment);
     }
     else
     {
         throw new StonImplementationException(segment.GetType(), typeof(IStonPathSegment), typeof(IStonAncestorPathSegment), typeof(IStonMemberPathSegment), typeof(IStonCollectionElementPathSegment));
     }
 }
Exemple #5
0
 // writes any path segment
 private void WritePathSegment(StonTokenWriter writer, IStonPathSegment segment)
 {
     if (segment == null)
     {
         throw new StonException("A non-existing path segment has been found in the structure to be written.");
     }
     else if (segment is IStonAncestorPathSegment)
     {
         WritePathSegment(writer, segment as IStonAncestorPathSegment);
     }
     else if (segment is IStonMemberPathSegment)
     {
         WritePathSegment(writer, segment as IStonMemberPathSegment);
     }
     else if (segment is IStonCollectionElementPathSegment)
     {
         WritePathSegment(writer, segment as IStonCollectionElementPathSegment);
     }
     else
     {
         throw new StonImplementationException(segment.GetType(), typeof(IStonPathSegment), typeof(IStonAncestorPathSegment), typeof(IStonMemberPathSegment), typeof(IStonCollectionElementPathSegment));
     }
 }