Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added base type NonGenericCollectionWrapperBase in FluentAssertions/D…
…ata/Wrappers and three subclasses DataTableCollectionWrapper, DataRowCollectionWrapper and DataColumnCollectionWrapper. These ensure that the Count property is passed through to the underlying implementation, and also allow code that knows about them to directly access the wrapped collection object. Updated AssertionExtensions.c to use DataTableCollectionWrapper, DataColumnCollectionWrapper and DataRowCollectionWrapper instead of System.Linq's .Cast<TItem> to produce generic collections for use with GenericCollectionAssertions<TItem> in Should overloads for DataTableCollection, DataColumnCollection and DataRowCollection. Updated DataTableCollectionAssertionExtensions.cs and DataColumnCollectionAssertionExtensions.cs to check if the assertion subject is a DataTableCollectionWrapper or DataColumnCollectionWrapper, respectively, so that existence of the member can be tested with the underlying Contains functionality rather than requiring the collection to be enumerated.
- Loading branch information
Showing
7 changed files
with
141 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Src/FluentAssertions/Data/Wrappers/DataColumnCollectionWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Data; | ||
|
||
namespace FluentAssertions.Data.Wrappers | ||
{ | ||
internal class DataColumnCollectionWrapper : NonGenericCollectionWrapperBase<DataColumnCollection, DataColumn> | ||
{ | ||
public DataColumnCollectionWrapper(DataColumnCollection collection) | ||
: base(collection) | ||
{ | ||
} | ||
|
||
public override int Count => UnderlyingCollection.Count; | ||
|
||
public bool Contains(string columnName) => UnderlyingCollection.Contains(columnName); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Src/FluentAssertions/Data/Wrappers/DataRowCollectionWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Data; | ||
|
||
namespace FluentAssertions.Data.Wrappers | ||
{ | ||
internal class DataRowCollectionWrapper : NonGenericCollectionWrapperBase<DataRowCollection, DataRow> | ||
{ | ||
public DataRowCollectionWrapper(DataRowCollection collection) | ||
: base(collection) | ||
{ | ||
} | ||
|
||
public override int Count => UnderlyingCollection.Count; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Src/FluentAssertions/Data/Wrappers/DataTableCollectionWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Data; | ||
|
||
namespace FluentAssertions.Data.Wrappers | ||
{ | ||
internal class DataTableCollectionWrapper : NonGenericCollectionWrapperBase<DataTableCollection, DataTable> | ||
{ | ||
public DataTableCollectionWrapper(DataTableCollection collection) | ||
: base(collection) | ||
{ | ||
} | ||
|
||
public override int Count => UnderlyingCollection.Count; | ||
|
||
public bool Contains(string tableName) => UnderlyingCollection.Contains(tableName); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
Src/FluentAssertions/Data/Wrappers/NonGenericCollectionWrapperBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace FluentAssertions.Data.Wrappers | ||
{ | ||
internal abstract class NonGenericCollectionWrapperBase<TCollection, TItem> : ICollection<TItem>, IEnumerable<TItem> | ||
where TCollection : ICollection, IEnumerable | ||
{ | ||
public TCollection UnderlyingCollection { get; private set; } | ||
|
||
public NonGenericCollectionWrapperBase(TCollection collection) | ||
{ | ||
UnderlyingCollection = collection; | ||
} | ||
|
||
public abstract int Count { get; } | ||
|
||
public bool IsReadOnly => true; | ||
|
||
public IEnumerator<TItem> GetEnumerator() => UnderlyingCollection.Cast<TItem>().GetEnumerator(); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => UnderlyingCollection.GetEnumerator(); | ||
|
||
public virtual bool Contains(TItem item) => UnderlyingCollection.Cast<TItem>().Contains(item); | ||
|
||
public void CopyTo(TItem[] array, int arrayIndex) => UnderlyingCollection.CopyTo(array, arrayIndex); | ||
|
||
// Mutation is not supported, but these methods must be implemented to satisfy ICollection<T>: | ||
// * Add | ||
// * Clear | ||
// * Remove | ||
|
||
public void Add(TItem item) => throw new NotSupportedException(); | ||
|
||
public void Clear() => throw new NotSupportedException(); | ||
|
||
public bool Remove(TItem item) => throw new NotSupportedException(); | ||
} | ||
} |