Mock SPField

3 posts, 0 answers
  1. Adrian
    Adrian avatar
    2 posts
    Member since:
    Jul 2012

    Posted 30 Jul 2012 Link to this post

    Dear Support
    I am currently evaluating JustMock and when trying to create mock for SPField:
    var field = Mock.Create<SPField>();
    I get NullReferenceException. 
    at Telerik.JustMock.DynamicProxy.ProxyFactory.CreateInstance(Type proxyType, Object[] extArgs)
    at Telerik.JustMock.DynamicProxy.ProxyFactory.Create()
    at Telerik.JustMock.DynamicProxy.Fluent.FluentProxy.NewInstance()
    at Telerik.JustMock.DynamicProxy.Proxy.Create(Type target, Action`1 action)
    at Telerik.JustMock.MockManager.CreateProxy(Type targetType, Container container)
    at Telerik.JustMock.MockManager.CreateInstance(Container container)
    at Telerik.JustMock.MockManager.SetupMock(Behavior behavior, Boolean static)
    at Telerik.JustMock.MockManager.CreateInstance()
    at Telerik.JustMock.Mock.Create(Type target, Behavior behavior, Object[] args)
    at Telerik.JustMock.Mock.Create(Type target, Object[] args)
    at Telerik.JustMock.Mock.Create[T]()

    Can SPField be mocked using JustMock?
  2. Adrian
    Adrian avatar
    2 posts
    Member since:
    Jul 2012

    Posted 31 Jul 2012 Link to this post

    OK. I did some more digging and found a way around this:

    var field = Mock.Create<SPField>(Constructor.Mocked);

    This works without throwing the null reference exception.
  3. Ricky
    Ricky avatar
    467 posts

    Posted 01 Aug 2012 Link to this post

    Hi Adrian,

    Thanks again for contacting us. Yes you have to use Constructor.Mocked since SPField constructor throws the exception.

    Kind Regards
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top