This is a migrated thread and some comments may be shown as answers.
Mocking methods with optional parameters?
1 Answer 67 Views
This is a migrated thread and some comments may be shown as answers.
Graham
Top achievements
Rank 1
Graham asked on 25 Apr 2012, 08:14 PM
Is it possible to mock out a method with optional parameters? I can't seem to figure out how to do it.

1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 30 Apr 2012, 07:46 PM
Hi Graham,

Thanks for bringing up the question. Yes you can mock method(s) with optional argument using JustMock. Please take a look into the following example that should give you some pointers.

   [Test]
       public void ShouldAssertMockingMethodWithOptionalArgument()
       {
           var foo = Mock.Create<Foo>();
 
           Mock.Arrange(() => foo.Submit(true)).MustBeCalled();
 
           foo.Submit();
 
           Mock.Assert(foo);
       }
 
       public class Foo
       {
           public void Submit(bool visible = true)
           {
               // nothing
           }
       }


Kind Regards
Ricky
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Asked by
Graham
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or