Skip to content

Conversation

@ZUOXIANGE
Copy link

@ZUOXIANGE ZUOXIANGE commented Aug 15, 2025

Summary by CodeRabbit

  • New Features

    • Collections of links (ICollection/ IEnumerable/ ISet of URI) are now treated as resource-valued properties in generated resource shapes.
  • Tests

    • New test project with comprehensive unit tests verifying resource shape creation, URI-collection mappings, and coverage tooling.
  • Chores

    • Solution updated to include the new test project across build configurations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 15, 2025

Walkthrough

Adds a new test project to the solution, introduces ResourceShapeFactory unit tests, and extends ResourceShapeFactory's type-to-value-type mapping to treat ICollection<Uri>, IEnumerable<Uri>, and ISet<Uri> as ValueType.Resource.

Changes

Cohort / File(s) Summary
Solution Update
OSLC4Net_SDK/OSLC4Net.Core.sln
Adds test project OSLC4Net.Core.Tests to the solution, adds ProjectConfigurationPlatforms entries for all configurations, and nests it under the Tests solution folder.
Core Model Mapping
OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs
Adds TYPE_TO_VALUE_TYPE mappings for ICollection<Uri>, IEnumerable<Uri>, and ISet<Uri> to resolve to ValueType.Resource.
Test Project Setup
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/OSLC4Net.Core.Tests.csproj
Adds a new .NET 8 test project referencing core projects and adds test/coverage/mocking/logging dependencies (xUnit v3, Microsoft.NET.Test.Sdk, NSubstitute, coverlet, logging helpers).
ResourceShapeFactory Unit Tests
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs
Adds comprehensive tests for ResourceShapeFactory.CreateResourceShape, including Requirement resource validations, getter-only detection, and collection-of-Uri property mappings (ICollection, List, array, HashSet, getter/setter pattern) plus test resource classes.

Sequence Diagram(s)

(omitted — changes are static type-to-value-type mapping and tests; no new runtime control-flow introduced)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

I nibble through the mapping trail,
Collections of URIs set sail,
Tests take seed and brightly sprout,
A new project hops and shouts about,
Tiny rabbit, big review — hooray! 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 427b216 and 0a87acf.

📒 Files selected for processing (1)
  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (3)

8-9: Use English for all code comments.

The XML documentation comment is in Chinese. According to Microsoft Framework design guidelines, code comments should be in English for consistency and maintainability.

/// <summary>
-/// 测试ResourceShapeFactory.CreateResourceShape方法
+/// Tests for the ResourceShapeFactory.CreateResourceShape method
/// </summary>

91-91: Use English for all code comments.

The inline comment is in Chinese. Keep all comments in English for consistency.

-        // ResourceShapeFactory只处理以Get或Is开头的方法,Requirement类只有从AbstractResourceRecord继承的GetTypes()方法
+        // ResourceShapeFactory only processes methods starting with Get or Is, Requirement class only has GetTypes() method inherited from AbstractResourceRecord

10-15: Consider using more descriptive constant names.

The constants could be more descriptive to better reflect their purpose in the OSLC context.

-    private const string BaseUri = "http://example.com";
-    private const string ResourceShapesPath = "resourceShapes";
-    private const string ResourceShapePath = "requirement";
+    private const string TestBaseUri = "http://example.com";
+    private const string OslcResourceShapesPath = "resourceShapes";
+    private const string RequirementResourceShapePath = "requirement";
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2c6244f and e9042f1.

📒 Files selected for processing (4)
  • OSLC4Net_SDK/OSLC4Net.Core.sln (3 hunks)
  • OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs (1 hunks)
  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/OSLC4Net.Core.Tests.csproj (1 hunks)
  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

⚙️ CodeRabbit Configuration File

**/*.cs: Review the C# code against the Microsoft Framework design guidelines as well as 10 guidelines
from "Building Maintainable Software" by Joost Visser. Point out deviations and improvements.

Files:

  • OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs
  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs
🧬 Code Graph Analysis (2)
OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs (1)
OSLC4Net_SDK/OSLC4Net.Core/Model/ValueType.cs (2)
  • ValueType (69-82)
  • ValueType (84-87)
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (3)
OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs (3)
  • ResourceShapeFactory (26-511)
  • ResourceShapeFactory (38-57)
  • ResourceShapeFactory (59-61)
OSLC4Net_SDK/OSLC4Net.Domains.RequirementsManagement/Constants.cs (1)
  • RM (27-77)
OSLC4Net_SDK/OSLC4Net.Core/Model/TypeFactory.cs (1)
  • GetName (41-47)
🔇 Additional comments (11)
OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs (1)

56-56: LGTM! The mapping addition is correct and addresses the KeyNotFound issue.

The addition of TYPE_TO_VALUE_TYPE[typeof(ICollection<Uri>)] = ValueType.Resource; properly maps URI collections to resource value types. This aligns with the existing pattern where Uri is mapped to ValueType.Resource on line 55, and extends that mapping to collections of URIs, which is semantically correct for OSLC resource relationships.

OSLC4Net_SDK/OSLC4Net.Core.sln (3)

45-46: LGTM! New test project properly added to the solution.

The new test project is correctly defined with the appropriate GUID and path structure following the established patterns in the solution.


217-228: LGTM! Complete configuration coverage for the new test project.

All solution configurations (Debug/Release across Any CPU, Mixed Platforms, and x86) are properly configured for the new test project, ensuring it builds correctly in all scenarios.


241-241: LGTM! Test project properly organized under Tests folder.

The NestedProjects section correctly places the new test project under the Tests solution folder, maintaining the solution's organizational structure.

OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/OSLC4Net.Core.Tests.csproj (1)

1-30: LGTM! Well-structured test project configuration.

The project file follows .NET 8.0 best practices with:

  • Proper targeting (net8.0)
  • Appropriate project references to both core library and domain-specific components
  • Comprehensive test package dependencies including xUnit v3, NSubstitute for mocking, and code coverage tools
  • Correct asset configurations for analyzers and build-time dependencies

The package selection demonstrates good testing practices with modern tooling.

OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (6)

16-33: LGTM! Well-structured basic validation test.

The test follows the AAA pattern correctly and validates the fundamental functionality of resource shape creation including proper URI construction.


35-51: LGTM! Title validation test is well-implemented.

The test properly verifies that the resource shape has the expected title as configured in the Requirement type's attributes.


53-71: LGTM! Describes validation test correctly checks domain URI.

The test properly validates that the resource shape describes the correct OSLC domain URI for requirements management, using proper string comparison.


73-94: LGTM! Properties validation test appropriately checks expected properties.

The test correctly validates that properties are generated and specifically checks for the "type" property, which is expected from the inheritance hierarchy.


96-118: LGTM! Detailed type property validation is thorough.

The test provides comprehensive validation of the type property including its name, value type, occurrence, and RDF property definition URI, ensuring proper OSLC compliance.


120-138: LGTM! Getter method filtering validation is appropriate.

The test correctly verifies that only getter methods are processed by the ResourceShapeFactory, confirming the expected behavior of filtering out setter methods and other non-getter methods.

@codecov
Copy link

codecov bot commented Aug 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.76%. Comparing base (3b092aa) to head (208f23a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #389      +/-   ##
==========================================
+ Coverage   49.55%   50.76%   +1.20%     
==========================================
  Files         166      166              
  Lines       15388    15391       +3     
  Branches     1024     1024              
==========================================
+ Hits         7626     7813     +187     
+ Misses       7479     7271     -208     
- Partials      283      307      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@berezovskyi
Copy link
Member

berezovskyi commented Aug 15, 2025

Thanks for the PR, @ZUOXIANGE!

I am away from a computer for a week or so - reviewing from phone.

First, a question: do the tests fail if we comment out your new mapping entry? I did not see Uri collections tested explicitly.

Second, I think it would be better to map all collection types in a consistent way - did you check how other backing types than ICollection are handled? E.g. List<Uri>, HashSet<Uri>, Uri[]? There a bit of Java-style legacy code (most of the code was written by IBMers between 2009-2013 and I started actively maintaining the lib and to bring into .NET 5+ since late 2023) that only works well with those concrete types and not with the high-level interfaces (I only started it recently in #322). See ExtractTypeInformation() in the DotNetRdfHelper class that I introduced.

Third, I started adding support in #322 for props like ImplementedBy instead of GetImplementedBy and SetImplementedBy. I think I missed to update resource shape handling for that. Would be nice to handle that too but we can file a separate issue for that if it is too much work in this PR.

Finally, we want to be careful with mapping ICollection to Uri* because there are other ways in RDF for representing collections other than repeating a prop multiple times (see https://ontola.io/blog/ordered-data-in-rdf) but we don't need to worry about this now unless you are modifying code that handles that conversion.

P.S. Please update XMLDOC comments to be in English only - see good suggestions from Coderabbit for that under Nitpick Comments.

@ZUOXIANGE
Copy link
Author

While creating the ResourceShape for Requirements, I encountered a KeyNotFoundException that required immediate attention to keep our development pipeline unblocked. I've implemented a temporary fix by adding the necessary code to resolve this specific scenario. I'd greatly appreciate your expertise in reviewing these changes to ensure they align with the project's architectural standards.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (6)
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (6)

1-5: Organize imports according to C# conventions.

The using directives should be organized with System namespaces first, followed by third-party libraries, then project namespaces. Additionally, there's a missing using System.Linq; import that's required for LINQ operations used throughout the file.

+using System;
+using System.Linq;
 using OSLC4Net.Core.Model;
 using OSLC4Net.Core.Attribute;
 using OSLC4Net.Domains.RequirementsManagement;
 using Xunit;

14-31: Simplify test to focus on single responsibility.

This test validates multiple aspects of the resource shape (non-null checks and URI construction). Consider splitting into focused tests or removing redundant assertions since the URI construction is already validated separately.

 [Fact]
-public void CreateResourceShape_WithRequirementType_ShouldReturnValidResourceShape()
+public void CreateResourceShape_WithRequirementType_ShouldReturnNonNullResourceShape()
 {
     // Arrange
     var resourceType = typeof(Requirement);

     // Act
     var resourceShape = ResourceShapeFactory.CreateResourceShape(
         BaseUri,
         ResourceShapesPath,
         ResourceShapePath,
         resourceType);

     // Assert
     Assert.NotNull(resourceShape);
-    Assert.NotNull(resourceShape.GetAbout());
-    Assert.Equal($"{BaseUri}/{ResourceShapesPath}/{ResourceShapePath}", resourceShape.GetAbout().ToString());
 }

133-135: Test assertion may be too brittle.

Using Assert.Single(properties) assumes exactly one property will always be present. This could break if the Requirement class gains additional OSLC properties. Consider using a more specific assertion.

-Assert.Single(properties);
-Assert.Equal("type", properties[0].GetName());
+var typeProperties = properties.Where(p => p.GetName() == "type").ToList();
+Assert.Single(typeProperties);
+Assert.Equal("type", typeProperties[0].GetName());

298-332: Clean up commented code or document test intent.

This test contains extensive commented-out assertions which makes it unclear whether this is work-in-progress or intentionally demonstrates unsupported functionality. The comment on Line 298-299 suggests this is intentional, but the commented code should either be removed or properly documented.

 // Note: ResourceShapeFactory only supports getter/setter methods, not direct properties
-// Direct property pattern is not supported by ResourceShapeFactory
+// This test verifies that direct property patterns are NOT supported by ResourceShapeFactory
 [Fact]
-public void CreateResourceShape_WithISetUriProperty_ShouldMapToResourceValueType()
+public void CreateResourceShape_WithISetUriDirectProperty_ShouldNotMapProperty()
 {
     // Arrange
     var resourceType = typeof(TestResourceWithISetUri);

     // Act
     var resourceShape = ResourceShapeFactory.CreateResourceShape(
         BaseUri,
         ResourceShapesPath,
         ResourceShapePath,
         resourceType);

     // Assert
+    // Direct properties are not supported - only getter/setter method patterns
     var properties = resourceShape.GetProperties();
     var uriSetProperty = properties.FirstOrDefault(p => p.GetName() == "uriSet");

     Assert.Null(uriSetProperty);
-    //Assert.Equal("uriSet", uriSetProperty.GetName());
-
-    //var actualValueType = uriSetProperty.GetValueType();
-    //var actualOccurs = uriSetProperty.GetOccurs();
-
-    //Assert.NotNull(actualValueType);
-    //Assert.NotNull(actualOccurs);
-
-    //var expectedValueTypeUri = new Uri(ValueTypeExtension.ToString(OSLC4Net.Core.Model.ValueType.Resource));
-    //var expectedOccursUri = new Uri(OccursExtension.ToString(OSLC4Net.Core.Model.Occurs.ZeroOrMany));
-
-    //Assert.Equal(expectedValueTypeUri, actualValueType);
-    //Assert.Equal(expectedOccursUri, actualOccurs);
-    //Assert.Equal("http://example.com/uriSet", uriSetProperty.GetPropertyDefinition()?.ToString());
 }

392-392: Remove unnecessary 'this' qualifier.

The this qualifier is redundant when there's no naming conflict.

-this._uriCollection = uriCollection;
+_uriCollection = uriCollection;

421-421: Use more readable array initialization.

The current initialization new Uri[0] can be replaced with the more readable Array.Empty<Uri>() for better intent clarity.

-private Uri[] _uriArray = new Uri[0];
+private Uri[] _uriArray = Array.Empty<Uri>();
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e9042f1 and 427b216.

📒 Files selected for processing (2)
  • OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs (1 hunks)
  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

⚙️ CodeRabbit Configuration File

**/*.cs: Review the C# code against the Microsoft Framework design guidelines as well as 10 guidelines
from "Building Maintainable Software" by Joost Visser. Point out deviations and improvements.

Files:

  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs
🧬 Code Graph Analysis (1)
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (4)
OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs (5)
  • ResourceShapeFactory (26-513)
  • ResourceShapeFactory (38-59)
  • ResourceShapeFactory (61-63)
  • ValueType (349-359)
  • Occurs (371-381)
OSLC4Net_SDK/OSLC4Net.Domains.RequirementsManagement/Constants.cs (1)
  • RM (27-77)
OSLC4Net_SDK/OSLC4Net.Core/Model/ValueType.cs (1)
  • ValueTypeExtension (59-88)
OSLC4Net_SDK/OSLC4Net.Core/Model/Occurs.cs (1)
  • OccursExtension (38-67)
🔇 Additional comments (5)
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (5)

8-13: LGTM! Well-structured test class.

The class structure follows good testing practices with clear constants and descriptive naming conventions.


68-68: Use StringComparison.Ordinal consistently.

Good practice using StringComparison.Ordinal for URI comparisons to avoid culture-specific issues.


187-194: Excellent pattern for URI comparison validation.

This test properly handles the fact that GetValueType() and GetOccurs() return URIs by using the extension methods to get expected URI values for comparison. This pattern should be applied consistently across all similar tests.


337-362: Verify correct OSLC attribute usage pattern.

The test class uses proper OSLC attributes and follows the getter/setter pattern correctly. The implementation properly handles null arrays and uses ISet<Uri> internally while exposing Uri[] externally, which is a common pattern for OSLC properties.


138-159: ResourceShapeFactory: Collection type mappings validated

  • Confirmed that ResourceShapeFactory registers ICollection<Uri>, IEnumerable<Uri>, and ISet<Uri> in its TYPE_TO_VALUE_TYPE dictionary, all mapping to ValueType.Resource.
  • ResourceShapeFactoryTests include coverage for each of these collection types—verifying both the mapped value type and the occurrences setting.

No further action needed.

Assert.NotNull(properties);
Assert.NotEmpty(properties);

var propertyNames = properties.Select(p => p.GetName()).ToList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Missing using directive causes compilation error.

The ToList() method requires using System.Linq; which is missing from the imports.

Add the missing using directive at the top of the file:

+using System.Linq;
🤖 Prompt for AI Agents
In OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs around
line 89, the call to ToList() on the LINQ projection requires the System.Linq
namespace which is not imported; add a using System.Linq; directive to the top
of the file alongside the other using statements so the extension methods like
Select and ToList are available and the file compiles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants