FluentAssertions терпит неудачу при сравнении объектов, если одно свойство имеет значение NULL

Сценарий: у меня есть объект со свойством, допускающим значение NULL, которое будет обновлено при запуске тестируемого метода. В ожидаемом объекте я его не указываю, так как хочу проверить значение отдельно. Вот простая тестовая демонстрация

using System;
using FluentAssertions;
using NUnit.Framework;

namespace FluentAssertionsNullableFailure
{
    public class SimpleWithNullable
    {
        public Int64? nullableIntegerProperty
        { get; set; }

        public string strProperty
        { get; set; }
    }

    [TestFixture]
    public class Demo
    {
        public SimpleWithNullable actual = new SimpleWithNullable { nullableIntegerProperty = 1, strProperty = "I haz a string!" };
        public SimpleWithNullable expected = new SimpleWithNullable { strProperty = "I haz a string!" };

        [Test]
        public void NullableTest ()
        {
            actual.ShouldBeEquivalentTo (
                expected,
                opt => opt.Using<Int64?> ( c => c.Subject.Should ().BeInRange ( 0, 10 ) ).WhenTypeIs<Int64?> ()
            );
        }
    }
}

Однако это не удается со следующим сообщением:

Test Name:  NullableTest
Test FullName:  FluentAssertionsNullableFailure.Demo.NullableTest
Test Source:    c:\Users\ebelew\Documents\Visual Studio 2012\Projects\FluentAssertionsNullableFailure\FluentAssertionsNullableFailure\Demo.cs : line 25
Test Outcome:   Failed
Test Duration:  0:00:00.271

Result Message: 
Expected property nullableIntegerProperty to be <null>, but found 1.

With configuration:
- Select all declared properties
- Match property by name (or throw)
- Invoke Action<Nullable`1> when info.RuntimeType.IsSameOrInherits(System.Nullable`1[System.Int64])
- Invoke Action<DateTime> when info.RuntimeType.IsSameOrInherits(System.DateTime)
- Invoke Action<String> when info.RuntimeType.IsSameOrInherits(System.String)
Result StackTrace:  
at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message) in d:\Workspace\Github\FluentAssertions\FluentAssertions.Net35\Execution\LateBoundTestFramework.cs:line 25
at FluentAssertions.Execution.CollectingAssertionStrategy.ThrowIfAny(IDictionary`2 context) in d:\Workspace\Github\FluentAssertions\FluentAssertions.Net35\Execution\CollectingAssertionStrategy.cs:line 57
at FluentAssertions.Execution.AssertionScope.Dispose() in d:\Workspace\Github\FluentAssertions\FluentAssertions.Net35\Execution\AssertionScope.cs:line 267
at FluentAssertions.Equivalency.EquivalencyValidator.AssertEquality(EquivalencyValidationContext context) in d:\Workspace\Github\FluentAssertions\FluentAssertions.Net35\Equivalency\EquivalencyValidator.cs:line 55
at FluentAssertions.AssertionExtensions.ShouldBeEquivalentTo[T](T subject, Object expectation, Func`2 config, String reason, Object[] reasonArgs) in d:\Workspace\Github\FluentAssertions\FluentAssertions.Net35\AssertionExtensions.cs:line 497
at FluentAssertionsNullableFailure.Demo.NullableTest() in c:\Users\ebelew\Documents\Visual Studio 2012\Projects\FluentAssertionsNullableFailure\FluentAssertionsNullableFailure\Demo.cs:line 25

Как я могу сделать это с контекстом параметров, а не разделить его на два или более утверждений. (Одно утверждение для общих свойств, по одному для элемента с диапазоном или желаемым значением вместо строгой эквивалентности)

Примечание. Это также не работает для ссылочных типов без явного значения в объекте expected.

Примечание+: я пробовал ExcludingMissingProperties(), это не меняет ошибку.


person Eris    schedule 31.10.2013    source источник


Ответы (1)


Вы раскрыли сценарий, которого я не предвидел. Я исправлю это в версии 2.2, но вы можете отслеживать мой прогресс через https://github.com/dennisdoomen/fluentassertions/issues/33

person Dennis Doomen    schedule 03.11.2013
comment
Проблема исправлена. Пожалуйста, проверьте проблему на GitHub для более подробной информации. - person Dennis Doomen; 16.11.2013