public Task<IResourceLinkage> Deserialize(JsonReader reader, string currentPath)
        {
            IResourceLinkage linkage;
            if (reader.TokenType == JsonToken.StartArray)
            {
                var array = JToken.ReadFrom(reader);
                var resourceIdentifiers = array.Select(t => ReadResourceIdentifier(t, currentPath)).ToArray();

                linkage = new ToManyResourceLinkage(resourceIdentifiers);
            }
            else if (reader.TokenType == JsonToken.StartObject)
            {
                var obj = JToken.ReadFrom(reader);
                var resourceIdentifier = ReadResourceIdentifier(obj, currentPath);

                linkage = new ToOneResourceLinkage(resourceIdentifier);
            }
            else if (reader.TokenType == JsonToken.Null)
            {
                linkage = new ToOneResourceLinkage(null);
            }
            else
            {
                throw new DeserializationException("Invalid linkage for relationship",
                    "Expected an array, object, or null for linkage, but got " + reader.TokenType, currentPath);
            }

            return Task.FromResult(linkage);
        }
        public void Identifiers_is_correct_for_present_identifiers()
        {
            var mockIdentifier1 = new Mock<IResourceIdentifier>(MockBehavior.Strict);
            mockIdentifier1.Setup(i => i.Type).Returns("countries");
            mockIdentifier1.Setup(i => i.Id).Returns("1000");

            var mockIdentifier2 = new Mock<IResourceIdentifier>(MockBehavior.Strict);
            mockIdentifier2.Setup(i => i.Type).Returns("cities");
            mockIdentifier2.Setup(i => i.Id).Returns("4000");

            var linkage = new ToManyResourceLinkage(new [] { mockIdentifier1.Object, mockIdentifier2.Object });

            linkage.Identifiers.Length.Should().Be(2);
            linkage.Identifiers[0].Type.Should().Be("countries");
            linkage.Identifiers[0].Id.Should().Be("1000");
            linkage.Identifiers[1].Type.Should().Be("cities");
            linkage.Identifiers[1].Id.Should().Be("4000");
        }
        public void Returns_corrent_LinkageToken_for_empty_identifiers()
        {
            var linkage = new ToManyResourceLinkage(new IResourceIdentifier[] { });

            linkage.Identifiers.Length.Should().Be(0);
        }
        public void Returns_corrent_LinkageToken_for_null_identifiers()
        {
            var linkage = new ToManyResourceLinkage(null);

            linkage.Identifiers.Length.Should().Be(0);
        }