Hi,
I am trying to mock db access using JustMock. I do have an interface defined and created a mock object from the interface. I then arranged a method to return false for any argument. After arranging the mock object on the second call with unique arguments a null reference exception is thrown. The code snippet below shows what I am trying to do:
IDBAccess fakeDBAccess = Mock.Create<IDBAccess>();
List<ModelType1> fakeModelType1 = GetFakeModelModelType1();
Mock.Arrange(()=> fakeDBAccess.GetModelType1ForPrimaryKey(Arg.Is<long>(1))).Returns(fakeModelType1[0]);
Mock.Arrange(() => fakeDBAccess.GetModelType1ForPrimaryKey(Arg.Is<long>(2))).Returns(fakeModelType1[1]);
List<fakeModelType2> fakeModelType2 = new List<fakeModelType2>();
Mock.Arrange(() => fakeDBAccess.GetModelType2ForPrimaryKey(Arg.IsAny<long>())).Returns(fakeModelType2);
Mock.Arrange(() => fakeDBAccess.GetModelType1Status(Arg.IsAny<ModelType1>())).Returns(false);
ClassUnderTest OUT = new ClassUnderTest(fakeDBAccess );
On debugging the above code try to call fakeDBAccess.GetModelType1Status() with two different values say fakeModelType[0] and fakeModelType[1] (in the watch window) the first call succeeds and returns false but the second call fails with a null reference exception. The order of calls do not matter. It is always the second call that throws the null reference exception. Can you please confirm whether this is a bug or not. If this is a bug can you please suggest a work around?
I am trying to mock db access using JustMock. I do have an interface defined and created a mock object from the interface. I then arranged a method to return false for any argument. After arranging the mock object on the second call with unique arguments a null reference exception is thrown. The code snippet below shows what I am trying to do:
IDBAccess fakeDBAccess = Mock.Create<IDBAccess>();
List<ModelType1> fakeModelType1 = GetFakeModelModelType1();
Mock.Arrange(()=> fakeDBAccess.GetModelType1ForPrimaryKey(Arg.Is<long>(1))).Returns(fakeModelType1[0]);
Mock.Arrange(() => fakeDBAccess.GetModelType1ForPrimaryKey(Arg.Is<long>(2))).Returns(fakeModelType1[1]);
List<fakeModelType2> fakeModelType2 = new List<fakeModelType2>();
Mock.Arrange(() => fakeDBAccess.GetModelType2ForPrimaryKey(Arg.IsAny<long>())).Returns(fakeModelType2);
Mock.Arrange(() => fakeDBAccess.GetModelType1Status(Arg.IsAny<ModelType1>())).Returns(false);
ClassUnderTest OUT = new ClassUnderTest(fakeDBAccess );
On debugging the above code try to call fakeDBAccess.GetModelType1Status() with two different values say fakeModelType[0] and fakeModelType[1] (in the watch window) the first call succeeds and returns false but the second call fails with a null reference exception. The order of calls do not matter. It is always the second call that throws the null reference exception. Can you please confirm whether this is a bug or not. If this is a bug can you please suggest a work around?