예제 #1
0
    public void BuildComplexContextSimply()
    {
        // given
        const string expected = @"
{
    '@base': 'http://example.com/',
    '@vocab': 'http://schema.org/',
    'dcterms': 'http://purl.org/dc/terms/',
    'xsd': 'http://www.w3.org/2001/XMLSchema#',
    'title': 'dcterms:title',
    'creator': { 
        '@id': 'dcterms:creator', 
        '@type': '@id'
    },
    'medium': { 
        '@id': 'dcterms:medium', 
        '@container': '@set', 
        '@type': '@vocab'
    },
    'date': { 
        '@id': 'dcterms:date', 
        '@type': 'xsd:date'
    },
    '@language': 'en',
    'label': {
        '@id': 'http://www.w3.org/2004/02/skos/core#prefLabel',
        '@language': null
    },
    'altLabel': {
        '@id': 'http://www.w3.org/2004/02/skos/core#altLabel',
        '@container': '@language',
        '@type': 'xsd:string'
    }
}";

        // when
        var context = new JObject(
            Base.Is("http://example.com/"),
            Vocab.Is(new Uri("http://schema.org/")),
            "dcterms".IsPrefixOf("http://purl.org/dc/terms/"),
            "xsd".IsPrefixOf(new Uri("http://www.w3.org/2001/XMLSchema#")),
            "title".IsProperty("dcterms:title"),
            "creator".IsProperty("dcterms:creator")
            .Type().Id(),
            "medium".IsProperty("dcterms:medium")
            .Container().Set()
            .Type().Vocab(),
            "date".IsProperty("dcterms:date")
            .Type().Is("xsd:date"),
            "en".IsLanguage(),
            "label".IsProperty("http://www.w3.org/2004/02/skos/core#prefLabel")
            .Language(null),
            "altLabel".IsProperty("http://www.w3.org/2004/02/skos/core#altLabel")
            .Container().Language()
            .Type().Is("xsd:string"));

        // then
        context = JObject.Parse(context.ToString()); // DeepEqual fails otherwise
        Assert.That(JToken.DeepEquals(context, JObject.Parse(expected)), "Actual context was {0}", context);
    }