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

Restore basic assertions for collections in System.Data #1812

Merged
merged 36 commits into from Apr 16, 2022

Commits on Apr 15, 2022

  1. Updated AssertionExtensions.cs with overloads to pass calls to .Shoul…

    …d() on DataTableCollection, DataColumnCollection and DataRowCollection into GenericCollectionAssertions using LINQ's .Cast<T>() method.
    
    Added type DataTableCollectionAssertionExtensions.cs with assertions specific to DataTableCollection as extensions on GenericCollectionAssertions<DataTable>.
    Added type DataColumnCollectionAssertionExtensions.cs with assertions specific to DataColumnCollection as extensions on GenericCollectionAssertions<DataColumn>.
    Added type DataRowCollectionAssertionExtensions.cs with assertions specific to DataRowCollection as extensions on GenericCollectionAssertions<DataRow>.
    Reran AcceptApiChanges.ps1 to update the approved API surface.
    Added automated tests of DataTableCollectionAssertionExtensions in new class Collections/Data/DataTableCollectionAssertionExtensionsSpecs.cs in FluentAssertions.Specs.
    Added automated tests of DataColumnCollectionAssertionExtensions in new class Collections/Data/DataColumnCollectionAssertionExtesnionsSpecs.cs in FluentAssertions.Specs.
    Added automated tests of DataRowCollectionAssertionExtensions in new class Collections/Data/DataRowCollectionAssertionExtensionsSpecs.cs in FluentAssertions.Specs.
    Added documentation of the new methods to docs/_pages/data.md.
    Added a corresponding line to the release notes in docs/_pages/releases.md.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    e5edaec View commit details
    Browse the repository at this point in the history
  2. Added type NonGenericCollectionWrapper.cs in FluentAssertions/Common.…

    … This ensures that the Count property is passed through to the underlying implementation, and also allows code that knows about it to directly access the wrapped collection object.
    
    Updated AssertionExtensions.c to use NonGenericCollectionWrapper instead of System.Linq's .Cast<TItem> to produce the generic collections for use with GenericCollectionAssertions<TItem> in Should overloads for DataTableCollection, DataColumnCollection and DataRowCollection.
    Updated the ContainTableWithName methods in DataTableCollectionAssertionExtensions.cs and ContainColumnWithName in DataColumnCollectionAssertionExtensions.cs to check if the assertion subject is a NonGenericCollectionWrapper and, if so, use it to gain access to the underlying Contains functionality rather than requiring the collection to be enumerated.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    96050a7 View commit details
    Browse the repository at this point in the history
  3. Corrected a copy/paste error in the XML docs in DataRowCollectionAsse…

    …rtionExtensions.cs.
    
    Added BeSameAs and NotBeSameAs extension methods in DataTableCollectionAssertionExtensions, DataColumnCollectionAssertionExtensions and DataRowCollectionAssertionExtensions, since the default ReferenceTypeAssertions implementation is broken by the NonGenericCollectionWrapper wrapping.
    Added automated tests of the new functionality.
    Reran AcceptApiChanges.ps1.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    c2012c6 View commit details
    Browse the repository at this point in the history
  4. PR feedback:

    - Improved the wording of XML documentation of .Should() for DataTableCollection, DataColumnCollection and DataRowCollection.
    - Moved DataTableCollectionAssertionExtensions.cs, DataColumnCollectionAssertionExtensions.cs and DataRowCollectionAssertionExtensions.cs to the project root.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    19966f6 View commit details
    Browse the repository at this point in the history
  5. Rewrote HaveSameCount and NotHaveSameCount in DataTableCollectionAsse…

    …rtionExtensions.cs, DataColumnCollectionAssertionExtensions.cs and DataRowCollectionAssertionExtensions.cs to use fluent assertion execution syntax.
    
    Updated automatde tests correspondingly, ensuring coverage.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    9d81c22 View commit details
    Browse the repository at this point in the history
  6. Generalized the implementations of HaveSameCount and NotHaveSameCount…

    … in DataTableCollectionAssertionExtensions.cs, DataColumncollectionAssertionExtensions.cs and DataRowCollectionAssertionExtensions.cs to operate on ICollection<T> instead of NonGenericCollectionWrapper<TCollection, T> specifically.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    20da350 View commit details
    Browse the repository at this point in the history
  7. Simplified the implementation of HaveSameCount and NotHaveSameCount i…

    …n DataTableCollectionAssertionExtensions.cs, DataColumnCollectionAssertionExtensions.cs and DataRowCollectionAssertionExtensions.cs, following the observation that IEnumerable<T>.Count() in LINQ actually already contains logic to pass the call through to ICollection<T>.Count if the subject implements that interface. Since NonGenericCollectionWrapper<TCollection, T> implements this interface, this meets our needs in avoiding having the underlying collection be enumerated.
    
    Updated tests correspondingly, removing checks for a subtle semaphore that was used to allow the tests to verify which branch in the HaveSameCount / NotHaveSameCount implementation had been taken. This is no longer needed and is no longer present.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    0617267 View commit details
    Browse the repository at this point in the history
  8. PR feedback related to DataTableCollectionAssertionExtensions.cs, Dat…

    …aColumnCollectionAssertionExtensions.cs and DataRowCollectionAssertions.cs:
    
    - Renamed expected to expectation in several places. Reran AcceptApiChanges.ps1.
    - Updated calls to FailWith to directly specify collection identifier instead of using WithDefaultIdentifier.
    - Improved XML documentation for assertions.
    - Added assertions on the null ugard in BeSubsetOf and NotBeSubsetOf for DataRowCollectionAssertions.cs.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    aac8378 View commit details
    Browse the repository at this point in the history
  9. Restructured assertions in DataTableCollectionAssertionExtensionsSpec…

    …s.cs, DataColumnCollectionAssertionExtensionsSpecs.cs and DataRowCollectionAssertionExtensionsSpecs.cs to use nested subclasses, and substantially simplified all of the test method names since they are in different namespaces now.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    baa0c96 View commit details
    Browse the repository at this point in the history
  10. Updated all System.Data collection specs to ensure that the exception…

    … that was thrown is actually the expected error.
    
    Updated a few .FailWith calls to include additional wording to make the message clearer.
    Added guards to BeSubsetOf and NotBeSubsetOf overloads in DataRowCollectionAssertionExtension.cs that then proceed to call a LINQ method on the supplied expectation.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    a4a7fea View commit details
    Browse the repository at this point in the history
  11. Eliminated explicit type names from test names in DataTableCollection…

    …AssertionExtensionsSpecs.cs, DataColumnCollectionAssertionExtensionSpecs.cs and DataRowCollectionAssertionExtensionsSpecs.cs with judicious use of nested classes.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    8eafbce View commit details
    Browse the repository at this point in the history
  12. Reverted partial renaming of "expected" to "expectation".

    Reran AcceptApiChanges.ps1.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    f638849 View commit details
    Browse the repository at this point in the history
  13. Updated BeSameAs assertions in DataTableCollectionAssertionExtensions…

    ….cs, DataColumnCollectionAssertionExtensions.cs and DataRowCollectionAssertionExtensions.cs to provide different failure messages for different paths. Corrected a format string error in the generic collection path ("{1}" when there was only one formatting argument).
    
    Added tests to DataTableCollectionAssertionExtensionsSpecs.cs, DataColumnCollectionAssertionExtensionsSpecs.cs and DataRowCollectionAssertionExtensionsSpecs.cs to verify that the path for subjects that aren't System.Data collections is in fact needed & gets hit.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    5ba6b84 View commit details
    Browse the repository at this point in the history
  14. PR feedback:

    - Corrected a typo "Expeected" in DataTableCollectionAssertionExtensions.cs and DataColumnAssertionExtensions.cs.
    - Updated the construction of NonGenericCollectionWrapper to use a helper method that returns null instead of wrapping null. Added a helper method for each System.Data type to NonGenericCollectionWrapper.cs.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    373f5fc View commit details
    Browse the repository at this point in the history
  15. Added a null argument guard to the constructor of NonGenericCollectio…

    …nWrapper<TCollection, TItem>.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    28cc3cf View commit details
    Browse the repository at this point in the history
  16. Excised set operations from DataRowCollectionAssertionExtensions.cs a…

    …nd the corresponding tests from DataRowCollectionAssertionExtensionsSpecs.cs.
    
    Reran AcceptApiChanges.ps1.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    a9a1702 View commit details
    Browse the repository at this point in the history
  17. Copy the full SHA
    7e13fe0 View commit details
    Browse the repository at this point in the history
  18. Copy the full SHA
    aeb21fb View commit details
    Browse the repository at this point in the history
  19. Removed ContainEquivalentOf and NotContainEquivalentOf from DataRowCo…

    …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.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    63f61e6 View commit details
    Browse the repository at this point in the history
  20. Corrected assertion failure messages for BeSameAs in DataTableCollect…

    …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.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    182f514 View commit details
    Browse the repository at this point in the history
  21. Excised custom Contain and NotContain (by name) from DataTableCollect…

    …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.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    1996730 View commit details
    Browse the repository at this point in the history
  22. Added tests that cover the situation where the subject is null to Dat…

    …aTableCollectionAssertionExtensionsSpecs.cs, DataColumnCollectionAssertionExtensionsSpecs.cs and DataRowCollectionAssertionExtensionSpecs.cs.
    
    Corrected indentation error in DataRowCollectionAssertionExtensions.cs.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    b7f2133 View commit details
    Browse the repository at this point in the history
  23. Unrolled loops in DataTableCollectionAssertionExtensionsSpecs.cs, Dat…

    …aColumnCollectionAssertionExtensionsSpecs.cs and DataRowCollectionAssertionExtensionsSpecs.cs.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    f496362 View commit details
    Browse the repository at this point in the history
  24. Simplified tests in DataTableCollectionAssertionExtensionsSpecs.cs an…

    …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.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    3e67266 View commit details
    Browse the repository at this point in the history
  25. Removed some additional unnecessary test subject set-up from DataRowC…

    …ollectionAssertionExtensionsSpecs.cs.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    c3423a6 View commit details
    Browse the repository at this point in the history
  26. Eliminated helper functions in the construction of subject and expect…

    …ation DataTables in DataTableCollectionAssertionExtensionsSpecs.cs and DataRowCollectionAssertionExtensionsSpecs.cs.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    316b34a View commit details
    Browse the repository at this point in the history
  27. Added additional tests to DataTableCollectionAssertionExtensionsSpecs…

    ….cs so that the DataSet overloads are covered.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    727bf0e View commit details
    Browse the repository at this point in the history
  28. Copy the full SHA
    16e3e0d View commit details
    Browse the repository at this point in the history
  29. PR review suggestions:

    - Removed unnecessary references to IEnumerable and IEnumerable<T>, already covered by implementing/constraining against ICollection and ICollection<T>.
    - Made UnderlyingCollection in ReadOnlyNonGenericCollectionWrapper<T> immutable.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    68ac311 View commit details
    Browse the repository at this point in the history
  30. Renamed DataTableCollectionAssertionExtensionsSpecs.cs to DataTableCo…

    …llectionAssertionSpecs.cs.
    
    Renamed DataColumnCollectionAssertionExtensionsSpecs.cs to DataColumnCollectionAssertionSpecs.cs.
    Renamed DataRowCollectionAssertionExtensionsSpecs.cs to DataRowCollectionAssertionSpecs.cs.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    13dfbda View commit details
    Browse the repository at this point in the history
  31. Added utility class TypeDescriptionUtility.cs, along with unit tests …

    …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.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    6ee1de2 View commit details
    Browse the repository at this point in the history
  32. Changed direct InvalidOperationException in BeSameAs and NotBeSameAs …

    …in DataTableCollectionAssertionExtensions.cs, DataColumnCollectionAssertionExtensions.cs and DataRowCollectionAssertionExtensions.cs into a standard assertion flow.
    
    Updated unit tests correspondingly.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    1c3f552 View commit details
    Browse the repository at this point in the history
  33. Undid the refactoring of FailWith in AssertionScope.cs that produced …

    …an internal method FormatFailureMessage to allow reuse.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    897f353 View commit details
    Browse the repository at this point in the history
  34. Made TypeDescriptionUtility.GetTypeDescription non-discoverable, as n…

    …othing _currently_ has a need to get a description for a Type directly.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    791e8af View commit details
    Browse the repository at this point in the history
  35. Moved TypeDescriptionUtility to the Common folder/namespace. Updated …

    …the TypeDescriptionUtilitySpecs.cs class correspondingly. All actual uses of TypeDescriptionUtility already import this namespace so no other changes are needed.
    logiclrd committed Apr 15, 2022
    Copy the full SHA
    02e0679 View commit details
    Browse the repository at this point in the history
  36. Copy the full SHA
    8c879bf View commit details
    Browse the repository at this point in the history