Skip to content

Exception "Property set method not found" when observing class with null property #3

@marcinbelczewski

Description

@marcinbelczewski

When I run this code on version 0.4.21.5:

public class Test
{
    public string Property
    {
        get { return null; }
    }
}

public class when_observing_test : Observes<Test>
{
    It should_not_fail_but_it_does = () => Console.WriteLine("Will fail");
}

I get:

System.ArgumentException: Property set method not found.
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at developwithpassion.specifications.core.reflection.PropertyInfoMemberAccessor.change_value_to(Object target, Object new_value) in PropertyInfoMemberAccessor.cs: line 27
at developwithpassion.specifications.core.factories.NonCtorDependencySetter.<>c__DisplayClass7.<attempt_to_update_all_of_the_accessors>b__5(MemberAccessor accessor) in NonCtorDependencySetter.cs: line 42
at developwithpassion.specifications.extensions.IterationExtensions.each(IEnumerable1 items, Action1 action) in IterationExtensions.cs: line 13
at developwithpassion.specifications.core.factories.NonCtorDependencySetter.attempt_to_update_all_of_the_accessors(IEnumerable1 accessors_to_update, Object target) in NonCtorDependencySetter.cs: line 40 at developwithpassion.specifications.core.factories.NonCtorDependencySetter.update(Object item) in NonCtorDependencySetter.cs: line 35 at developwithpassion.specifications.faking.DefaultSUTFactory1.create_automatically() in DefaultSUTFactory.cs: line 32
at developwithpassion.specifications.faking.DefaultSUTFactory1.create() in DefaultSUTFactory.cs: line 23 at developwithpassion.specifications.DefaultTestStateFor1.build_sut() in DefaultTestStateFor.cs: line 32
at developwithpassion.specifications.DefaultTestStateFor1.run_setup() in DefaultTestStateFor.cs: line 43 at developwithpassion.specifications.DefaultObservationController2.run_setup() in DefaultObservationController.cs: line 51
at developwithpassion.specifications.observations.InstanceObservations`3.<.ctor>b__0() in InstanceObservations.cs: line 14

In my production code Test.Property isn't really implemented like that. It's a calculated property and it just returns null in certain situations. Our unit tests fail then.

When Test class looks like this:
public class Test
{
public string Property
{
get { return "property value"; }
}
}

all works fine.

It was working ok with version 0.4.13.0 which we were using previously.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions