Hello Adiel,
Yes, you can mock properties using MockingContainer. You can find additional information here http://www.telerik.com/help/justmock/properties_t_telerik_justmock_container_mockingcontainer_1.html .
Here is an example of automocking where a mocked property (Balance) is used
public class AccountService
{
public AccountService(IAcccount fromAccount, IAcccount toAccount)
{
this.fromAccount = fromAccount;
this.toAccount = toAccount;
}
public void TransferFunds(decimal amount)
{
if (fromAccount.Balance <= amount)
{
fromAccount.Withdraw(amount);
toAccount.Deposit(amount);
}
}
private IAcccount fromAccount;
private IAcccount toAccount;
}
public interface IAcccount
{
decimal Balance { get; }
void Withdraw(decimal amount);
void Deposit(decimal amount);
}
[TestMethod]
public void AutoMockingProperyExample()
{
var container = new MockingContainer<
AccountService
>();
decimal expectedBalance = 100;
container.Arrange<
IAcccount
>(x => x.Balance, Take.First()).Returns(expectedBalance);
container.Arrange<
IAcccount
>(x => x.Withdraw(expectedBalance), Take.First()).MustBeCalled();
container.Arrange<
IAcccount
>(x => x.Deposit(expectedBalance), Take.Last()).MustBeCalled();
container.Instance.TransferFunds(expectedBalance);
container.Assert();
}
Don't hesitate to contact us if you have other questions.
Regards,
Tsvetomir
Telerik
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our
forums, or our
JustTrace or
JustMock portals.