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

Mock.Arrange throws NullReferenceException

2 Answers 214 Views
JustMock Free Edition
This is a migrated thread and some comments may be shown as answers.
Viktor zhivkov
Top achievements
Rank 1
Viktor zhivkov asked on 28 Jun 2011, 04:46 PM
I have a problem with this code:

public interface IProcessDataPersister
{
List<TaskWarning> GetTaskWarnings(Guid taskId);
}
 
//in a method
var localPersister = Mock.Create<IProcessDataPersister>();
Mock.Arrange(() => localPersister.GetTaskWarnings(new Guid("{00000000-0000-0000-0001-000000000003}")))
.Returns(new List<TaskWarning>() { new TaskWarning(new Guid("{00000000-0000-0000-0001-000000000003}")) { EscalationLevel = 0 } })
.MustBeCalled();

Mock.Arrange(...) throws the following exception:
System.NullReferenceException occurred
  Message=Object reference not set to an instance of an object.
  Source=Telerik.JustMock
  StackTrace:
       at .™.(Type valueType, Object value) in c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Utility.cs:line 334
  InnerException: 


If I change the Arrange method to use Arg.IsAny<Guid>() instead of the explicit value there is no exception and everything works fine.
I am using the latest internal JustMock Free Edition build 2011.1.620.0.
Also test it on the official build and the results were the same.
Hope that will help you solve the problem.

2 Answers, 1 is accepted

Sort by
0
Accepted
Ricky
Telerik team
answered on 01 Jul 2011, 02:01 PM
Hi Viktor,

Thanks again for sending issue. Yes you are right about it and therefore I filed a bug regarding it and hopefully it will be fixed in the coming Q2 release.


Should you find  any more exceptions, please feel free to write us back.


Kind Regards,
Ricky
the Telerik team

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

0
Viktor zhivkov
Top achievements
Rank 1
answered on 01 Jul 2011, 02:10 PM
I am looking forward the fix.
Meantime if anyone else struggles with the same issue here is my own workaround:

var localPersister = Mock.Create<IProcessDataPersister>();
Mock.Arrange(() => localPersister.GetTaskWarnings(Arg.IsAny<Guid>()))
.Returns((Guid id) =>
{
string strId = id.ToString();
 
switch (strId)
{
    case "00000000-0000-0000-0001-000000000001":
        return new List<TaskWarning>() { new TaskWarning(id) { EscalationLevel = 1 } };
    case "00000000-0000-0000-0001-000000000002":
        return new List<TaskWarning>() {
            new TaskWarning(id) { EscalationLevel = 1 },
            new TaskWarning(id) { EscalationLevel = 2 } };
    default:
        return new List<TaskWarning>();
}
});
Tags
JustMock Free Edition
Asked by
Viktor zhivkov
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Viktor zhivkov
Top achievements
Rank 1
Share this question
or