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
Restore basic assertions for collections in System.Data
Restore basic assertions for collections in System.Data
#1812
Conversation
Wow. Wasn't it easier to use |
We already have a suite of tests which I'd prefer to touch only if strictly necessary, and using |
The new assertions types and corresponding tests are very closely based on the existing collections assertion code; this is not created out of whole cloth, but out of copy/pasting the existing code and then massaging it to the types in question. :-) |
Sorry, what I meant is that your new |
Mm, that would provide part of the functionality. But, it wouldn't have things like |
Of course, there's no pre-existing code calling those methods. But given all the other System.Data-specific sets of assertions, this seemed the logical way to do it. Casting the collection and using |
You could provide those as an extension method on It's more to avoid too much duplication and maintenance on our side. |
Hmm, that's true :-) I'll investigate that. |
One thing with that approach is that after |
Is that a real issue? How many tables does a data set typically contain? I guess 50 is already quite a lot. |
In it's current state I think this is duplicating too much functionality. |
@dennisdoomen That's true... Is there no other situation where the loss of the subject type would be an issue? |
Have the exact same feeling. In retrospect, we should have decided to make it a supporting library that is maintained by others. |
Can't think of anything right now. |
9f478c6
to
f579d96
Compare
I was hoping to get this in before the end of your day, but it was just too late for me. :-) Here's a rewrite that leverages |
While looking at the implementation and thinking of the repercussions of us maintaining this, I thought of another solution:
Then this wrapper delegates properties like Since |
That sounds promising! I'll give that a go. |
Hmm, one problem: The non-generic |
Huh, I think Visual Studio must have been acting up. IntelliSense was initially telling me that the non-generic interfaces didn't expose a But, I kept poking at it because this didn't make sense to me and suddenly |
68c839e
to
a93a59b
Compare
There, I think that commit is what you had in mind, and it solves the problem elegantly. Thank you :-) |
What if you used |
The problem is more fundamental -- the |
Fair enough. Let us know when you're ready for the formal review ;-) |
I don't think I have anything outstanding on my end at this point. |
Some general notes before I can continue the review:
- I suspect a lot of the methods on the new extension classes are no longer needed
- The unit tests need to be updated to take into account some of the comments we had on #1807
Src/FluentAssertions/Data/Extensions/DataColumnCollectionAssertionExtensions.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Data/Extensions/DataColumnCollectionAssertionExtensions.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Data/Extensions/DataColumnCollectionAssertionExtensions.cs
Outdated
Show resolved
Hide resolved
It's a big enhancement, albeit quite niche, so there is a lot of work to be done to finish this. I hope you're up for it.
FYI, just assume that my code review comment apply to all other code as well, so please be thorough.
Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs
Outdated
Show resolved
Hide resolved
Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionExtensionsSpecs.cs
Outdated
Show resolved
Hide resolved
Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionExtensionsSpecs.cs
Outdated
Show resolved
Hide resolved
Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionExtensionsSpecs.cs
Outdated
Show resolved
Hide resolved
…llectionAssertionExtensions.cs, as their implementation is actually identical to that in GenericCollectionAssertions. Reran AcceptApiChanges.ps1. Added tests to DataRowCollectionAssertionExtensionsSpecs.cs to verify that ContainEquivalentOf and NotContainEquivalentOf do the right thing with DataRow objects & collections.
…ionAssertionExtensions.cs, DataColumnCollectionAssertionExtensions.cs and DataRowCollectionAssertionExtensions.cs. Removed unnecessary calls to .ForCondition(false). Removed unnecessary cast from IEnumerable<DataRow> to IEnumerable<object> in ContainEquivalentOf in DataRowCollectionAssertionExtensions.cs. Updated ContainEquivalentOf in DataRowCollectionAssertions.cs to return an AndWhichConstraint.
…ionAssertionExtensions.cs and DataColumnCollectionAssertionExtensions.cs and the corresponding tests from DataTableCollectionAssertionExtensionsSpecs.cs and DataColumnCollectionAssertionExtensionsSpecs.cs. Reran AcceptApiChanges.ps1. Removed documentation for Contain and NotContain (by name) operations from data.md.
…aTableCollectionAssertionExtensionsSpecs.cs, DataColumnCollectionAssertionExtensionsSpecs.cs and DataRowCollectionAssertionExtensionSpecs.cs. Corrected indentation error in DataRowCollectionAssertionExtensions.cs.
…aColumnCollectionAssertionExtensionsSpecs.cs and DataRowCollectionAssertionExtensionsSpecs.cs.
…d DataColumnCollectionAssertionExtensionsSpecs.cs. Since the tests don't actually look at the column specifications, it isn't important that they be assigned a variety of different types.
…ollectionAssertionExtensionsSpecs.cs.
…ation DataTables in DataTableCollectionAssertionExtensionsSpecs.cs and DataRowCollectionAssertionExtensionsSpecs.cs.
….cs so that the DataSet overloads are covered.
- Removed unnecessary references to IEnumerable and IEnumerable<T>, already covered by implementing/constraining against ICollection and ICollection<T>. - Made UnderlyingCollection in ReadOnlyNonGenericCollectionWrapper<T> immutable.
…llectionAssertionSpecs.cs. Renamed DataColumnCollectionAssertionExtensionsSpecs.cs to DataColumnCollectionAssertionSpecs.cs. Renamed DataRowCollectionAssertionExtensionsSpecs.cs to DataRowCollectionAssertionSpecs.cs.
…in TypeDescriptionUtilitySpecs.cs. Refactored AssertionScope.FailWith to produce new utility method AssertionScope.FormatFailureMessage. Updated DataTableCollectionAssertionExtensions.cs, DataColumnCollectionAssertionExtensions.cs and DataRowCollectionAssertionExtensions.cs to throw InvalidOperationException when BeSameAs or NotBeSameAs is called with a subject of the wrong type, using the new AssertionScope.FormatFailureMessage method to give the exception an appropriate message. Updated DataTableCollectionAssertionSpecs.cs, DataColumnCollectionAssertionSpecs.cs and DataRowCollectionAssertionSpecs.cs to account for the change in the exception type & message in the When_generic_collection_is_tested_against_typed_collection_it_should_fail test methods.
…in DataTableCollectionAssertionExtensions.cs, DataColumnCollectionAssertionExtensions.cs and DataRowCollectionAssertionExtensions.cs into a standard assertion flow. Updated unit tests correspondingly.
…an internal method FormatFailureMessage to allow reuse.
…othing _currently_ has a need to get a description for a Type directly.
…the TypeDescriptionUtilitySpecs.cs class correspondingly. All actual uses of TypeDescriptionUtility already import this namespace so no other changes are needed.
d2076fd
to
8c879bf
Compare
(rebased to resolve |
Sorry for the delayed review.
I gave it another look and it looks good.
System.Data
In anticipation of the new functionality to allow excluding non-browsable fields (#1807), I updated our project to the latest published version and discovered that about 9 months ago, assertions on non-generic collections were removed from FluentAssertions. Unfortunately,
DataSet
andDataTable
were codified before generics existed and have only non-generic collections. As such, assertions on these collections depended on the existing blanket non-generic collection functionality. With this removed, our test suite no longer compiles because of assertions such as,This PR addresses this issue by wrapping the three collections involved in System.Data in a class that implements
IEnumerable<T>
, so that the assertions inGenericCollectionAssertions<T>
can apply. In addition, some additional assertions are provided that take System.Data types as arguments.This PR also includes updates to the release notes and documentation, as well as comprehensive automated testing of the new functionality.
IMPORTANT