tags:

views:

30

answers:

2

I am new to using Mock test in .Net.
I am testing out a financial transaction which is of the following nature:

int  amt =20;
//sets all the props and func and returns a FinaceAccount.
//Note I did not SetUp the amt of the account.
var account =GetFinanceAccount() 


//service layer to be tested
_financeService.tranx(account,amt);

//checks if the amt was added to the account.amt
//here the amt comes out same as that set in GetFinanceAccount.
Assert.AreEqual(account.amt ,amt)  

I know that the function tranx works correctly but there is an issue with the test. Are there any GOOD reference material on Mocking in .Net

+1  A: 

This happens because, when you do SetupGet, you are essentially saying "When invoking this property, always return this value". What you want to do is probably "SetupProperty", which makes all properties on the mocked object behave as normal properties with get/set behaviour.

  Mock<Account> mockAccount = new Mock<Account>();
  mockAccount.SetupProperty(mock => mock.amt);
  // Perhaps set a initial value
  mockAccount.Object.amt = 10;
driis
A: 

I suggest you hook up your unit tests to visual studio go to properties and select debug then click start external program and select the nunit.exe then in the arguments add the complete path to the dll in the debug map of your tests project. This will enable you to debug your tests and step through everything. Now you can see what is going wrong.

Chino