Telerik JustMock
[TestMethod]
public
void
ShouldArrangeReturnForFutureUserDataInstances()
{
// Arrange
var fakeUsed = Mock.Create<UserData>();
Mock.Arrange(() => fakeUsed.ReturnFive()).IgnoreInstance().Returns(7);
// Assert
Assert.AreEqual(7, fakeUsed.ReturnFive());
Assert.AreEqual(7,
new
UserData().ReturnFive());
}
public
Foo GetNewFooInstance()
{
return
new
Foo();
}
[TestMethod]
public
void
ShouldReturnNewObjectForFutureInstances()
{
// ARRANGE - Every new instantiation of the Foo class should return a predefined instance.
var testObj =
new
Foo() { MyProp =
"Test"
};
// Directly arranging the expression to return our predefined object.
Mock.Arrange(() =>
new
Foo()).Returns(testObj);
// ACT
var myNewInstance = GetNewFooInstance();
// ASSERT
Assert.IsNotNull(myNewInstance);
Assert.IsInstanceOfType(myNewInstance,
typeof
(Foo));
// Assert that the returned instance is equal to the predefined.
Assert.AreEqual(
"Test"
, myNewInstance.MyProp);
}