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
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 SolutionsCsharpWMGreekGeeks2GreekGeeks.Ementor.Controls.FixturesinDebugGreekGeeks.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 SolutionsCsharpWMGreekGeeks2GreekGeeks.Ementor.Controls.FixturesFormCreatorFixture.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 SolutionsCsharpWMGreekGeeks2GreekGeeks.Ementor.Controls.FixturesFormCreatorFixture.cs(110,0): at GreekGeeks.Ementor.Controls.Fixtures.FormCreatorFixture.AddGrid()
   c:RelEngProjectsMbUnit v3WorksrcGallioGallioUtilitiesExceptionUtils.cs(97,0): at Gallio.Utilities.ExceptionUtils.RethrowWithNoStackTraceLoss(Exception ex)
   c:RelEngProjectsMbUnit v3WorksrcGallioGallioUtilitiesExceptionUtils.cs(120,0): at Gallio.Utilities.ExceptionUtils.InvokeMethodWithoutTargetInvocationException(MethodBase method, Object obj, Object[] args)
   c:RelEngProjectsMbUnit v3WorksrcGallioGallioFrameworkPatternPatternTestInstanceState.cs(361,0): at Gallio.Framework.Pattern.PatternTestInstanceState.InvokeTestMethod()
   c:RelEngProjectsMbUnit v3WorksrcGallioGallioFrameworkPatternTestMethodPatternAttribute.cs(158,0): at Gallio.Framework.Pattern.TestMethodPatternAttribute.<SetTestSemantics>b__1(PatternTestInstanceState testInstanceState)
   c:RelEngProjectsMbUnit v3WorksrcMbUnitMbUnitFrameworkTestAttribute.cs(99,0): at MbUnit.Framework.TestAttribute.<SetTestSemantics>b__0(PatternTestInstanceState state, Action`1 action)
   c:RelEngProjectsMbUnit v3WorksrcGallioGallioActionChain.cs(131,0): at Gallio.ActionChain`1.<>c__DisplayClass1.<Around>b__0(T obj)
   c:RelEngProjectsMbUnit v3WorksrcGallioGallioFrameworkPatternPatternTestInstanceActions.cs(182,0): at Gallio.Framework.Pattern.PatternTestInstanceActions.ExecuteTestInstance(PatternTestInstanceState testInstanceState)
   c:RelEngProjectsMbUnit v3WorksrcGallioGallioFrameworkPatternPatternTestInstanceActions.cs(182,0): at Gallio.Framework.Pattern.PatternTestInstanceActions.ExecuteTestInstance(PatternTestInstanceState testInstanceState)
   c:RelEngProjectsMbUnit v3WorksrcGallioGallioFrameworkPatternPatternTestInstanceActions.cs(182,0): at Gallio.Framework.Pattern.PatternTestInstanceActions.ExecuteTestInstance(PatternTestInstanceState testInstanceState)
   c:RelEngProjectsMbUnit v3WorksrcGallioGallioFrameworkPatternPatternTestExecutor.cs(446,0): at Gallio.Framework.Pattern.PatternTestExecutor.<>c__DisplayClass26.<DoExecuteTestInstance>b__24()
   c:RelEngProjectsMbUnit v3WorksrcGallioGallioConcurrencyThreadAbortScope.cs(156,0): at Gallio.Concurrency.ThreadAbortScope.RunWithThreadAbort(Action action)
   c:RelEngProjectsMbUnit v3WorksrcGallioGallioConcurrencyThreadAbortScope.cs(75,0): at Gallio.Concurrency.ThreadAbortScope.Run(Action action)
   c:RelEngProjectsMbUnit v3WorksrcGallioGallioFrameworkSandbox.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 tolisss (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 lior (13.2k points)
0 votes
You should never use VerifyMocks and ClearMocks together.
VerifyMocks does a ClearMocks
answered by eli (5.7k points)
...