Typemock exception:Cannot call Isolate.Verify.WasCalledWithArguments without a closing Matching function

0 votes


I do not know how this exception is coming when calling the test case.

I do not have any Isolate.Verify.WasCalledWithArguments in the method.

My sample code:

        public void TraceCachingManager_Cache_HttpContext_Test1()
            Mock configurationManagerMock = MockManager.Mock(typeof(ConfigurationManager));
            NameValueCollection customSettings = new NameValueCollection();
            customSettings.Add("LogLastTenSqlTraces", "true");
            configurationManagerMock.CallStatic.ExpectGetAlways("AppSettings", customSettings);
            Isolate.WhenCalled(() => HttpContext.Current).ReturnRecursiveFake();
            IDictionary dictionary = new AdapterDictionary();
            Isolate.WhenCalled(() => HttpContext.Current.Items).WillReturn(dictionary);

            string testCachedKey = "SqlCommandsKey";

            Command command = new Command("up_api_AuthorisedUserGet", CommandType.SqlStoredProcedure);
            command.Parameters.Add(new CommandParameter("@iUserId", 1));
            command.Parameters.Add(new CommandParameter("@iCustomerId", 11209));

            Isolate.WhenCalled(() => TraceCachingManager.AddItem(null, (Command)null)).CallOriginal();

            TraceCachingManager.AddItem(testCachedKey, command);
            string[] array = new string[1];
            HttpContext.Current.Items.Keys.CopyTo(array, 0);
            // Assert
            Assert.AreEqual("SqlCommandsKey", array[0]);

it is erroring out in this first method of the class but all other methods passed.

I can see other methods do call the verify method but those are passed and it is unusual that it states error in the method which i do not have that syntax.

when i run individually it is passed but whole test in the project it fails.

For your reference the sample method which call Isolate.Verify.WasCalledWithArguments

        public void Execute_With_Command_ThrowsException()
            IDataProvider providerMock = Isolate.Fake.Instance<IDataProvider>();
            ICommand commandMock = Isolate.Fake.Instance<ICommand>();
            DataContext ctx = new DataContext(providerMock);
            Isolate.WhenCalled(() => providerMock.Execute(null)).WillThrow(SqlHelper.CreateSqlException(1, "test proc"));
                ResultSet rs = ctx.Execute(commandMock);
            catch (SqlException ex)
                bool knownError = false;
                if (ex.Message == "Test Message")
                    knownError = true;

                if (!knownError)
                    throw ex;

            Isolate.Verify.WasCalledWithArguments(() => providerMock.Execute(commandMock));

Please help me out i could not able to get any clue

asked Feb 10 by Karthik (120 points)

1 Answer

0 votes


The API you probrably need is


Or use

Isolate.Verify.WasCalledWithArgument(()=>...).Matching(a => ...)

See here

The reason that it doesn't tell you on the correct test is that you forgot to use [Isolated] Attribute on test/class (see here)

answered Feb 19 by eli (5,770 points)