Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
Last active December 24, 2015 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacabraham/6882535 to your computer and use it in GitHub Desktop.
Save isaacabraham/6882535 to your computer and use it in GitHub Desktop.
A few tests that illustrate how JustMockLite easily handles recursive mocks.
public interface Service
{
OtherService GetOtherService();
}
public interface OtherService
{
Int32 GetNumber();
}
public class Tests
{
[Fact]
public void ChildMockIsCreatedTest()
{
var service = Mock.Create<Service>();
// Act
var otherService = service.GetOtherService();
// Assert
Assert.IsAssignableFrom<OtherService>(otherService);
}
[Fact]
public void SameInstanceFromRecursiveMock()
{
var service = Mock.Create<Service>();
// Act
var otherService = service.GetOtherService();
var otherServiceTwo = service.GetOtherService();
// Assert
Assert.Same(otherService, otherServiceTwo);
}
[Fact]
public void MockResultOfRecursiveMock()
{
var service = Mock.Create<Service>();
Mock.Arrange(() => service.GetOtherService().GetNumber())
.Returns(123);
// Act
var actual = service.GetOtherService().GetNumber();
// Assert
Assert.Equal(123, actual);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment