Telerik JustMock
ICurrencyService currencyService = Mock.Create<ICurrencyService>();
No physical file, no additional clutter. Еasy maintenance and increased productivity with just a few lines of code.[TestMethod]
public
void
ShouldAssertAgainstNonArrangedChainCallInRecursiveLooseMock()
{
// Arrange
// This equals to: Mock.Create<IFirst>();
var foo = Mock.Create<IFirst>(Behavior.RecursiveLoose);
// Act
// This call will never encounter a NullReferenceException
var actual = foo.Second.Third.Fourth.DoSomething();
// Assert
Assert.IsNotNull(actual);
}
public
class
FooBase
{
public
string
GetString(
string
str)
{
return
str;
}
}
...
[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);
}
[TestMethod]
[ExpectedException(
typeof
(StrictMockException))]
public
void
ArbitraryCallsShouldGenerateException()
{
//Arrange
var foo = Mock.Create<IFoo>(Behavior.Strict);
//Act
foo.VoidCall();
}
ICurrencyService currencyService = Mock.Create<ICurrencyService>(Behavior.Loose);