New to Telerik JustMock? Start a free 30-day trial
CallOriginal
Updated on Mar 25, 2026
CallOriginal behavior makes the mock call the original implementation of the mocked type for every method or property that has no explicit arrangement. Use it for partial mocking: create a Behavior.CallOriginal mock, then arrange only the specific methods you want to override. All other calls execute the actual code.
Syntax
Mock.Create<T>(Behavior.CallOriginal);
Examples
Basic CallOriginal Example
Assume the following class:
C#
public class Log
{
public virtual void Info()
{
throw new NotImplementedException();
}
}To show how CallOriginal mocks behave, we have the next example:
C#
[TestMethod]
[ExpectedException(typeof(NotImplementedException))]
public void ShouldThrowAnExpectedException()
{
// Arrange
var log = Mock.Create<Log>(Behavior.CallOriginal);
// Act
log.Info();
}Here, we create a mock of the Log class, with Behavior.CallOriginal and call a not implemented method. This method follows its original logic and throws a NotImplementedException.
Arranging CallOriginal Mock
We are free to further arrange mocks with Behavior.CallOriginal, as shown in the next example:
C#
public class FooBase
{
public string GetString(string str)
{
return str;
}
}C#
[TestMethod]
public void ShouldAssertAgainstOriginalAndArrangedExpectations()
{
// Arrange
var foo = Mock.Create<FooBase>(Behavior.CallOriginal);
Mock.Arrange(() => foo.GetString("y")).Returns("z");
// Act
var actualX = foo.GetString("x");
var actualY = foo.GetString("y");
var expectedX = "x";
var expectedY = "z";
// Assert
Assert.AreEqual(expectedX, actualX);
Assert.AreEqual(expectedY, actualY);
}