Skip to content

Commit ab8c030

Browse files
author
Marco De Salvo
committed
Slight code optimization in ApplyModifiers
1 parent 9bc91f7 commit ab8c030

File tree

11 files changed

+128
-128
lines changed

11 files changed

+128
-128
lines changed

RDFSharp.Test/Model/RDFDatatypeTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void ShouldCreateFacetedDatatype()
3434
Assert.IsNotNull(length6);
3535
Assert.AreEqual(RDFModelEnums.RDFDatatypes.XSD_STRING, length6.TargetDatatype);
3636
Assert.IsTrue(length6.URI.Equals(new Uri("ex:length6")));
37-
Assert.IsTrue(length6.Facets.Single() is RDFLengthFacet { Length: 6 });
37+
Assert.IsTrue(length6.Facets[0] is RDFLengthFacet { Length: 6 });
3838
Assert.IsTrue(string.Equals(length6.ToString(), "ex:length6", StringComparison.Ordinal));
3939
}
4040

RDFSharp.Test/Model/RDFGraphTest.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ public void ShouldImportFromFileWithEnabledDatatypeDiscovery(string fileExtensio
13841384
}
13851385
//Test that automatic datatype discovery happened successfully
13861386
Assert.AreEqual(RDFModelEnums.RDFDatatypes.XSD_STRING, RDFDatatypeRegister.GetDatatype($"ex:mydt{(int)format}").TargetDatatype);
1387-
Assert.IsTrue(RDFDatatypeRegister.GetDatatype($"ex:mydt{(int)format}").Facets.Single() is RDFPatternFacet
1387+
Assert.IsTrue(RDFDatatypeRegister.GetDatatype($"ex:mydt{(int)format}").Facets[0] is RDFPatternFacet
13881388
{
13891389
Pattern: "^ex$"
13901390
});
@@ -1480,7 +1480,7 @@ public void ShouldImportFromStreamWithEnabledDatatypeDiscovery(RDFModelEnums.RDF
14801480
}
14811481
//Test that automatic datatype discovery happened successfully
14821482
Assert.AreEqual(RDFModelEnums.RDFDatatypes.XSD_STRING, RDFDatatypeRegister.GetDatatype($"ex:mydtT{(int)format}").TargetDatatype);
1483-
Assert.IsTrue(RDFDatatypeRegister.GetDatatype($"ex:mydtT{(int)format}").Facets.Single() is RDFPatternFacet
1483+
Assert.IsTrue(RDFDatatypeRegister.GetDatatype($"ex:mydtT{(int)format}").Facets[0] is RDFPatternFacet
14841484
{
14851485
Pattern: "^ex$"
14861486
});
@@ -1539,7 +1539,7 @@ public void ShouldImportFromDataTableWithEnabledDatatypeDiscovery()
15391539
Assert.IsTrue(graph2.Equals(graph1));
15401540
//Test that automatic datatype discovery happened successfully
15411541
Assert.AreEqual(RDFModelEnums.RDFDatatypes.XSD_STRING, RDFDatatypeRegister.GetDatatype("ex:mydtZ").TargetDatatype);
1542-
Assert.IsTrue(RDFDatatypeRegister.GetDatatype("ex:mydtZ").Facets.Single() is RDFPatternFacet { Pattern: "^ex$" });
1542+
Assert.IsTrue(RDFDatatypeRegister.GetDatatype("ex:mydtZ").Facets[0] is RDFPatternFacet { Pattern: "^ex$" });
15431543
}
15441544

15451545
[TestMethod]
@@ -1751,31 +1751,31 @@ public void ShouldExtractDatatypeDefinitionsFromGraph()
17511751

17521752
Assert.IsTrue(datatypes.Any(dt => string.Equals(dt.URI.ToString(), "ex:length6", StringComparison.Ordinal)
17531753
&& dt.TargetDatatype == RDFModelEnums.RDFDatatypes.XSD_STRING
1754-
&& dt.Facets.Single() is RDFLengthFacet { Length: 6 }));
1754+
&& dt.Facets[0] is RDFLengthFacet { Length: 6 }));
17551755
Assert.IsTrue(datatypes.Any(dt => string.Equals(dt.URI.ToString(), "ex:minlength6", StringComparison.Ordinal)
17561756
&& dt.TargetDatatype == RDFModelEnums.RDFDatatypes.XSD_STRING
1757-
&& dt.Facets.Single() is RDFMinLengthFacet { Length: 6 }));
1757+
&& dt.Facets[0] is RDFMinLengthFacet { Length: 6 }));
17581758
Assert.IsTrue(datatypes.Any(dt => string.Equals(dt.URI.ToString(), "ex:maxlength6", StringComparison.Ordinal)
17591759
&& dt.TargetDatatype == RDFModelEnums.RDFDatatypes.XSD_STRING
1760-
&& dt.Facets.Single() is RDFMaxLengthFacet { Length: 6 }));
1760+
&& dt.Facets[0] is RDFMaxLengthFacet { Length: 6 }));
17611761
Assert.IsTrue(datatypes.Any(dt => string.Equals(dt.URI.ToString(), "ex:maxinclusive6", StringComparison.Ordinal)
17621762
&& dt.TargetDatatype == RDFModelEnums.RDFDatatypes.XSD_DOUBLE
1763-
&& dt.Facets.Single() is RDFMaxInclusiveFacet { InclusiveUpperBound: 6 }));
1763+
&& dt.Facets[0] is RDFMaxInclusiveFacet { InclusiveUpperBound: 6 }));
17641764
Assert.IsTrue(datatypes.Any(dt => string.Equals(dt.URI.ToString(), "ex:mininclusive6", StringComparison.Ordinal)
17651765
&& dt.TargetDatatype == RDFModelEnums.RDFDatatypes.XSD_DOUBLE
1766-
&& dt.Facets.Single() is RDFMinInclusiveFacet { InclusiveLowerBound: 6 }));
1766+
&& dt.Facets[0] is RDFMinInclusiveFacet { InclusiveLowerBound: 6 }));
17671767
Assert.IsTrue(datatypes.Any(dt => string.Equals(dt.URI.ToString(), "ex:maxexclusive6", StringComparison.Ordinal)
17681768
&& dt.TargetDatatype == RDFModelEnums.RDFDatatypes.XSD_DOUBLE
1769-
&& dt.Facets.Single() is RDFMaxExclusiveFacet { ExclusiveUpperBound: 6 }));
1769+
&& dt.Facets[0] is RDFMaxExclusiveFacet { ExclusiveUpperBound: 6 }));
17701770
Assert.IsTrue(datatypes.Any(dt => string.Equals(dt.URI.ToString(), "ex:minexclusive6", StringComparison.Ordinal)
17711771
&& dt.TargetDatatype == RDFModelEnums.RDFDatatypes.XSD_DOUBLE
1772-
&& dt.Facets.Single() is RDFMinExclusiveFacet { ExclusiveLowerBound: 6 }));
1772+
&& dt.Facets[0] is RDFMinExclusiveFacet { ExclusiveLowerBound: 6 }));
17731773
Assert.IsTrue(datatypes.Any(dt => string.Equals(dt.URI.ToString(), "ex:aliasRational", StringComparison.Ordinal)
17741774
&& dt.TargetDatatype == RDFModelEnums.RDFDatatypes.OWL_RATIONAL
17751775
&& dt.Facets.Count == 0));
17761776
Assert.IsTrue(datatypes.Any(dt => string.Equals(dt.URI.ToString(), "ex:patternex", StringComparison.Ordinal)
17771777
&& dt.TargetDatatype == RDFModelEnums.RDFDatatypes.XSD_STRING
1778-
&& dt.Facets.Single() is RDFPatternFacet patternFacet
1778+
&& dt.Facets[0] is RDFPatternFacet patternFacet
17791779
&& string.Equals(patternFacet.Pattern, "^ex", StringComparison.Ordinal)));
17801780
Assert.IsTrue(datatypes.Any(dt => string.Equals(dt.URI.ToString(), "ex:integer", StringComparison.Ordinal)
17811781
&& dt.TargetDatatype == RDFModelEnums.RDFDatatypes.XSD_INTEGER
@@ -1933,7 +1933,7 @@ public async Task ShouldImportFromFileAsyncWithEnabledDatatypeDiscovery(string f
19331933
}
19341934
//Test that automatic datatype discovery happened successfully
19351935
Assert.AreEqual(RDFModelEnums.RDFDatatypes.XSD_STRING, RDFDatatypeRegister.GetDatatype($"ex:mydtK{(int)format}").TargetDatatype);
1936-
Assert.IsTrue(RDFDatatypeRegister.GetDatatype($"ex:mydtK{(int)format}").Facets.Single() is RDFPatternFacet
1936+
Assert.IsTrue(RDFDatatypeRegister.GetDatatype($"ex:mydtK{(int)format}").Facets[0] is RDFPatternFacet
19371937
{
19381938
Pattern: "^ex$"
19391939
});
@@ -2028,7 +2028,7 @@ public async Task ShouldImportFromStreamAsyncWithEnabledDatatypeDiscovery(RDFMod
20282028
}
20292029
//Test that automatic datatype discovery happened successfully
20302030
Assert.AreEqual(RDFModelEnums.RDFDatatypes.XSD_STRING, RDFDatatypeRegister.GetDatatype($"ex:mydtKK{(int)format}").TargetDatatype);
2031-
Assert.IsTrue(RDFDatatypeRegister.GetDatatype($"ex:mydtKK{(int)format}").Facets.Single() is RDFPatternFacet
2031+
Assert.IsTrue(RDFDatatypeRegister.GetDatatype($"ex:mydtKK{(int)format}").Facets[0] is RDFPatternFacet
20322032
{
20332033
Pattern: "^ex$"
20342034
});
@@ -2085,7 +2085,7 @@ public async Task ShouldImportFromDataTableAsyncWithEnabledDatatypeDiscovery()
20852085
Assert.IsTrue(graph2.Equals(graph1));
20862086
//Test that automatic datatype discovery happened successfully
20872087
Assert.AreEqual(RDFModelEnums.RDFDatatypes.XSD_STRING, RDFDatatypeRegister.GetDatatype("ex:mydtR").TargetDatatype);
2088-
Assert.IsTrue(RDFDatatypeRegister.GetDatatype("ex:mydtR").Facets.Single() is RDFPatternFacet { Pattern: "^ex$" });
2088+
Assert.IsTrue(RDFDatatypeRegister.GetDatatype("ex:mydtR").Facets[0] is RDFPatternFacet { Pattern: "^ex$" });
20892089
}
20902090

20912091
[TestMethod]

RDFSharp.Test/Model/Validation/Abstractions/RDFShapesGraphTest.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ public void ShouldImportShapesGraph()
173173
Assert.IsFalse(shapesGraph2.SelectShape("ex:shape").Deactivated);
174174
Assert.AreEqual(RDFValidationEnums.RDFShapeSeverity.Violation, shapesGraph2.SelectShape("ex:shape").Severity);
175175
Assert.AreEqual(1, shapesGraph2.SelectShape("ex:shape").MessagesCount);
176-
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Messages.Single().Equals(new RDFPlainLiteral("This is an error", "en-US")));
176+
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Messages[0].Equals(new RDFPlainLiteral("This is an error", "en-US")));
177177
Assert.AreEqual(1, shapesGraph2.SelectShape("ex:shape").TargetsCount);
178-
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Targets.Single().TargetValue.Equals(new RDFResource("ex:class")));
178+
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Targets[0].TargetValue.Equals(new RDFResource("ex:class")));
179179
Assert.AreEqual(1, shapesGraph2.SelectShape("ex:shape").ConstraintsCount);
180-
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Constraints.Single() is RDFClassConstraint classContstraint && classContstraint.ClassType.Equals(new RDFResource("ex:class")));
180+
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Constraints[0] is RDFClassConstraint classContstraint && classContstraint.ClassType.Equals(new RDFResource("ex:class")));
181181
}
182182

183183
[TestMethod]
@@ -201,11 +201,11 @@ public void ShouldImportShapesGraphHavingDeactivatedShape()
201201
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Deactivated);
202202
Assert.AreEqual(RDFValidationEnums.RDFShapeSeverity.Violation, shapesGraph2.SelectShape("ex:shape").Severity);
203203
Assert.AreEqual(1, shapesGraph2.SelectShape("ex:shape").MessagesCount);
204-
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Messages.Single().Equals(new RDFPlainLiteral("This is an error", "en-US")));
204+
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Messages[0].Equals(new RDFPlainLiteral("This is an error", "en-US")));
205205
Assert.AreEqual(1, shapesGraph2.SelectShape("ex:shape").TargetsCount);
206-
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Targets.Single().TargetValue.Equals(new RDFResource("ex:class")));
206+
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Targets[0].TargetValue.Equals(new RDFResource("ex:class")));
207207
Assert.AreEqual(1, shapesGraph2.SelectShape("ex:shape").ConstraintsCount);
208-
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Constraints.Single() is RDFClassConstraint classContstraint && classContstraint.ClassType.Equals(new RDFResource("ex:class")));
208+
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Constraints[0] is RDFClassConstraint classContstraint && classContstraint.ClassType.Equals(new RDFResource("ex:class")));
209209
}
210210

211211
[TestMethod]
@@ -228,11 +228,11 @@ public async Task ShouldImportShapesGraphAsync()
228228
Assert.IsFalse(shapesGraph2.SelectShape("ex:shape").Deactivated);
229229
Assert.AreEqual(RDFValidationEnums.RDFShapeSeverity.Violation, shapesGraph2.SelectShape("ex:shape").Severity);
230230
Assert.AreEqual(1, shapesGraph2.SelectShape("ex:shape").MessagesCount);
231-
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Messages.Single().Equals(new RDFPlainLiteral("This is an error", "en-US")));
231+
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Messages[0].Equals(new RDFPlainLiteral("This is an error", "en-US")));
232232
Assert.AreEqual(1, shapesGraph2.SelectShape("ex:shape").TargetsCount);
233-
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Targets.Single().TargetValue.Equals(new RDFResource("ex:class")));
233+
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Targets[0].TargetValue.Equals(new RDFResource("ex:class")));
234234
Assert.AreEqual(1, shapesGraph2.SelectShape("ex:shape").ConstraintsCount);
235-
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Constraints.Single() is RDFClassConstraint classContstraint && classContstraint.ClassType.Equals(new RDFResource("ex:class")));
235+
Assert.IsTrue(shapesGraph2.SelectShape("ex:shape").Constraints[0] is RDFClassConstraint classContstraint && classContstraint.ClassType.Equals(new RDFResource("ex:class")));
236236
}
237237
#endregion
238238
}

RDFSharp.Test/Model/Validation/RDFValidationEngineTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ public void ShouldNotConformNodeShape()
9696
Assert.IsNotNull(validationReport);
9797
Assert.IsFalse(validationReport.Conforms);
9898
Assert.AreEqual(1, validationReport.ResultsCount);
99-
Assert.AreEqual(RDFValidationEnums.RDFShapeSeverity.Violation, validationReport.Results.Single().Severity);
100-
Assert.IsTrue(validationReport.Results.Single().ResultMessages.Single().Equals(new RDFPlainLiteral("ErrorMessage")));
101-
Assert.IsTrue(validationReport.Results.Single().FocusNode.Equals(new RDFResource("ex:Alice")));
102-
Assert.IsTrue(validationReport.Results.Single().ResultValue.Equals(new RDFResource("ex:Alice")));
103-
Assert.IsNull(validationReport.Results.Single().ResultPath);
104-
Assert.IsTrue(validationReport.Results.Single().SourceConstraintComponent.Equals(RDFVocabulary.SHACL.CLASS_CONSTRAINT_COMPONENT));
105-
Assert.IsTrue(validationReport.Results.Single().SourceShape.Equals(new RDFResource("ex:NodeShape")));
99+
Assert.AreEqual(RDFValidationEnums.RDFShapeSeverity.Violation, validationReport.Results[0].Severity);
100+
Assert.IsTrue(validationReport.Results[0].ResultMessages[0].Equals(new RDFPlainLiteral("ErrorMessage")));
101+
Assert.IsTrue(validationReport.Results[0].FocusNode.Equals(new RDFResource("ex:Alice")));
102+
Assert.IsTrue(validationReport.Results[0].ResultValue.Equals(new RDFResource("ex:Alice")));
103+
Assert.IsNull(validationReport.Results[0].ResultPath);
104+
Assert.IsTrue(validationReport.Results[0].SourceConstraintComponent.Equals(RDFVocabulary.SHACL.CLASS_CONSTRAINT_COMPONENT));
105+
Assert.IsTrue(validationReport.Results[0].SourceShape.Equals(new RDFResource("ex:NodeShape")));
106106
}
107107

108108
[TestMethod]

0 commit comments

Comments
 (0)