8000 Code cleanups by jnyrup · Pull Request #1973 · fluentassertions/fluentassertions · GitHub
[go: up one dir, main page]

Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ReadOnlyNonGenericCollectionWrapper(TCollection collection)

public int Count => UnderlyingCollection.Count;

public bool IsReadOnly => true;
bool ICollection<TItem>.IsReadOnly => true;

public IEnumerator<TItem> GetEnumerator() => UnderlyingCollection.Cast<TItem>().GetEnumerator();

Expand All @@ -57,18 +57,9 @@ public ReadOnlyNonGenericCollectionWrapper(TCollection collection)

public void CopyTo(TItem[] array, int arrayIndex) => UnderlyingCollection.CopyTo(array, arrayIndex);

/*
void ICollection<TItem>.Add(TItem item) => throw new NotSupportedException();

Mutation is not supported, but these methods must be implemented to satisfy ICollection<T>:
* Add
* Clear
* Remove
void ICollection<TItem>.Clear() => throw new NotSupportedException();

*/

public void Add(TItem item) => throw new NotSupportedException();

public void Clear() => throw new NotSupportedException();

public bool Remove(TItem item) => throw new NotSupportedException();
bool ICollection<TItem>.Remove(TItem item) => throw new NotSupportedException();
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static AndConstraint<GenericCollectionAssertions<DataColumn>> NotBeSameAs
Guard.ThrowIfArgumentIsNull(
unexpected, nameof(unexpected), "Cannot verify same reference against a <null> collection (use NotBeNull instead?).");

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

Expand Down
4 changes: 2 additions & 2 deletions Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static AndConstraint<GenericCollectionAssertions<DataRow>> BeSameAs(
this GenericCollectionAssertions<DataRow> assertion, DataRowCollection expected, string because = "",
params object[] becauseArgs)
{
if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper<DataRowCollection, DataRow> wrapper)
if (assertion.Subject is ICollectionWrapper<DataRowCollection> wrapper)
{
var actualSubject = wrapper.UnderlyingCollection;

Expand Down Expand Up @@ -68,7 +68,7 @@ public static AndConstraint<GenericCollectionAssertions<DataRow>> NotBeSameAs(
this GenericCollectionAssertions<DataRow> assertion, DataRowCollection unexpected, string because = "",
params object[] becauseArgs)
{
if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper<DataRowCollection, DataRow> wrapper)
if (assertion.Subject is ICollectionWrapper<DataRowCollection> wrapper)
{
var actualSubject = wrapper.UnderlyingCollection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static AndConstraint<GenericCollectionAssertions<DataTa F440 ble>> BeSameAs(
this GenericCollectionAssertions<DataTable> assertion, DataTableCollection expected, string because = "",
params object[] becauseArgs)
{
if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper<DataTableCollection, DataTable> wrapper)
if (assertion.Subject is ICollectionWrapper<DataTableCollection> wrapper)
{
var actualSubject = wrapper.UnderlyingCollection;

Expand Down Expand Up @@ -65,7 +65,7 @@ public static AndConstraint<GenericCollectionAssertions<DataTable>> NotBeSameAs(
this GenericCollectionAssertions<DataTable> assertion, DataTableCollection unexpected, string because = "",
params object[] becauseArgs)
{
if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper<DataTableCollection, DataTable> wrapper)
if (assertion.Subject is ICollectionWrapper<DataTableCollection> wrapper)
{
var actualSubject = wrapper.UnderlyingCollection;

Expand Down
14 changes: 2 additions & 12 deletions Src/FluentAssertions/Equivalency/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ public object GetValue(object obj)

public CSharpAccessModifier SetterAccessibility => fieldInfo.GetCSharpAccessModifier();

public bool IsBrowsable
{
get
{
if (isBrowsable == null)
{
isBrowsable = fieldInfo.GetCustomAttribute<EditorBrowsableAttribute>() is not { State: EditorBrowsableState.Never };
}

return isBrowsable.Value;
}
}
public bool IsBrowsable =>
isBrowsable ??= fieldInfo.GetCustomAttribute<EditorBrowsableAttribute>() is not { State: EditorBrowsableState.Never };
}
3 changes: 1 addition & 2 deletions Src/FluentAssertions/Events/EventMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ internal class EventMonitor<T> : IMonitor<T>
{
private readonly WeakReference subject;

private readonly ConcurrentDictionary<string, EventRecorder> recorderMap =
new ConcurrentDictionary<string, EventRecorder>();
private readonly ConcurrentDictionary<string, EventRecorder> recorderMap = new();

public EventMonitor(object eventSource, Func<DateTime> utcNow)
{
Expand Down
0