Sorry for the meaningless title, but I do have a general question on using JustMock.
Imagine the following SUT
Now have a look at my test case for the save method:
Running this test I get the error that Mock.AssertAll(dao) failed because the IDao.Insert method has never been called ?
Debugging through the test I could step into
service.Save()
-> service.Get() => returning NULL as expected
-> service.Set()
-> dao.Insert (which is proxied)
What am I doing wrong here ?
Kind regards
Sebastian
Imagine the following SUT
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);
}
}
}
Now have a look at my test case for the save method:
[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);
}
Running this test I get the error that Mock.AssertAll(dao) failed because the IDao.Insert method has never been called ?
Debugging through the test I could step into
service.Save()
-> service.Get() => returning NULL as expected
-> service.Set()
-> dao.Insert (which is proxied)
What am I doing wrong here ?
Kind regards
Sebastian