string GetNodeTitle(DomNode node) { StringBuilder b = new StringBuilder(); b.Append(DecodeRole(node.Role, node.Parent != null ? node.Parent.GetType() : null)); b.Append(": "); b.Append(node.GetType().Name); bool hasProperties = false; foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (p.Name == "NodeType" || p.Name == "IsNull") continue; if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum || p.PropertyType == typeof(bool)) { if (!hasProperties) { hasProperties = true; b.Append(" ("); } else { b.Append(", "); } b.Append(p.Name); b.Append(" = "); try { object val = p.GetValue(node, null); b.Append(val != null ? val.ToString() : "**null**"); } catch (TargetInvocationException ex) { b.Append("**" + ex.InnerException.GetType().Name + "**"); } } } if (hasProperties) b.Append(")"); return b.ToString(); }
// PUBLIC METHODS /////////////////////////////////////////////////// #region Assert Methods public static void Equal(Relationships expected, DomNode actual) { if (expected == null) { Assert.Null(actual); return; } Assert.NotNull(actual); var actualType = actual.GetType(); if (actualType == typeof(DomReadOnlyRelationships)) { var actualDomReadOnlyRelationships = (DomReadOnlyRelationships)actual; DomReadOnlyRelationshipsAssert.Equal(expected, actualDomReadOnlyRelationships); } else if (actualType == typeof(DomReadWriteRelationships)) { var actualDomReadWriteRelationships = (DomReadWriteRelationships)actual; DomReadWriteRelationshipsAssert.Equal(expected, actualDomReadWriteRelationships); } else { Assert.True(false, "Unknown actual node type [name={0}].".FormatWith(actualType.Name)); } }
// PUBLIC METHODS /////////////////////////////////////////////////// #region Assert Methods public static void Equal(string expectedRel, Relationship expectedRelationship, DomNode actual) { Assert.False(String.IsNullOrWhiteSpace(expectedRel)); if (expectedRelationship == null) { Assert.Null(actual); return; } Assert.NotNull(actual); var actualType = actual.GetType(); if (actualType == typeof(DomReadOnlyRelationship)) { var actualDomReadOnlyRelationship = (DomReadOnlyRelationship)actual; DomReadOnlyRelationshipAssert.Equal(expectedRel, expectedRelationship, actualDomReadOnlyRelationship); } else if (actualType == typeof(DomReadWriteRelationship)) { var actualDomReadWriteRelationship = (DomReadWriteRelationship)actual; DomReadWriteRelationshipAssert.Equal(expectedRel, expectedRelationship, actualDomReadWriteRelationship); } else { Assert.True(false, "Unknown actual node type [name={0}].".FormatWith(actualType.Name)); } }
// PUBLIC METHODS /////////////////////////////////////////////////// #region Assert Methods public static void Equal(ResourceIdentifier expectedApiResourceIdentifier, DomNode actual) { if (expectedApiResourceIdentifier == null) { Assert.Null(actual); return; } Assert.NotNull(actual); var actualType = actual.GetType(); if (actualType == typeof(DomReadOnlyResourceIdentifier)) { var actualDomReadOnlyResourceIdentifier = (DomReadOnlyResourceIdentifier)actual; DomReadOnlyResourceIdentifierAssert.Equal(expectedApiResourceIdentifier, actualDomReadOnlyResourceIdentifier); } else if (actualType == typeof(DomReadWriteResourceIdentifier)) { var actualDomReadWriteResourceIdentifier = (DomReadWriteResourceIdentifier)actual; DomReadWriteResourceIdentifierAssert.Equal(expectedApiResourceIdentifier, actualDomReadWriteResourceIdentifier); } else { Assert.True(false, "Unknown actual node type [name={0}].".FormatWith(actualType.Name)); } }
// PUBLIC METHODS /////////////////////////////////////////////////// #region Assert Methods public static void Equal(JsonApiVersion expected, DomNode actual) { if (expected == null) { Assert.Null(actual); return; } Assert.NotNull(actual); var actualType = actual.GetType(); if (actualType == typeof(DomReadOnlyJsonApiVersion)) { var actualDomReadOnlyJsonApiVersion = (DomReadOnlyJsonApiVersion)actual; DomReadOnlyJsonApiVersionAssert.Equal(expected, actualDomReadOnlyJsonApiVersion); } else { Assert.True(false, "Unknown actual node type [name={0}].".FormatWith(actualType.Name)); } }