Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Maps by Type #214

Merged
merged 3 commits into from
Sep 3, 2024
Merged

Get Maps by Type #214

merged 3 commits into from
Sep 3, 2024

Conversation

moxplod
Copy link
Contributor

@moxplod moxplod commented Aug 31, 2024

Description

Added a method in mapper to return the maps by type. This can be used to define custom value convertors by the caller.

Discussion - #213
Related issue - #211

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works
  • I have made corresponding changes to the documentation
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes

Copy link

what-the-diff bot commented Aug 31, 2024

PR Summary

  • Introduction of new method 'GetCurrentMapsByType' in 'GridifyMapper.cs'
    This update introduces a fresh method that gives you the capacity to retrieve the current mappings based on the types of targets you have.

  • New methods in 'IGridifyMapper.cs'
    Two new methods named 'GetCurrentMapsByType()' and 'GetCurrentMapsByType(HashSet targetTypes)' have been added to the 'IGridifyMapper.cs'. These provide more variety and flexibility in obtaining the current mappings based on target types.

  • Added unit test 'GetMappingByType'
    A new unit test method called 'GetMappingByType' has been included in the 'GridifyMapperShould.cs'. This addition is valuable as it allows for thorough testing of the 'GetCurrentMapsByType' method within the 'GridifyMapper.cs', ensuring its functionality and reliability.

yield return map;
}
}
// TODO: need to implement other types that aren't unary expression
Copy link
Owner

Choose a reason for hiding this comment

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

This needs to be completed to support and test all types; currently, it only works with unary expressions. Adding a couple of additional unit tests for known dotnet types and a few custom types is also required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ppdated the method a bit further, I am not sure what other types of expressions are out there. Where can I find the list?

Probably my lack of depth in understanding expressions. This approach isn't looking so hot anymore, where we have to figure out each expression type to find the property type.

Copy link
Owner

Choose a reason for hiding this comment

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

Handling all types of expressions isn't necessary; I believe these three cover at least 80% of the types, and so far, it looks very promising. Perhaps we should consider adding another test case to determine if we can support custom types. Lastly, the PR seems fine, but the documentation needs to be updated.

Copy link
Owner

@alirezanet alirezanet left a comment

Choose a reason for hiding this comment

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

Looks good,
Just documentation, and if you have time more tests with other types

@@ -149,8 +149,31 @@ public void AddMap_DuplicateKey_ShouldThrowErrorIfOverrideIfExistsIsFalse()
//The thrown exception can be used for even more detailed assertions.
Assert.Equal("Duplicate Key. the 'test' key already exists", exception.Message);
}

[Theory]
[InlineData(typeof(DateTime), 0)]
Copy link
Owner

Choose a reason for hiding this comment

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

one improvement would be to add a test case that has a DateTime ... false test is not so useful

Copy link
Owner

@alirezanet alirezanet Aug 31, 2024

Choose a reason for hiding this comment

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

one other thing that I just remembered is nested mappings... does it work with nested ones? Additionally, we should verify mappings that utilize a Select method for collections. It's crucial to conduct further testing prior to proceeding with a merge.

@alirezanet alirezanet merged commit 4eccf13 into alirezanet:master Sep 3, 2024
3 checks passed
@moxplod moxplod deleted the get_maps_type branch September 3, 2024 14:23
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