Hi, here is the complete testing code.
01.
<P>
02.
using
System;
03.
using
Microsoft.VisualStudio.TestTools.UnitTesting;
04.
using
Telerik.JustMock;
05.
using
Telerik.JustMock.Core;
06.
07.
namespace
TestMock1
08.
{
09.
[TestClass]
10.
public
class
UnitTest1
11.
{
12.
[TestMethod]
13.
public
void
TestMethod1()
14.
{
15.
var mock = Mock.Create<MyClass>(Behavior.CallOriginal);
16.
Mock.Arrange(() => mock.MyFunc1(DateTime.Now)).DoNothing();
17.
mock.MyFunc2();
18.
}
19.
}
20.
21.
class
SomeClass
22.
{
23.
public
DateTime SentDate {
get
;
set
; }
24.
}
25.
26.
public
class
MyClass
27.
{
28.
SomeClass SomeObject;
29.
30.
SomeClass GetObjectFromDB()
31.
{
32.
SomeClass obj =
new
SomeClass();
33.
// get it from DB
34.
return
obj;
35.
}
36.
37.
public
virtual
void
MyFunc1(DateTime somedate)
38.
{
39.
SomeObject = GetObjectFromDB();
40.
}
41.
public
virtual
void
MyFunc2()
42.
{
43.
MyFunc1(SomeObject.SentDate);
44.
}
45.
46.
}
47.
}</P>
At line 43 the code produces an exception because SomeObject is null
On a separate note, if I declare MyFunc2() as "internal" instead of "public", I can skip Behavior.CallOriginal and the original code is still called. I am not sure if this is a bug or feature.