This is a migrated thread and some comments may be shown as answers.

Why is Mock.Arrange().DoNothing() not available?

4 Answers 610 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
cori
Top achievements
Rank 1
cori asked on 13 Aug 2010, 03:36 AM
I'm trying to mock the static System.IO namespace methods in C#, so I have calls like this:

            Mock.SetupStatic<File>();
            Mock.Arrange( () => File.AppendText(Arg.AnyString)).DoNothing();

because I want to stop the filesystem from writing anything.  When I do so, however, I receive the following error:
'Telerik.JustMock.Expectations.FuncExpectation<System.IO.StreamWriter>' does not contain a definition for 'DoNothing' and no extension method 'DoNothing' accepting a first argument of type 'Telerik.JustMock.Expectations.FuncExpectation<System.IO.StreamWriter>' could be found (are you missing a using directive or an assembly reference?)

In a different test method in the same class using a static class of my own, I am able to make that call without any difficulty.

What am I missing?

4 Answers, 1 is accepted

Sort by
0
Accepted
Ricky
Telerik team
answered on 13 Aug 2010, 04:57 PM
Hello Cori,

Thanks for reporting the issue. I tried to mock File.AppendText the following way that works nicely:

[TestMethod]
public void ShouldStopFile_AppendTextForWriting()
{
    Mock.Arrange(() => File.AppendText(Arg.AnyString));
    File.AppendText("anything");
}


Therefore, I found out that DoNothing modifier is not available for members that return a value. But this an optional modifier added to increase readability and without it things should work just fine. But, yes that goes into our product backlog and should be fixed for the next build.

Also, please make sure that you have MockClassAttribute on top of your class which is required for mocking framework members.

Hope this information helps.

Regards,
Mehfuz

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
cori
Top achievements
Rank 1
answered on 13 Aug 2010, 05:15 PM
So is DoNothing() essentially just decoration - in other words, is that the default behavior of Mock.Arrange()?

I suppose that makes sense - if you're mocking a method and you don't tell the mock to do something then be default it will do nothing. Is that the way I should be interpreting this?
0
Chris
Telerik team
answered on 13 Aug 2010, 05:18 PM
Hello Cori,

Yes, exactly, DoNothing is just a decoration method which does nothing but improves readability. Omitting it won't change anything.

Kind regards,
Chris
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
cori
Top achievements
Rank 1
answered on 13 Aug 2010, 05:20 PM
Perfect, thanks!
Tags
General Discussions
Asked by
cori
Top achievements
Rank 1
Answers by
Ricky
Telerik team
cori
Top achievements
Rank 1
Chris
Telerik team
Share this question
or