Mocked Set Only Property Throws NullReferenceException when called

2 posts, 0 answers
  1. Scott
    Scott avatar
    1 posts
    Member since:
    May 2011

    Posted 31 May 2011 Link to this post

    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
  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 15 Jun 2011 Link to this post

    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 >>

  3. DevCraft R3 2016 release webinar banner
Back to Top