Mock.Arrange throws NullReferenceException

3 posts, 1 answers
  1. Viktor zhivkov
    Viktor zhivkov avatar
    3 posts
    Member since:
    Nov 2009

    Posted 28 Jun 2011 Link to this post

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

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

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

    Posted 01 Jul 2011 Link to this post

    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,
    the Telerik team

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

  3. Viktor zhivkov
    Viktor zhivkov avatar
    3 posts
    Member since:
    Nov 2009

    Posted 01 Jul 2011 Link to this post

    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 } };
            return new List<TaskWarning>();
Back to Top