Last active
December 24, 2015 23:48
-
-
Save isaacabraham/6882535 to your computer and use it in GitHub Desktop.
A few tests that illustrate how JustMockLite easily handles recursive mocks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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