tpierrain / NFluent

Smooth your .NET TDD experience with NFluent! NFluent is an ergonomic assertion library which aims to fluent your .NET TDD experience (based on simple Check.That() assertion statements). NFluent aims your tests to be fluent to write (with a super-duper-happy 'dot' auto-completion experience), fluent to read (i.e. as close as possible to plain English expression), but also fluent to troubleshoot, in a less-error-prone way comparing to the classical .NET test frameworks. NFluent is also directly inspired by the awesome Java FEST Fluent assertion/reflection library (http://fest.easytesting.org/)
Apache License 2.0
310 stars 53 forks source link

Handle n-dimension arrays #257

Closed benjaminbelloyan closed 6 years ago

benjaminbelloyan commented 6 years ago

Hello guys,

I'm having an issue with HasFieldsWithSameValues check. My object has a property with multidimensionnal array.

e.g:

class MyType{
    public MyPropertyType[,] Property { get; set; }
}

When calling HasFieldWithSameValues of a MyType object, I get an argument exception saying that the array doesn't have exactly one dimension.

Any plans on adding the support for multidimensionnal array?

Thanks

dupdob commented 6 years ago

Hello thanks for reporting this. Support for multi dimensionnal arrays delayed until someone requested it, as it requires significant work. I am starting effort now and will keep you posted

dupdob commented 6 years ago

hi @benjaminbelloyan I have a working version. Are you interested in testing a pre version with the fix?

Before an official release, I still have to refactor this and review behavior for multi dimensionnal arrays, which means several weeks of delay.

benjaminbelloyan commented 6 years ago

Hi @dupdob Thanks for the quick update. I would indeed be interested in testing the pre version

dupdob commented 6 years ago

2.4.0.182-beta is available on myget. It contains the fix for your problem

https://www.myget.org/feed/dupdobnightly/package/nuget/NFluent

benjaminbelloyan commented 6 years ago

Hi @dupdob

The fix seems to be working in some cases. In other cases though, I encountered a DivideByZeroException:

Test Name: Dequeue Test FullName: Kernel.Test.Warehouse.LocalFileWarehouseTestFixture.Dequeue Test Source: C:\Projects\nept-in\smartdataprovider\Kernel\test\Warehouse\LocalFileWarehouseTestFixture.cs : line 53 Test Outcome: Failed Test Duration: 0:00:00,282

Result StackTrace:
à NFluent.Helpers.ReflectionWrapper.GetSubExtendedMemberInfosFields() à NFluent.Helpers.ReflectionWrapper.MapFields(ReflectionWrapper actual, ICollection1 scanned, Int32 depth, Func4 mapFunction) à NFluent.Helpers.ReflectionWrapper.MapFields(ReflectionWrapper actual, ICollection1 scanned, Int32 depth, Func4 mapFunction) à NFluent.Helpers.ReflectionWrapper.MemberMatches[TU](TU expectedValue) à NFluent.ReflectionWrapperChecks.<>c__DisplayClass1_01.<FieldEqualTest>b__0(ReflectionWrapper sut, ICheckLogic1 test) à NFluent.Kernel.CheckLogic1.Analyze(Action2 action) à NFluent.ReflectionWrapperChecks.FieldEqualTest[TU](ICheck1 check, TU expectedValue, Boolean mustMatch) à NFluent.ReflectionWrapperChecks.IsEqualTo[TU](ICheck1 check, TU expectedValue) à NFluent.ObjectFieldsCheckExtensions.HasFieldsWithSameValues[T,TU](ICheck`1 check, TU expected) à Kernel.Test.Warehouse.LocalFileWarehouseTestFixture.Dequeue() dans C:\Projects\nept-in\smartdataprovider\Kernel\test\Warehouse\LocalFileWarehouseTestFixture.cs:ligne 124 Result Message: System.DivideByZeroException : Tentative de division par zéro.

My 2-dimensions array use case is an array of an abstract class type, that might be a wrapper for a string or int. Don't know if it helps.

dupdob commented 6 years ago

Thanks for your feedback. Could you give the dimensions of the array(s)? I do not think the issue relates to what is inside the array

dupdob commented 6 years ago

I have been able to understand and fix the issue. I will publish a new beta shortly

dupdob commented 6 years ago

I just pushed a new beta. It should fix the divide by zero issue

benjaminbelloyan commented 6 years ago

Hi,

I've tested it this morning in different scenarios, and it seems to be working properly both when arrays content are equal or not. The message points to the correct indexes and is explicit to track down the diff.

I've only tested it with 2 dimensions array for now though, might have 3 dimensions arrays in the future.

Thanks for the great work again