public void Remove_pair_handles_public_dictionaries() { var expected = new Graph(); expected.LoadFromString(@" <urn:s2> <urn:s1> ""o3"" . <urn:s2> <urn:p3> <urn:s1> . "); var actual = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:")); actual.LoadFromString(@" <urn:s1> <urn:p1> ""o1"" . <urn:s1> <urn:p2> ""o2"" . <urn:s2> <urn:s1> ""o3"" . <urn:s2> <urn:p3> <urn:s1> . "); var s1 = UriFactory.Create("urn:s1"); var value = new Dictionary <object, object> { { "p1", "o1" }, { "p2", "o2" } }; ((IDictionary <Uri, object>)actual).Remove(new KeyValuePair <Uri, object>(s1, value)); Assert.Equal <IGraph>(expected, actual); }
public void Remove_po_handles_public_properties() { var expected = new Graph(); expected.LoadFromString(@" <urn:s2> <urn:s1> ""o3"" . <urn:s2> <urn:p3> <urn:s1> . "); var actual = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:")); actual.LoadFromString(@" <urn:s1> <urn:p1> ""o1"" . <urn:s1> <urn:p2> ""o2"" . <urn:s2> <urn:s1> ""o3"" . <urn:s2> <urn:p3> <urn:s1> . "); var s1 = actual.Nodes.First(); var predicateAndObjects = new { p1 = "o1", p2 = "o2" }; actual.Remove(s1, predicateAndObjects); Assert.Equal <IGraph>(expected, actual); }
public void Set_index_overwrites_by_subject() { var expected = new Graph(); expected.LoadFromString(@" <urn:s1> <urn:p1> ""o"" . <urn:s2> <urn:s1> ""o6"" . <urn:s2> <urn:p3> <urn:s1> . "); var actual = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:")); actual.LoadFromString(@" <urn:s1> <urn:p1> ""o1"" . <urn:s1> <urn:p1> ""o2"" . <urn:s1> <urn:p2> ""o3"" . <urn:s1> <urn:p2> ""o4"" . <urn:s1> <urn:p2> ""o5"" . <urn:s2> <urn:s1> ""o6"" . <urn:s2> <urn:p3> <urn:s1> . "); var s1 = UriFactory.Create("urn:s1"); actual[s1] = new { p1 = "o" }; Assert.Equal <IGraph>(expected, actual); }
public void Set_index_with_null_value_retracts_by_subject() { var expected = new Graph(); expected.LoadFromString(@" <urn:s2> <urn:s1> ""o6"" . <urn:s2> <urn:p3> <urn:s1> . "); var actual = new DynamicGraph(); actual.LoadFromString(@" <urn:s1> <urn:p1> ""o1"" . <urn:s1> <urn:p1> ""o2"" . <urn:s1> <urn:p2> ""o3"" . <urn:s1> <urn:p2> ""o4"" . <urn:s1> <urn:p2> ""o5"" . <urn:s2> <urn:s1> ""o6"" . <urn:s2> <urn:p3> <urn:s1> . "); var s1 = UriFactory.Create("urn:s1"); actual[s1] = null; Assert.Equal <IGraph>(expected, actual); }
public void Remove_retracts_by_subject() { var expected = new Graph(); expected.LoadFromString(@" <urn:s2> <urn:s1> ""o5"" . <urn:s2> <urn:p3> <urn:s1> . "); var actual = new DynamicGraph(); actual.LoadFromString(@" <urn:s1> <urn:p1> ""o1"" . <urn:s1> <urn:p1> ""o2"" . <urn:s1> <urn:p2> ""o3"" . <urn:s1> <urn:p2> ""o4"" . <urn:s2> <urn:s1> ""o5"" . <urn:s2> <urn:p3> <urn:s1> . "); var s1 = UriFactory.Create("urn:s1"); actual.Remove(s1); Assert.Equal <IGraph>(expected, actual); }
public void Values_are_dynamic_uri_nodes() { var d = new DynamicGraph(); d.LoadFromString(@" <urn:s1> <urn:p1> <urn:o01> . <urn:s1> <urn:p1> <urn:o02> . <urn:s1> <urn:p2> <urn:o03> . <urn:s1> <urn:p2> <urn:o04> . <urn:s2> <urn:p3> <urn:o05> . <urn:s2> <urn:p3> <urn:o06> . <urn:s2> <urn:p4> <urn:o07> . <urn:s2> <urn:p4> <urn:o08> . _:s3 <urn:p5> <urn:o9> . _:s3 <urn:p5> <urn:o10> . _:s3 <urn:p6> <urn:o11> . _:s3 <urn:p6> <urn:o12> . "); Assert.Equal(d.Nodes.UriNodes(), d.Values); foreach (var value in d.Values) { Assert.IsType <DynamicNode>(value); } }
public void Leaves_absoulte_URIs_without_base() { var d = new DynamicGraph(); d.LoadFromString(@" <urn:s> <urn:p> <urn:o> . "); Assert.Equal(new[] { "urn:s", "urn:o" }, d.Keys); }
public void Contains_searches_exisiting_statements() { var d = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:")); d.LoadFromString(@"<urn:s> <urn:p> ""o"" ."); var dict = (IDictionary <Uri, object>)d; var s = UriFactory.Create("urn:s"); Assert.True(dict.Contains(new KeyValuePair <Uri, object>(s, new { p = "o" }))); }
public void Contains_rejects_missing_statement() { var d = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:")); d.LoadFromString(@"<urn:s> <urn:p> ""o"" ."); var dict = (IDictionary <string, object>)d; var s = "urn:s"; Assert.False(dict.Contains(new KeyValuePair <string, object>(s, new { p = "o1" }))); }
public void Remove_reports_retraction_success() { var d = new DynamicGraph(); d.LoadFromString("<urn:s> <urn:p> <urn:o> ."); var s = UriFactory.Create("urn:s"); Assert.True(d.Remove(s)); Assert.False(d.Remove(s)); }
public void Remove_p_reports_retraction_success() { var d = new DynamicGraph(); d.LoadFromString("<urn:s> <urn:p> <urn:o> ."); var s = d.Nodes.First(); Assert.True(d.Remove(s)); Assert.False(d.Remove(s)); }
public void Contains_rejects_missing_statement() { var d = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:")); d.LoadFromString(@" <urn:s> <urn:p> <urn:o> . "); var s = d.CreateUriNode(UriFactory.Create("urn:s")); Assert.False(d.Contains(s, new { p = s })); }
public void TryGetValue_returns_dynamic_subject() { var d = new DynamicGraph(); d.LoadFromString("<urn:s> <urn:p> <urn:o> ."); var s = UriFactory.Create("urn:s"); Assert.True(d.TryGetValue(s, out var value)); Assert.Equal(value, d.CreateUriNode(s)); Assert.IsType <DynamicNode>(value); }
public void Ignores_URNs_for_QName_parsing() { var d = new DynamicGraph(); d.LoadFromString(@" <urn:s> <urn:p> <urn:o> . "); var s = d.CreateUriNode(UriFactory.Create("urn:s")); Assert.Equal(s, d["urn:s"]); }
public void Ignores_URIs_for_QName_parsing() { var d = new DynamicGraph(); d.LoadFromString(@" <http://example.com/s> <http://example.com/p> <http://example.com/o> . "); var s = d.CreateUriNode(UriFactory.Create("http://example.com/s")); Assert.Equal(s, d["http://example.com/s"]); }
public void Reduces_QNames() { var d = new DynamicGraph(); d.LoadFromString(@" @prefix : <urn:> . :s :p :o . "); Assert.Equal(new[] { ":s", ":o" }, d.Keys); }
public void Reduces_hash_base_URIs() { var d = new DynamicGraph { BaseUri = UriFactory.Create("http://example.com/#") }; d.LoadFromString(@" <http://example.com/#s> <http://example.com/#p> <http://example.com/#o> . "); Assert.Equal(new[] { "s", "o" }, d.Keys); }
public void Reduces_base_URIs() { var d = new DynamicGraph { BaseUri = UriFactory.Create("urn:") }; d.LoadFromString(@" <urn:s> <urn:p> <urn:o> . "); Assert.Equal(new[] { "s", "o" }, d.Keys); }
public void Enumerates_pairs_with_subject_key_and_dynamic_subject_value() { var g = new DynamicGraph(); g.LoadFromString(@" <urn:s> <urn:s> <urn:s> . # 1 (subject) <urn:s> <urn:s> <urn:p> . <urn:s> <urn:s> <urn:o> . <urn:s> <urn:p> <urn:s> . <urn:s> <urn:p> <urn:p> . <urn:s> <urn:p> <urn:o> . <urn:s> <urn:o> <urn:s> . <urn:s> <urn:o> <urn:p> . <urn:s> <urn:o> <urn:o> . <urn:p> <urn:s> <urn:s> . # 2 (subject) <urn:p> <urn:s> <urn:p> . <urn:p> <urn:s> <urn:o> . <urn:p> <urn:p> <urn:s> . <urn:p> <urn:p> <urn:p> . <urn:p> <urn:p> <urn:o> . <urn:p> <urn:o> <urn:s> . <urn:p> <urn:o> <urn:p> . <urn:p> <urn:o> <urn:o> . <urn:o> <urn:s> <urn:s> . # 3 (subject) <urn:o> <urn:s> <urn:p> . <urn:o> <urn:s> <urn:o> . <urn:o> <urn:p> <urn:s> . <urn:o> <urn:p> <urn:p> . <urn:o> <urn:p> <urn:o> . <urn:o> <urn:o> <urn:s> . <urn:o> <urn:o> <urn:p> . <urn:o> <urn:o> <urn:o> . "); var s = UriFactory.Create("urn:s"); var p = UriFactory.Create("urn:p"); var o = UriFactory.Create("urn:o"); using (var actual = g.Cast <KeyValuePair <Uri, object> >().GetEnumerator()) { using (var expected = new[] { s, p, o }.Cast <Uri>().GetEnumerator()) { while (expected.MoveNext() | actual.MoveNext()) { var keyNode = g.CreateUriNode(expected.Current); Assert.Equal(new KeyValuePair <Uri, object>(expected.Current, keyNode), actual.Current); Assert.IsType <DynamicNode>(actual.Current.Value); } } } }
public void Enumerates_pairs_with_uri_key_and_dynamic_value() { var g = new DynamicGraph(); g.LoadFromString(@" <urn:s> <urn:s> <urn:s> . # 1 <urn:s> <urn:s> <urn:p> . <urn:s> <urn:s> <urn:o> . <urn:s> <urn:p> <urn:s> . <urn:s> <urn:p> <urn:p> . <urn:s> <urn:p> <urn:o> . <urn:s> <urn:o> <urn:s> . <urn:s> <urn:o> <urn:p> . <urn:s> <urn:o> <urn:o> . <urn:p> <urn:s> <urn:s> . # 2 <urn:p> <urn:s> <urn:p> . <urn:p> <urn:s> <urn:o> . <urn:p> <urn:p> <urn:s> . <urn:p> <urn:p> <urn:p> . <urn:p> <urn:p> <urn:o> . <urn:p> <urn:o> <urn:s> . <urn:p> <urn:o> <urn:p> . <urn:p> <urn:o> <urn:o> . <urn:o> <urn:s> <urn:s> . # 3 <urn:o> <urn:s> <urn:p> . <urn:o> <urn:s> <urn:o> . <urn:o> <urn:p> <urn:s> . <urn:o> <urn:p> <urn:p> . <urn:o> <urn:p> <urn:o> . <urn:o> <urn:o> <urn:s> . <urn:o> <urn:o> <urn:p> . <urn:o> <urn:o> <urn:o> . "); var s = g.CreateUriNode(UriFactory.Create("urn:s")); var p = g.CreateUriNode(UriFactory.Create("urn:p")); var o = g.CreateUriNode(UriFactory.Create("urn:o")); var d = (IEnumerable)g; var spo = new[] { s, p, o }; var actual = d.GetEnumerator(); var expected = spo.GetEnumerator(); while (expected.MoveNext() | actual.MoveNext()) { var current = (KeyValuePair <INode, object>)actual.Current; Assert.Equal(expected.Current, current.Key); Assert.IsType <DynamicNode>(current.Value); Assert.Equal(expected.Current, current.Value); } }
public void Handles_get_member() { var g = new DynamicGraph(subjectBaseUri: new Uri("urn:")); g.LoadFromString(@" <urn:s> <urn:p> <urn:o> . "); var s = g.CreateUriNode(UriFactory.Create("urn:s")); dynamic d = g; Assert.Equal(s, d.s); }
public void TryGetValue_returns_dynamic_subject() { var d = new DynamicGraph(); d.LoadFromString("<urn:s> <urn:p> <urn:o> ."); var s = d.Nodes.First(); Assert.True(d.TryGetValue(s, out var value)); Assert.Equal(value, s); Assert.NotNull(value); Assert.IsType <DynamicNode>(value); }
public void Rejects_relative_URI_without_base() { var d = new DynamicGraph(); d.LoadFromString(@" <urn:s> <urn:p> <urn:o> . "); var s = d.CreateUriNode(UriFactory.Create("urn:s")); Assert.Throws <InvalidOperationException>(() => Assert.Equal(s, d["/s"])); }
public void Contains_searches_exisiting_statements() { var d = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:")); d.LoadFromString(@" <urn:s> <urn:p> <urn:o> . "); var s = d.CreateUriNode(UriFactory.Create("urn:s")); var o = d.CreateUriNode(UriFactory.Create("urn:o")); Assert.True(d.Contains(s, new { p = o })); }
public void Get_index_returns_dynamic_subject() { var d = new DynamicGraph(); d.LoadFromString(@" <urn:s> <urn:p> <urn:o> . "); var s = d.CreateUriNode(UriFactory.Create("urn:s")); Assert.Equal(s, d[s]); Assert.IsType <DynamicNode>(d[s]); }
public void Provides_dictionary_meta_object() { var d = new DynamicGraph(); d.LoadFromString(@" <urn:s> <urn:p> <urn:o> . "); var p = (IDynamicMetaObjectProvider)d; var mo = p.GetMetaObject(Expression.Empty()); Assert.NotNull(mo); }
public void Contains_handles_pairs() { var g = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:")); g.LoadFromString(@" <urn:s> <urn:p> <urn:o> . "); var s = g.CreateUriNode(UriFactory.Create("urn:s")); var o = g.CreateUriNode(UriFactory.Create("urn:o")); Assert.Contains(new KeyValuePair <INode, object>(s, new { p = o }), g); }
public void ContainsKey_searches_uri_nodes() { var d = new DynamicGraph(); d.LoadFromString("<urn:s> <urn:p> <urn:o> ."); var s = UriFactory.Create("urn:s"); var p = UriFactory.Create("urn:p"); var o = UriFactory.Create("urn:o"); Assert.True(d.ContainsKey(s)); Assert.False(d.ContainsKey(p)); Assert.True(d.ContainsKey(o)); }
public void Expands_slash_URI_base() { var d = new DynamicGraph { BaseUri = UriFactory.Create("http://example.com/") }; d.LoadFromString(@" <http://example.com/s> <http://example.com/p> <http://example.com/o> . "); var s = d.CreateUriNode(UriFactory.Create("http://example.com/s")); Assert.Equal(s, d["s"]); }
public void Get_index_returns_dynamic_subject() { var d = new DynamicGraph(); d.LoadFromString("<urn:s> <urn:p> <urn:o> ."); var s = UriFactory.Create("urn:s"); var expected = d.CreateUriNode(s); var actual = d[s]; Assert.Equal(expected, actual); Assert.IsType <DynamicNode>(actual); }