Skip to content

Commit

Permalink
Make RDFMemoryStore.FromDataTable work with default context when not …
Browse files Browse the repository at this point in the history
…finding ?CONTEXT column
  • Loading branch information
mdesalvo committed Nov 9, 2024
1 parent 1d8eb8b commit 3307120
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 62 deletions.
2 changes: 1 addition & 1 deletion RDFSharp.Test/Model/RDFGraphTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,7 @@ public void ShouldRaiseExceptionOnImportingFromNullDataTable()
=> Assert.ThrowsException<RDFModelException>(() => RDFGraph.FromDataTable(null));

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableNotHaving3Columns()
public void ShouldRaiseExceptionOnImportingFromDataTableNotHavingMandatoryColumns()
{
DataTable table = new DataTable();
table.Columns.Add("?SUBJECT", typeof(string));
Expand Down
140 changes: 95 additions & 45 deletions RDFSharp.Test/Store/Engines/RDFMemoryStoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,12 +1248,12 @@ public async Task ShouldImportEmptyFromFileAsync(string fileExtension, RDFStoreE
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromNullOrEmptyFilepathAsync()
=> Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromFileAsync(RDFStoreEnums.RDFFormats.NQuads, null));
public async Task ShouldRaiseExceptionOnImportingFromNullOrEmptyFilepathAsync()
=> await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromFileAsync(RDFStoreEnums.RDFFormats.NQuads, null));

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromUnexistingFilepathAsync()
=> Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromFileAsync(RDFStoreEnums.RDFFormats.NQuads, "blablabla"));
public async Task ShouldRaiseExceptionOnImportingFromUnexistingFilepathAsync()
=> await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromFileAsync(RDFStoreEnums.RDFFormats.NQuads, "blablabla"));

[DataTestMethod]
[DataRow(RDFStoreEnums.RDFFormats.NQuads)]
Expand Down Expand Up @@ -1380,8 +1380,8 @@ public async Task ShouldImportFromEmptyStreamAsync(RDFStoreEnums.RDFFormats form
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromNullStreamAsync()
=> Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromStreamAsync(RDFStoreEnums.RDFFormats.NQuads, null));
public async Task ShouldRaiseExceptionOnImportingFromNullStreamAsync()
=> await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromStreamAsync(RDFStoreEnums.RDFFormats.NQuads, null));

[TestMethod]
public void ShouldImportFromDataTable()
Expand Down Expand Up @@ -1437,7 +1437,7 @@ public void ShouldRaiseExceptionOnImportingFromNullDataTable()
=> Assert.ThrowsException<RDFStoreException>(() => RDFMemoryStore.FromDataTable(null));

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableNotHaving4Columns()
public void ShouldRaiseExceptionOnImportingFromDataTableNotHavingMandatoryColumns()
{
DataTable table = new DataTable();
table.Columns.Add("?SUBJECT", typeof(string));
Expand All @@ -1459,7 +1459,7 @@ public void ShouldRaiseExceptionOnImportingFromDataTableNotHavingExactColumns()
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullContext()
public void ShouldImportFromDataTableHavingRowWithNullContext()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1468,11 +1468,15 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullContext
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add(null, "http://subj/", "http://pred/", "http://obj/");

Assert.ThrowsException<RDFStoreException>(() => RDFMemoryStore.FromDataTable(table));
RDFMemoryStore store = RDFMemoryStore.FromDataTable(table);

Assert.IsNotNull(store);
Assert.IsTrue(store.QuadruplesCount == 1);
Assert.IsTrue(store[new RDFContext(), new RDFResource("http://subj/"), new RDFResource("http://pred/"), new RDFResource("http://obj/"), null].QuadruplesCount == 1);
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithEmptyContext()
public void ShouldImportFromDataTableHavingRowWithEmptyContext()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1481,7 +1485,28 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithEmptyContex
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("", "http://subj/", "http://pred/", "http://obj/");

Assert.ThrowsException<RDFStoreException>(() => RDFMemoryStore.FromDataTable(table));
RDFMemoryStore store = RDFMemoryStore.FromDataTable(table);

Assert.IsNotNull(store);
Assert.IsTrue(store.QuadruplesCount == 1);
Assert.IsTrue(store[new RDFContext(), new RDFResource("http://subj/"), new RDFResource("http://pred/"), new RDFResource("http://obj/"), null].QuadruplesCount == 1);
}

[TestMethod]
public void ShouldImportFromDataTableHavingRowWithValorizedContext()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
table.Columns.Add("?SUBJECT", typeof(string));
table.Columns.Add("?PREDICATE", typeof(string));
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("http://ctx/", "http://subj/", "http://pred/", "http://obj/");

RDFMemoryStore store = RDFMemoryStore.FromDataTable(table);

Assert.IsNotNull(store);
Assert.IsTrue(store.QuadruplesCount == 1);
Assert.IsTrue(store[new RDFContext("http://ctx/"), new RDFResource("http://subj/"), new RDFResource("http://pred/"), new RDFResource("http://obj/"), null].QuadruplesCount == 1);
}

[TestMethod]
Expand Down Expand Up @@ -1651,33 +1676,33 @@ public async Task ShouldImportEmptyFromDataTableAsync()
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromNullDataTableAsync()
=> Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(null));
public async Task ShouldRaiseExceptionOnImportingFromNullDataTableAsync()
=> await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(null));

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableNotHaving4ColumnsAsync()
public async Task ShouldRaiseExceptionOnImportingFromDataTableNotHavingMandatoryColumnsAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?SUBJECT", typeof(string));
table.Columns.Add("?PREDICATE", typeof(string));

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableNotHavingExactColumnsAsync()
public async Task ShouldRaiseExceptionOnImportingFromDataTableNotHavingExactColumnsAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
table.Columns.Add("?SUBJECT", typeof(string));
table.Columns.Add("?PREDICATE", typeof(string));
table.Columns.Add("?OBJECTTTTT", typeof(string));

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullContextAsync()
public async Task ShouldImportFromDataTableHavingRowWithNullContextAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1686,11 +1711,15 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullContext
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add(null, "http://subj/", "http://pred/", "http://obj/");

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
RDFMemoryStore store = await RDFMemoryStore.FromDataTableAsync(table);

Assert.IsNotNull(store);
Assert.IsTrue(store.QuadruplesCount == 1);
Assert.IsTrue(store[new RDFContext(), new RDFResource("http://subj/"), new RDFResource("http://pred/"), new RDFResource("http://obj/"), null].QuadruplesCount == 1);
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithEmptyContextAsync()
public async Task ShouldImportFromDataTableHavingRowWithEmptyContextAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1699,11 +1728,32 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithEmptyContex
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("", "http://subj/", "http://pred/", "http://obj/");

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
RDFMemoryStore store = await RDFMemoryStore.FromDataTableAsync(table);

Assert.IsNotNull(store);
Assert.IsTrue(store.QuadruplesCount == 1);
Assert.IsTrue(store[new RDFContext(), new RDFResource("http://subj/"), new RDFResource("http://pred/"), new RDFResource("http://obj/"), null].QuadruplesCount == 1);
}

[TestMethod]
public async Task ShouldImportFromDataTableHavingRowWithValorizedContextAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
table.Columns.Add("?SUBJECT", typeof(string));
table.Columns.Add("?PREDICATE", typeof(string));
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("http://ctx/", "http://subj/", "http://pred/", "http://obj/");

RDFMemoryStore store = await RDFMemoryStore.FromDataTableAsync(table);

Assert.IsNotNull(store);
Assert.IsTrue(store.QuadruplesCount == 1);
Assert.IsTrue(store[new RDFContext("http://ctx/"), new RDFResource("http://subj/"), new RDFResource("http://pred/"), new RDFResource("http://obj/"), null].QuadruplesCount == 1);
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithLiteralContextAsync()
public async Task ShouldImportFromDataTableHavingRowWithLiteralContextAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1712,11 +1762,11 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithLiteralCont
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("hello@en", "http://subj/", "http://pred/", "http://obj/");

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullSubjectAsync()
public async Task ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullSubjectAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1725,11 +1775,11 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullSubject
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("http://ctx/", null, "http://pred/", "http://obj/");

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithEmptySubjectAsync()
public async Task ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithEmptySubjectAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1738,11 +1788,11 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithEmptySubjec
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("http://ctx/", "", "http://pred/", "http://obj/");

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithLiteralSubjectAsync()
public async Task ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithLiteralSubjectAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1751,11 +1801,11 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithLiteralSubj
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("http://ctx/", "hello@en", "http://pred/", "http://obj/");

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullPredicateAsync()
public async Task ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullPredicateAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1764,11 +1814,11 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullPredica
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("http://ctx/", "http://subj/", null, "http://obj/");

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithEmptyPredicateAsync()
public async Task ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithEmptyPredicateAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1777,11 +1827,11 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithEmptyPredic
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("http://ctx/", "http://subj/", "", "http://obj/");

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithBlankPredicateAsync()
public async Task ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithBlankPredicateAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1790,11 +1840,11 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithBlankPredic
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("http://ctx/", "http://subj/", "bnode:12345", "http://obj/");

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithLiteralPredicateAsync()
public async Task ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithLiteralPredicateAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1803,11 +1853,11 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithLiteralPred
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("http://ctx/", "http://subj/", "hello@en", "http://obj/");

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullObjectAsync()
public async Task ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullObjectAsync()
{
DataTable table = new DataTable();
table.Columns.Add("?CONTEXT", typeof(string));
Expand All @@ -1816,7 +1866,7 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullObjectA
table.Columns.Add("?OBJECT", typeof(string));
table.Rows.Add("http://ctx/", "http://subj/", "http://pred/", null);

Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromDataTableAsync(table));
}

[TestMethod]
Expand Down Expand Up @@ -1846,16 +1896,16 @@ public async Task ShouldImportFromUriAsync()
}

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromNullUriAsync()
=> Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromUriAsync(null));
public async Task ShouldRaiseExceptionOnImportingFromNullUriAsync()
=> await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromUriAsync(null));

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromRelativeUriAsync()
=> Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromUriAsync(new Uri("/file/system", UriKind.Relative)));
public async Task ShouldRaiseExceptionOnImportingFromRelativeUriAsync()
=> await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromUriAsync(new Uri("/file/system", UriKind.Relative)));

[TestMethod]
public void ShouldRaiseExceptionOnImportingFromUnreacheableUriAsync()
=> Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromUriAsync(new Uri("http://rdfsharp.test/")));
public async Task ShouldRaiseExceptionOnImportingFromUnreacheableUriAsync()
=> await Assert.ThrowsExceptionAsync<RDFStoreException>(() => RDFMemoryStore.FromUriAsync(new Uri("http://rdfsharp.test/")));

[TestCleanup]
public void Cleanup()
Expand Down
Loading

0 comments on commit 3307120

Please sign in to comment.