chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
the test bellow is not expected to pass cause i never atteched the NeedCriteria event
        [Test]
        [VerifyMocks]
        [ClearMocks]
        public void AddGrid()
        {
            var ecmsFieldParentChild = (EcmsFieldParentChild) EcmsField.Factory(EcmsFieldType.ParentChild, true);
            var tableRow = new TableRow();
            var radGridController = new RadGridController();

            using (RecordExpectations expectations = RecorderManager.StartRecording())
            {
                radGridController.NeedCriteria += null;
            }


            formCreator.AddGrid(ecmsFieldParentChild, tableRow, 2, new List<IBaseFieldControl>());


        }

but the code bellow fails as expected
 [Test]
        [VerifyMocks]
        [ClearMocks]
        public void AddGrid()
        {
            var ecmsFieldParentChild = (EcmsFieldParentChild) EcmsField.Factory(EcmsFieldType.ParentChild, true);
            var tableRow = new TableRow();
            var radGridController = new RadGridController();

            using (RecordExpectations expectations = RecorderManager.StartRecording())
            {
                radGridController.NeedCriteria += null;
            }


            formCreator.AddGrid(ecmsFieldParentChild, tableRow, 2, new List<IBaseFieldControl>());

MockManager.Verify();
        }


------ Test started: Assembly: GreekGeeks.Ementor.Controls.Fixtures.dll ------

Gallio TestDriven.Net Runner - Version 3.0 build 0

Test Assemblies:
   E:\NET Solutions\Csharp\WM\GreekGeeks2\GreekGeeks.Ementor.Controls.Fixtures\bin\Debug\GreekGeeks.Ementor.Controls.Fixtures.DLL

Verifying assembly names.
Initializing the test runner.
Initalizing the test runner.
Start time: 3:01 μμ
Loading the test package.
Exploring the tests.
Running the tests.
TestCase 'MbUnit v3.0.0.285/GreekGeeks.Ementor.Controls.Fixtures/FormCreatorFixture/AddGrid' failed: 
   TypeMock.VerifyException: 
   TypeMock Verification: Method GreekGeeks.Ementor.Controls.RadGridController.add_NeedCriteria() has 1 more expected calls
   
   at TypeMock.MockManager.Verify()
   E:\NET Solutions\Csharp\WM\GreekGeeks2\GreekGeeks.Ementor.Controls.Fixtures\FormCreatorFixture.cs(130,0): at GreekGeeks.Ementor.Controls.Fixtures.FormCreatorFixture.AddGrid()
   at TypeMock.VerifyMocksAttribute.Execute()
   at TypeMock.MethodDecorator.e()
   at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
   at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
   E:\NET Solutions\Csharp\WM\GreekGeeks2\GreekGeeks.Ementor.Controls.Fixtures\FormCreatorFixture.cs(110,0): at GreekGeeks.Ementor.Controls.Fixtures.FormCreatorFixture.AddGrid()
   c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Utilities\ExceptionUtils.cs(97,0): at Gallio.Utilities.ExceptionUtils.RethrowWithNoStackTraceLoss(Exception ex)
   c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Utilities\ExceptionUtils.cs(120,0): at Gallio.Utilities.ExceptionUtils.InvokeMethodWithoutTargetInvocationException(MethodBase method, Object obj, Object[] args)
   c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Framework\Pattern\PatternTestInstanceState.cs(361,0): at Gallio.Framework.Pattern.PatternTestInstanceState.InvokeTestMethod()
   c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Framework\Pattern\TestMethodPatternAttribute.cs(158,0): at Gallio.Framework.Pattern.TestMethodPatternAttribute.<SetTestSemantics>b__1(PatternTestInstanceState testInstanceState)
   c:\RelEng\Projects\MbUnit v3\Work\src\MbUnit\MbUnit\Framework\TestAttribute.cs(99,0): at MbUnit.Framework.TestAttribute.<SetTestSemantics>b__0(PatternTestInstanceState state, Action`1 action)
   c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\ActionChain.cs(131,0): at Gallio.ActionChain`1.<>c__DisplayClass1.<Around>b__0(T obj)
   c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Framework\Pattern\PatternTestInstanceActions.cs(182,0): at Gallio.Framework.Pattern.PatternTestInstanceActions.ExecuteTestInstance(PatternTestInstanceState testInstanceState)
   c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Framework\Pattern\PatternTestInstanceActions.cs(182,0): at Gallio.Framework.Pattern.PatternTestInstanceActions.ExecuteTestInstance(PatternTestInstanceState testInstanceState)
   c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Framework\Pattern\PatternTestInstanceActions.cs(182,0): at Gallio.Framework.Pattern.PatternTestInstanceActions.ExecuteTestInstance(PatternTestInstanceState testInstanceState)
   c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Framework\Pattern\PatternTestExecutor.cs(446,0): at Gallio.Framework.Pattern.PatternTestExecutor.<>c__DisplayClass26.<DoExecuteTestInstance>b__24()
   c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Concurrency\ThreadAbortScope.cs(156,0): at Gallio.Concurrency.ThreadAbortScope.RunWithThreadAbort(Action action)
   c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Concurrency\ThreadAbortScope.cs(75,0): at Gallio.Concurrency.ThreadAbortScope.Run(Action action)
   c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Framework\Sandbox.cs(275,0): at Gallio.Framework.Sandbox.RunWithScope(ThreadAbortScope scope, Action action, String description)

Unloading the test package.
Generating reports.
Stop time: 3:01 μμ (Total execution time: 9,622 seconds)
Disposing the test runner.
TestResults: file:///C:/Documents%20and%20Settings/abekiaris/Local%20Settings/Temp/Gallio.TDNetRunner/GreekGeeks.Ementor.Controls.Fixtures.DLL.html

0 passed, 1 failed, 0 skipped, took 12,58 seconds.


asked by (28.8k points)

2 Answers

0 votes
Hi,

A hunch, try removing the [ClearMock] in your original test.
I think that the that attribute is applied before the verify which causes all the expectation to be cleared just before the verification.

:arrow: If that works let me know, cause naturally this need fixing.

:idea: In general I would advise using [ClearMocks] on the class level. and using the [VerifyMocks] on the test level.
answered by (13.2k points)
0 votes
You should never use VerifyMocks and ClearMocks together.
VerifyMocks does a ClearMocks
answered by (5.1k points)
...