2

I have the following converter, which returns DependencyProperty.UnsetValue from its ConvertBack method:

public class DictionaryValueConverter<T> : IValueConverter
{
...

    public object ConvertBack(
        object value,
        Type targetType,
        object parameter,
        string language)
    {
        return DependencyProperty.UnsetValue;
    }
}

When trying to assert the returned value in a unit test, none of the assertions succeeds:

Assert.Same() Failure: Values are not the same instance
Expected: IInspectable { ObjRef = ObjectReference`1 { ThisPtr = 1754526379632, Vftbl = WinRT.IInspectable+Vftbl }, ThisPtr = 1754526379632 }
Actual:   IInspectable { ObjRef = ObjectReference`1 { ThisPtr = 1754526385520, Vftbl = WinRT.IInspectable+Vftbl }, ThisPtr = 1754526385520 }
Assert.Equal() Failure: Values differ
Expected: IInspectable { ObjRef = ObjectReference`1 { ThisPtr = 2602783527936, Vftbl = WinRT.IInspectable+Vftbl }, ThisPtr = 2602783527936 }
Actual:   IInspectable { ObjRef = ObjectReference`1 { ThisPtr = 2602783529856, Vftbl = WinRT.IInspectable+Vftbl }, ThisPtr = 2602783529856 }

How can we test that the returned result should be DependencyProperty.UnsetValue?

Tried several types of assertions but none of them works. I am expecting to be able to test that the resturned result is DependencyProperty.UnsetValue.

Abdessattar
  • 114
  • 5
  • If you look at a variable holding that value in the debugger, you will see it is from an internal class named `MS.Internal.NamedObject`. It has a string field containing the name that gets set to the literal text *DependencyProperty.UnsetValue* So if you don't mind writing the code and relying upon an implementation detail -- that is extremely unlikely to ever change -- you could call `GetType()` and be sure that its type name is of that type and that is has a member string field called `_name` and that the string holds that text. – Joe Aug 11 '23 at 19:41
  • Unfortunately, in the latest version of the WinApp SDK, 1.3.230724000, the type is WinRT.IInspectable, which means everything and anything, from the documentation, 'Provides functionality required for all Windows Runtime classes.'. It has a method `GetRuntimeClassName()`, which in this cases returns an empty string. It's very hacky, but I could test for that empty string if there is no other way. – Abdessattar Aug 12 '23 at 07:31

0 Answers0