This is a migrated thread and some comments may be shown as answers.

Mocked Set Only Property Throws NullReferenceException when called

1 Answer 32 Views
JustMock Free Edition
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 31 May 2011, 04:26 PM
I am experiencing difficulty mocking an interface that has write only properties.  When I try to set the property's value a NullReferenceExcpetion is thrown.

Here is some sample code (which throws the exception):
public interface IFoo
{
    int Foo { set; }
}
 
 
[TestMethod]
public void TestSetOnlyProperty()
{
    IFoo fooMock = Mock.Create<IFoo>();
 
    fooMock.Foo = 30;
 
    Mock.AssertSet(() => fooMock.Foo = 30);
}

By simply adding a getter to the interface, the test passes as expected:
public interface IFooGetAndSet
{
    int Foo { get; set; }
}
 
[TestMethod]
public void TestSetProperty()
{
    IFooGetAndSet fooMock = Mock.Create<IFooGetAndSet>();
 
    fooMock.Foo = 30;
 
    Mock.AssertSet(() => fooMock.Foo = 30);
}

I would like to be able to mock interfaces that might have write only properties.

Thanks

1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 15 Jun 2011, 10:27 AM
Hi Scott,

Sorry for the late reply. Yes you are right about the issue. However, we have recently fixed it and should you require an internal build please open up a support ticket(since we can’t send one in public forum) and we would be more than happy to send you one.


Kind regards,
Mehfuz
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
JustMock Free Edition
Asked by
Scott
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or