Browsing all articles from January, 2007
Jan
21
Comments

Beginners Forum

Author Eli Lopian    Category .NET Tests     Tags

We are beginning to see more and more complex questions on our community forums. This is great news as our customers are using the more complex features of TypeMock.NET. But it is getting harder for novice and beginner developers to get support and perhaps some of them are a bit intimidated to ask simple questions in our forums. So we created a Beginners Forum to cater for all novice customers.

What do you think of this?

Jan
21
Comments

How to Mock an Initialization Method

Author Eli Lopian    Category .NET Tests     Tags

I have come across this scenario a few times, where developers want to swap a method with another method. Here is a quick example:

Suppose we have an initlization method called FillIt(). This method expects a List and fills it with data (from a database for example)

private void FillIt(List theList) { // connect to database and fill the list }

Now in our test, we don’t want to connect to the database, we want to mock this method but we want to fill the list with fake data. We would actually like to tell TypeMock to call another method instead

private void MockedFillIt(List theList) { // fake data for test theList.Add("Item 1"); }

Well we can’t really do this yet. What we can do is call the DynamicReturnValue delegate that will fill the list for us

Mock theMock = MockManager.Mock(typeof(TheType)); theMock.ExpectAndReturn("FillIt", new DynamicReturnValue(MockedFillIt)); ... // Called when FillIt is called private object MockedFillIt(object[] parameters, object that) { List theList = (List)parameters[0]; // fake data for test theList.Add("Item 1"); return null; // FillIt is void }

Notes:

1. You can use ExpectAndReturn for void methods when the return value is DynamicReturnValue
2. The delegate is executed when the mocked method is called
3. The delegate receives the actuall mocked object (context) and arguments.
4. The return value is ignored for void methods.

QUESTION

Do you think that we should have another API for this scenario?
e.g

theMock.ExpectCall("FillIt").Perform(MockedFillIt);
Jan
21
Comments

Donation outcome

Author Eli Lopian    Category .NET Tests     Tags

Jamie has managed to donate over $10,000 towards Creating Safe Drinking Water. We have been delighted to participate. Way to go Jamie

Jan
21
Comments

Microsoft Developer Academy

Author Eli Lopian    Category .NET Tests     Tags

You are all welcome to our booth in the Microsoft Developers Academy on the 31 January, 2007.

Come see the latest technology in Agile Development at our booth.

Jan
21
Comments

Back in Town

Author Eli Lopian    Category .NET Tests     Tags

I am back in town after a business trip and vacation.

So I am back to bogging