or
Line 10: Mock.SetupStatic(
typeof
(XY));
Line 11: Mock.Arrange(() => XY.XY()).Returns(
"xy"
);
at Telerik.JustMock.Handlers.InterceptorHandler.Create(Object target, MethodInfo methodInfo, Boolean privateMethod)
at Telerik.JustMock.MockContext`1.SetupMock(MockExpression`1 expression)
at Telerik.JustMock.MockContext`1.SetupMock(Expression`1 expression)
at Telerik.JustMock.Mock.<>c__DisplayClass1`1.<Arrange>b__0(MockContext`1 x)
at Telerik.JustMock.MockContext.Setup(Instruction instruction, Func`2 function)
at Telerik.JustMock.Mock.Arrange(Expression`1 expression)
at XY()
in
XY.cs: line 11
class Program
{
static void Main()
{
var results = new Program().CheckForY2K();
Console.WriteLine(results);
Console.Read();
}
internal bool CheckForY2K()
{
return DateTime.Now == new DateTime(2000, 1, 1);
}
}
[TestFixture]
public class NuintTest
{
static NuintTest()
{
Mock.Replace(() => DateTime.Now).In<
Program
>(x => x.CheckForY2K());
}
[Test]
public void TestY2K()
{
Mock.Arrange(() => DateTime.Now).Returns(new DateTime(2000, 1, 1));
var results = new Program().CheckForY2K();
Assert.IsTrue(results);
}
}
class Program
{
static void Main()
{
var results = CheckForY2K();
Console.WriteLine(results);
Console.Read();
}
internal static bool CheckForY2K()
{
return DateTime.Now == new DateTime(2000, 1, 1);
}
}
Mock.Replace(() => DateTime.Now).In<
Program
>(x => x.CheckForY2K());
public
interface
IDao
{
// throws an exception on duplicate key
void
Insert(
string
key,
string
value);
// throws an exception if key not available
void
Update(
string
key,
string
value);
// throws an exception of key not found
string
FindByKey(
string
key);
}
public
interface
IService
{
string
Get(
string
key);
void
Set(
string
key,
string
value);
// should insert or update the value for the given key
void
Save(
string
key,
string
value);
}
public
class
ServiceImpl : IService
{
private
readonly
IDao _dao;
public
ServiceImpl(IDao dao)
{
_dao = dao;
}
public
string
Get(
string
key)
{
return
_dao.FindById(key);
}
public
void
Set(
string
key,
string
value)
{
_dao.Insert(key, value);
}
public
void
Save(
string
key,
string
value)
{
var value = Get(key);
if
(
null
== value)
{
Set(key, value);
}
else
{
_dao.Update(key, value);
}
}
}
[Test]
public
void
SaveShouldCallInsertOnNonExistingKey()
{
var key =
"key"
;
var value =
"value"
;
var dao = Mock.Create<IDao>();
dao.Arrange(x => x.Insert(Arg.AnyString,Arg.AnyString)).MustBeCalled();
var service = Mock.Create<ServiceImpl>(Behaviour.CallOriginal, dao);
service.Arrange(x => x.Get(Arg.AnyString)).Returns((
string
)
null
).MustBeCalled();
service.Save(key, value);
Mock.AssertAll(dao);
Mock.AssertAll(service);
}
MSomeClass.AllInstances.GetError = (instance) =>
{
return string.Empty;
};