Comments (10)
I agree about not going down the TwoDimensionalArrayAssertions
path.
Since Array.GetValue()
has overloads for up to three indices before deferring to params int[] indices
or params long[] indices
, Let's as well go with three Should
s for T[,]
, T[,,]
and T[,,,]
.
If users needs more, they can always add those overloads themselves as they just resolve ambiguity and forward to MultiDimensionArrayAssertions
.
Since we haven't had requests for multi-dimensional arrays, I don't think we should duplicate all functionality from GenericCollectionAssertions
I suggest starting out soft with these:
BeEmpty()
NotBeEmpty()
HaveCount(int expected)
NotHaveCount(int unexpected)
from fluentassertions.
You can already use BeEquivalenTo
for that. It has support for multi-dimensional arrays.
from fluentassertions.
But what kind of assertion would you suggest?
from fluentassertions.
for asserting the Length
and GetLength
functionality
maybe something like this
var array = new string[2,3] { { "a", "b", "c" }, { "d", "e", "f" } };
array.Should().BeEmpty();
array.Should().NotBeEmpty();
array.Should().HaveElementAt(0, 0, "a");
array.Should().HaveElementAt(1, 2, "f");
array.Should().HaveTotalLength(6);
array.Should().HaveDimensionLength(0, 2);
array.Should().HaveDimensionLength(1, 3);
from fluentassertions.
I like that. What do you think @jnyrup ?
from fluentassertions.
I'm wondering if for each different array dimension there should be a dedicated assertions class, this will allow to have strongly-typed assertions and not just use the System.Array
type.
this would mean that instead of HaveDimensionLength
there could be a dedicated method for each dimension length
something like this:
public static class Extensions
{
public static TwoDimensionalArrayAssertions<T> Should<T>(this T[,] actual) => new(actual);
public static ThreeDimensionalArrayAssertions<T> Should<T>(this T[,,] actual) => new(actual);
public static FourDimensionalArrayAssertions<T> Should<T>(this T[,,,] actual) => new(actual);
}
public class TwoDimensionalArrayAssertions<T>
{
public TwoDimensionalArrayAssertions(T[,] array) { }
}
public class ThreeDimensionalArrayAssertions<T>
{
public ThreeDimensionalArrayAssertions(T[,,] array) { }
}
public class FourDimensionalArrayAssertions<T>
{
public FourDimensionalArrayAssertions(T[,,,] array) { }
}
from fluentassertions.
That's possible, but this is the first time in 13 years that somebody suggests this feature, so your original proposal should be good enough.
from fluentassertions.
I think that a generic assertion extension will not work here
public static ArrayAssertions Should(this Array array) => new ArrayAssertions(array);
I think that the assertion extensions need to be for each dimension separately, otherwise when using a single-dimension array the extension method used will be the new one instead of the Collections.GenericCollectionAssertions<T>
so we would need something like this -
public static class Ex
{
public static MultiDimensionArrayAssertions Should<T>(this T[,] array) => new MultiDimensionArrayAssertions(array);
public static MultiDimensionArrayAssertions Should<T>(this T[,,] array) => new MultiDimensionArrayAssertions(array);
public static MultiDimensionArrayAssertions Should<T>(this T[,,,] array) => new MultiDimensionArrayAssertions(array);
// more dimensions ...
}
public class MultiDimensionArrayAssertions // what should this extend from?
{
public MultiDimensionArrayAssertions(Array array) { }
}
from fluentassertions.
Yeah, you're right. You can define an extension method on Array
, but for single-dimension arrays, it'll result in ambiguous calls.
from fluentassertions.
Let's as well go with three Shoulds for T[,], T[,,] and T[,,,].
That settles it then
from fluentassertions.
Related Issues (20)
- Add support for asserting NaN values HOT 10
- Library is not compatible with .NET MAUI 8.0.6 HOT 4
- Add feature to check if an XElement or XAttribute is absent within the XDocument HOT 25
- Null reference exception when using custom comparer in equivalency options HOT 7
- WithInnerException<T>() needs the type as a parameter HOT 2
- `Should().BeEquivalentTo` failing for identical objects HOT 3
- FluetntAssertion doesn't work correctly for records HOT 8
- Equivalency assertion option Excluding outputs "value(...<>c__DisplayClass).variableName" in some instances HOT 2
- Add string-option for ignoring newline style HOT 2
- Unexpected default equivalency behaviour with interfaces HOT 3
- ArgumentOutOfRangeException in FluentAssertions.Equivalency.Tracing.StringBuilderTraceWriter.ToString() HOT 8
- FluentAssertions: using a NullorEqual string EqualityComparer still returns a type difference error HOT 2
- [API Proposal]: Allow to assert RegEx matched groups HOT 3
- BeXmlSerializable does not respect XmlIgnoreAttribute HOT 5
- Use StringSyntaxAttribute to provide IDE support for proper reasons HOT 2
- [API Proposal]: Parsability of strings HOT 18
- Add AllSatisfyOrEmpty for GenericCollection HOT 4
- AssertionScope w/explicit name AND DetermineCallerIdentity doesn't work as expected
- [Feature]: SetEquals, unordered equal for collections HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluentassertions.