Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
172 changed files
with
36,759 additions
and
31,859 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
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
49 changes: 49 additions & 0 deletions
49
Src/FluentAssertions/Common/MemberPathSegmentEqualityComparer.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,49 @@ | ||
using System.Collections.Generic; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace FluentAssertions.Common | ||
{ | ||
/// <summary> | ||
/// Compares two segments of a <see cref="MemberPath"/>. | ||
/// Sets the <see cref="AnyIndexQualifier"/> equal with any numeric index qualifier. | ||
/// All other comparisons are default string equality. | ||
/// </summary> | ||
internal class MemberPathSegmentEqualityComparer : IEqualityComparer<string> | ||
{ | ||
private const string AnyIndexQualifier = "*"; | ||
private static readonly Regex IndexQualifierRegex = new(@"^\d+$"); | ||
|
||
/// <summary> | ||
/// Compares two segments of a <see cref="MemberPath"/>. | ||
/// </summary> | ||
/// <param name="x">Left part of the comparison.</param> | ||
/// <param name="y">Right part of the comparison.</param> | ||
/// <returns>True if segments are equal, false if not.</returns> | ||
public bool Equals(string x, string y) | ||
{ | ||
if (x == AnyIndexQualifier) | ||
{ | ||
return IsIndexQualifier(y); | ||
} | ||
|
||
if (y == AnyIndexQualifier) | ||
{ | ||
return IsIndexQualifier(x); | ||
} | ||
|
||
return x == y; | ||
} | ||
|
||
private static bool IsIndexQualifier(string segment) | ||
=> segment == AnyIndexQualifier || IndexQualifierRegex.IsMatch(segment); | ||
|
||
public int GetHashCode(string obj) | ||
{ | ||
#if NETCOREAPP2_1_OR_GREATER | ||
return obj.GetHashCode(System.StringComparison.Ordinal); | ||
#else | ||
return obj.GetHashCode(); | ||
#endif | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.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,75 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Linq; | ||
|
||
namespace FluentAssertions.Common | ||
{ | ||
internal static class ReadOnlyNonGenericCollectionWrapper | ||
{ | ||
public static ReadOnlyNonGenericCollectionWrapper<DataTableCollection, DataTable> Create(DataTableCollection collection) | ||
{ | ||
return | ||
(collection != null) | ||
? new ReadOnlyNonGenericCollectionWrapper<DataTableCollection, DataTable>(collection) | ||
: null; | ||
} | ||
|
||
public static ReadOnlyNonGenericCollectionWrapper<DataColumnCollection, DataColumn> Create(DataColumnCollection collection) | ||
{ | ||
return | ||
(collection != null) | ||
? new ReadOnlyNonGenericCollectionWrapper<DataColumnCollection, DataColumn>(collection) | ||
: null; | ||
} | ||
|
||
public static ReadOnlyNonGenericCollectionWrapper<DataRowCollection, DataRow> Create(DataRowCollection collection) | ||
{ | ||
return | ||
(collection != null) | ||
? new ReadOnlyNonGenericCollectionWrapper<DataRowCollection, DataRow>(collection) | ||
: null; | ||
} | ||
} | ||
|
||
internal class ReadOnlyNonGenericCollectionWrapper<TCollection, TItem> : ICollection<TItem> | ||
where TCollection : ICollection | ||
{ | ||
public TCollection UnderlyingCollection { get; } | ||
|
||
public ReadOnlyNonGenericCollectionWrapper(TCollection collection) | ||
{ | ||
Guard.ThrowIfArgumentIsNull(collection, nameof(collection)); | ||
|
||
UnderlyingCollection = collection; | ||
} | ||
|
||
public int Count => UnderlyingCollection.Count; | ||
|
||
public bool IsReadOnly => true; | ||
|
||
public IEnumerator<TItem> GetEnumerator() => UnderlyingCollection.Cast<TItem>().GetEnumerator(); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => UnderlyingCollection.GetEnumerator(); | ||
|
||
public 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(); | ||
} | ||
} |
Oops, something went wrong.