Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

New Post: CollectionPropertyAssertions

$
0
0

Here is the best "solution" I came to. First, we split ShouldHave methods:

public static IPropertyAssertions<T> ShouldHave<T>(this T subject)
{
    return new PropertyAssertions<T>(subject);
}

public static IPropertyAssertions<T> ShouldHave<T>(this IEnumerable<T> subject)
{
    return new CollectionPropertyAssertions<T>(subject);
}

Then try to use them:

var collection1 = new List<Customer>(); //first overload is chosen
List<Customer> collection2 = new List<Customer>(); //first overload is chosen
IEnumerable<Customer> collection3 = new List<Customer>(); //second overload is chosen
Unfortunately C# chooses first overload in first two cases, but it chooses the second if you explicitly specify IEnumerable<Customer> type. So it is possible to implement full-featured generic CollectionPropertyAssertions but library users will have to specify collection type explicitly. What do you think about this "solution"?

Viewing all articles
Browse latest Browse all 1402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>