3 Answers, 1 is accepted
0
Hello Adiel,
Tsvetomir
Telerik
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
0
Adiel
Top achievements
Rank 2
answered on 28 Aug 2013, 11:36 AM
Hello Tsvetomir
This capability is clear.
My question was could I mock the interface if it's not a parameter of the ctor?
Regards
Adiel
This capability is clear.
My question was could I mock the interface if it's not a parameter of the ctor?
Regards
Adiel
0
Hi Adiel,
I am sorry that I've misunderstood you.
The scenario you are asking me is not possible at the moment. For now we support only .ctor injection.
We are working on a new feature, which will enable you to mock interface properties of future instances. This feature is scheduled for one of next internal builds of JustMock.
Thank you for your time and cooperation.
Regards,
Tsvetomir
Telerik
I am sorry that I've misunderstood you.
The scenario you are asking me is not possible at the moment. For now we support only .ctor injection.
We are working on a new feature, which will enable you to mock interface properties of future instances. This feature is scheduled for one of next internal builds of JustMock.
Thank you for your time and cooperation.
Regards,
Tsvetomir
Telerik