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

Mock SPField

2 Answers 48 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Adrian
Top achievements
Rank 1
Adrian asked on 30 Jul 2012, 12:24 PM
Dear Support
I am currently evaluating JustMock and when trying to create mock for SPField:
var field = Mock.Create<SPField>();
I get NullReferenceException. 
StackTrace:
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 Answers, 1 is accepted

Sort by
0
Adrian
Top achievements
Rank 1
answered on 31 Jul 2012, 10:19 AM
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.
0
Ricky
Telerik team
answered on 01 Aug 2012, 02:51 PM
Hi Adrian,

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

Kind Regards
Ricky
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
General Discussions
Asked by
Adrian
Top achievements
Rank 1
Answers by
Adrian
Top achievements
Rank 1
Ricky
Telerik team
Share this question
or