// PUBLIC METHODS ///////////////////////////////////////////////////
        #region Assert Methods
        public static void Equal(ResourceIdentifier expectedApiResourceIdentifier, DomReadWriteResourceIdentifier actual)
        {
            if (expectedApiResourceIdentifier == null)
            {
                Assert.Null(actual);
                return;
            }
            Assert.NotNull(actual);

            Assert.Equal(DomNodeType.ResourceIdentifier, actual.NodeType);

            // Type
            var domType = actual.GetNode <DomNodeType, DomType>(DomNodeType.Type);

            DomTypeAssert.Equal(expectedApiResourceIdentifier.Type, domType);

            // Id
            var domId = actual.GetNode <DomNodeType, DomId>(DomNodeType.Id);

            DomIdAssert.Equal(expectedApiResourceIdentifier.Id, domId);

            // Meta
            var domMeta = actual.GetNode(DomNodeType.Meta);

            DomMetaAssert.Equal(expectedApiResourceIdentifier.Meta, domMeta);
        }
Exemple #2
0
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Assert Methods
        public static void Equal(string expectedRel, Link expectedLink, DomReadWriteLink actual)
        {
            if (String.IsNullOrWhiteSpace(expectedRel))
            {
                Assert.Null(actual);
                return;
            }
            Assert.NotNull(actual);
            Assert.NotNull(expectedLink);

            Assert.Equal(DomNodeType.Link, actual.NodeType);

            // Rel
            var actualRel = actual.Rel;

            Assert.Equal(expectedRel, actualRel);

            // HRef
            var domHRef = actual.GetNode <DomNodeType, DomHRef>(DomNodeType.HRef);

            DomHRefAssert.Equal(expectedLink.HRef, domHRef);

            // Meta
            var domMeta = actual.GetNode(DomNodeType.Meta);

            DomMetaAssert.Equal(expectedLink.Meta, domMeta);
        }
Exemple #3
0
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Assert Methods
        public static void Equal(string expectedRel, Relationship expectedRelationship, DomReadWriteRelationship actual)
        {
            if (String.IsNullOrWhiteSpace(expectedRel))
            {
                Assert.Null(actual);
                return;
            }
            Assert.NotNull(actual);
            Assert.NotNull(expectedRelationship);

            Assert.Equal(DomNodeType.Relationship, actual.NodeType);

            // Rel
            var actualRel = actual.Rel;

            Assert.Equal(expectedRel, actualRel);

            // Links
            var domLinks = actual.GetNode(DomNodeType.Links);

            DomLinksAssert.Equal(expectedRelationship.Links, domLinks);

            // Data
            var expectedRelationshipType = expectedRelationship.GetRelationshipType();

            switch (expectedRelationshipType)
            {
            case RelationshipType.Relationship:
                break;

            case RelationshipType.ToOneRelationship:
            {
                var expectedToOneResourceLinkage = expectedRelationship.GetToOneResourceLinkage();
                var domData = actual.GetNode(DomNodeType.Data);
                DomDataAssert.Equal(expectedToOneResourceLinkage, domData);
            }
            break;

            case RelationshipType.ToManyRelationship:
            {
                var expectedToManyResourceLinkage = expectedRelationship.GetToManyResourceLinkage();
                var domDataCollection             = actual.GetNode(DomNodeType.DataCollection);
                DomDataCollectionAssert.Equal(expectedToManyResourceLinkage, domDataCollection);
            }
            break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            // Meta
            var domMeta = actual.GetNode(DomNodeType.Meta);

            DomMetaAssert.Equal(expectedRelationship.Meta, domMeta);
        }
Exemple #4
0
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Assert Methods
        public static void Equal(Resource expected, DomReadWriteResource actual)
        {
            if (expected == null)
            {
                Assert.Null(actual);
                return;
            }
            Assert.NotNull(actual);

            Assert.Equal(DomNodeType.Resource, actual.NodeType);

            // Type
            var domType = actual.GetNode <DomNodeType, DomType>(DomNodeType.Type);

            DomTypeAssert.Equal(expected.Type, domType);

            // Id
            var domId = actual.GetNode <DomNodeType, DomId>(DomNodeType.Id);

            DomIdAssert.Equal(expected.Id, domId);

            // Attributes
            var domAttributes = actual.GetNode <DomNodeType, DomAttributes>(DomNodeType.Attributes);

            DomAttributesAssert.Equal(expected.Attributes, domAttributes);

            // Relationships
            var domRelationships = actual.GetNode(DomNodeType.Relationships);

            DomRelationshipsAssert.Equal(expected.Relationships, domRelationships);

            // Links
            var domLinks = actual.GetNode(DomNodeType.Links);

            DomLinksAssert.Equal(expected.Links, domLinks);

            // Meta
            var domMeta = actual.GetNode(DomNodeType.Meta);

            DomMetaAssert.Equal(expected.Meta, domMeta);
        }
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Assert Methods
        public static void Equal(Document expected, DomDocument actual)
        {
            if (expected == null)
            {
                Assert.Null(actual);
                return;
            }
            Assert.NotNull(actual);

            // JsonApiVersion
            var expectedJsonApiVersion = expected.JsonApiVersion;
            var domJsonApiVersion      = actual.GetNode(DomNodeType.JsonApiVersion);

            DomJsonApiVersionAssert.Equal(expectedJsonApiVersion, domJsonApiVersion);

            // Meta
            var expectedMeta = expected.Meta;
            var domMeta      = actual.GetNode(DomNodeType.Meta);

            DomMetaAssert.Equal(expectedMeta, domMeta);

            // Links
            var expectedLinks = expected.Links;
            var domLinks      = actual.GetNode(DomNodeType.Links);

            DomLinksAssert.Equal(expectedLinks, domLinks);

            // Data/Included
            if (expected.IsDataDocument())
            {
                var expectedDocumentType = expected.GetDocumentType();
                switch (expectedDocumentType)
                {
                case DocumentType.EmptyDocument:
                {
                    var domDataCollection = actual.GetNode(DomNodeType.DataCollection);

                    DomDataCollectionAssert.Empty(domDataCollection);
                }
                break;

                case DocumentType.NullDocument:
                {
                    var domData = actual.GetNode(DomNodeType.Data);

                    DomDataAssert.Null(domData);
                }
                break;

                case DocumentType.ResourceDocument:
                {
                    var expectedResource = expected.GetResource();
                    var domData          = actual.GetNode(DomNodeType.Data);

                    DomDataAssert.Equal(expectedResource, domData);

                    // Included
                    var expectedIncluded = expected.GetIncludedResources();
                    var domIncluded      = actual.GetNode(DomNodeType.Included);
                    DomIncludedAssert.Equal(expectedIncluded, domIncluded);
                }
                break;

                case DocumentType.ResourceCollectionDocument:
                {
                    var expectedResourceCollection = expected.GetResourceCollection();
                    var domDataCollection          = actual.GetNode(DomNodeType.DataCollection);

                    DomDataCollectionAssert.Equal(expectedResourceCollection, domDataCollection);

                    // Included
                    var expectedIncluded = expected.GetIncludedResources();
                    var domIncluded      = actual.GetNode(DomNodeType.Included);
                    DomIncludedAssert.Equal(expectedIncluded, domIncluded);
                }
                break;

                case DocumentType.ResourceIdentifierDocument:
                {
                    var expectedResourceIdentifier = expected.GetResourceIdentifier();
                    var domData = actual.GetNode(DomNodeType.Data);

                    DomDataAssert.Equal(expectedResourceIdentifier, domData);
                }
                break;

                case DocumentType.ResourceIdentifierCollectionDocument:
                {
                    var expectedResourceIdentifierCollection = expected.GetResourceIdentifierCollection();
                    var domDataCollection = actual.GetNode(DomNodeType.DataCollection);

                    DomDataCollectionAssert.Equal(expectedResourceIdentifierCollection, domDataCollection);
                }
                break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                // If this is a data document then the document errors node
                // should not be present in the DOM tree.
                var domErrors = actual.GetNode(DomNodeType.Errors);
                Assert.Null(domErrors);
            }
            else if (expected.IsErrorsDocument())
            {
                // Errors
                var expectedErrors = expected.GetErrors();
                var domErrors      = actual.GetNode(DomNodeType.Errors);
                DomErrorsAssert.Equal(expectedErrors, domErrors);

                // If this is an errors document then the document data, data collection,
                // or included nodes should not be present in the DOM tree.
                var domData = actual.GetNode(DomNodeType.Data);
                Assert.Null(domData);

                var domDataCollection = actual.GetNode(DomNodeType.DataCollection);
                Assert.Null(domDataCollection);

                var domIncluded = actual.GetNode(DomNodeType.Included);
                Assert.Null(domIncluded);
            }
            else
            {
                // If this is a base document then the document data, data collection, included,
                // or errors nodes should not be present in the DOM tree.
                var domData = actual.GetNode(DomNodeType.Data);
                Assert.Null(domData);

                var domDataCollection = actual.GetNode(DomNodeType.DataCollection);
                Assert.Null(domDataCollection);

                var domIncluded = actual.GetNode(DomNodeType.Included);
                Assert.Null(domIncluded);

                var domErrors = actual.GetNode(DomNodeType.Errors);
                Assert.Null(domErrors);
            }
        }