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

Make it possible for third-party libraries to access the underlying collection of instances of ReadOnlyNonGenericCollectionWrapper #1968

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions Src/FluentAssertions/Common/ICollectionWrapper.cs
@@ -0,0 +1,15 @@
using System.Collections;

namespace FluentAssertions.Common
{
/// <summary>
/// Used to provide access to the underlying <typeparamref name="TCollection"/> for an object that wraps an underlying
/// collection.
/// </summary>
/// <typeparam name="TCollection">Collection type.</typeparam>
public interface ICollectionWrapper<TCollection>
where TCollection : ICollection
{
TCollection UnderlyingCollection { get; }
}
}
Expand Up @@ -33,7 +33,7 @@ internal static class ReadOnlyNonGenericCollectionWrapper
}
}

internal class ReadOnlyNonGenericCollectionWrapper<TCollection, TItem> : ICollection<TItem>
internal class ReadOnlyNonGenericCollectionWrapper<TCollection, TItem> : ICollection<TItem>, ICollectionWrapper<TCollection>
where TCollection : ICollection
{
public TCollection UnderlyingCollection { get; }
Expand Down
Expand Up @@ -30,7 +30,7 @@ public static class DataColumnCollectionAssertionExtensions
Guard.ThrowIfArgumentIsNull(
expected, nameof(expected), "Cannot verify same reference against a <null> collection (use BeNull instead?).");

if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper<DataColumnCollection, DataColumn> wrapper)
if (assertion.Subject is ICollectionWrapper<DataColumnCollection> wrapper)
{
var actualSubject = wrapper.UnderlyingCollection;

Expand Down
Expand Up @@ -635,6 +635,11 @@ namespace FluentAssertions.Common
System.Threading.Tasks.Task DelayAsync(System.TimeSpan delay, System.Threading.CancellationToken cancellationToken);
FluentAssertions.Common.ITimer StartTimer();
}
public interface ICollectionWrapper<TCollection>
where TCollection : System.Collections.ICollection
{
TCollection UnderlyingCollection { get; }
}
public interface IConfigurationStore
{
string GetSetting(string name);
Expand Down
Expand Up @@ -647,6 +647,11 @@ namespace FluentAssertions.Common
System.Threading.Tasks.Task DelayAsync(System.TimeSpan delay, System.Threading.CancellationToken cancellationToken);
FluentAssertions.Common.ITimer StartTimer();
}
public interface ICollectionWrapper<TCollection>
where TCollection : System.Collections.ICollection
{
TCollection UnderlyingCollection { get; }
}
public interface IConfigurationStore
{
string GetSetting(string name);
Expand Down
Expand Up @@ -635,6 +635,11 @@ namespace FluentAssertions.Common
System.Threading.Tasks.Task DelayAsync(System.TimeSpan delay, System.Threading.CancellationToken cancellationToken);
FluentAssertions.Common.ITimer StartTimer();
}
public interface ICollectionWrapper<TCollection>
where TCollection : System.Collections.ICollection
{
TCollection UnderlyingCollection { get; }
}
public interface IConfigurationStore
{
string GetSetting(string name);
Expand Down
Expand Up @@ -635,6 +635,11 @@ namespace FluentAssertions.Common
System.Threading.Tasks.Task DelayAsync(System.TimeSpan delay, System.Threading.CancellationToken cancellationToken);
FluentAssertions.Common.ITimer StartTimer();
}
public interface ICollectionWrapper<TCollection>
where TCollection : System.Collections.ICollection
{
TCollection UnderlyingCollection { get; }
}
public interface IConfigurationStore
{
string GetSetting(string name);
Expand Down
Expand Up @@ -628,6 +628,11 @@ namespace FluentAssertions.Common
System.Threading.Tasks.Task DelayAsync(System.TimeSpan delay, System.Threading.CancellationToken cancellationToken);
FluentAssertions.Common.ITimer StartTimer();
}
public interface ICollectionWrapper<TCollection>
where TCollection : System.Collections.ICollection
{
TCollection UnderlyingCollection { get; }
}
public interface IConfigurationStore
{
string GetSetting(string name);
Expand Down
Expand Up @@ -635,6 +635,11 @@ namespace FluentAssertions.Common
System.Threading.Tasks.Task DelayAsync(System.TimeSpan delay, System.Threading.CancellationToken cancellationToken);
FluentAssertions.Common.ITimer StartTimer();
}
public interface ICollectionWrapper<TCollection>
where TCollection : System.Collections.ICollection
{
TCollection UnderlyingCollection { get; }
}
public interface IConfigurationStore
{
string GetSetting(string name);
Expand Down