I have a problem when trying to use a DoInstead of a method that returns an enum value.
The mocked function is indeed called as expected. However, the return value (an enum) is not returned correctly. Instead it always returns the first value of the enum.
Using Progress Telerik.JustMock 2019.2.620.1 (with license).
Here is a way to reproduce it (Console application, VS2017, Link to Telerik.JustMock dll):
namespace
TelerikJustMockBug
{
using
System;
using
Telerik.JustMock;
class
Program
{
delegate
CompletionCode MockedReadWriteDelegate(
byte
[] buffer,
int
count,
out
int
retCount);
static
void
Main(
string
[] args)
{
new
Program().Run();
}
private
void
Run()
{
ClassToMock session = Mock.Create<ClassToMock>();
Mock.Arrange(() =>
new
ClassToMock()).Returns(session);
Mock.Arrange(() => session.Read(Arg.IsAny<
byte
[]>(), Arg.AnyInt,
out
Arg.Ref(Arg.AnyInt).Value)).DoInstead(
new
MockedReadWriteDelegate(
this
.MockedRead));
ClassToMock c =
new
ClassToMock();
CompletionCode result = c.Read(
new
byte
[2], 2,
out
int
retCount);
if
(retCount != 5)
{
throw
new
Exception(
"retCount was not set correctly"
);
}
if
(result != CompletionCode.NOT_SUCCESS)
{
// this exception is thrown in my case with 'Wrong result: 0'
throw
new
Exception($
"Wrong result: {result.ToString()}"
);
}
}
private
CompletionCode MockedRead(
byte
[] buffer,
int
count,
out
int
retCount)
{
retCount = 5;
return
CompletionCode.NOT_SUCCESS;
}
public
enum
CompletionCode
{
SUCCESS = 1,
NOT_SUCCESS = 2
}
public
class
ClassToMock
{
public
CompletionCode Read(
byte
[] buffer,
int
count,
out
int
retCount)
{
throw
new
Exception(
"Real implementation - should never be called due to mocking"
);
}
}
}
}