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
Ok,

I have two tests, one does not mock, and works, one mocks and fails with the following:

TearDown : TypeMock.VerifyException : 
TypeMock Verification: Method TypeMockTests.MainClass.GetSquare() has 1 more expected calls

--TearDown
   at TypeMock.Mock.Verify()
   at TypeMock.Expectations.Verify()
   at TypeMock.MockManager.Verify()
   at TypeMockTests.Test.MainClassTests.TearDown() in c:documents and settings
obpmy documentsisual studio projects	ypemocktests	estmainclasstests.cs:line 45



The thing is, I am pulling my hair out as to see why

My simple class is this

using System;

namespace TypeMockTests
{
   /// <summary>
   /// Summary description for Class1.
   /// </summary>
   
   public class MainClass
   {
      public MainClass()
      {
         //
         // TODO: Add constructor logic here
         //
      }

      public int GetSquare(int nNumber)
      {
         return (int)(nNumber*nNumber);
         
      }
   }
}



My tests are as follows, and I get this "TypeMock Verification: Method TypeMockTests.MainClass.GetSquare() has 1 more expected calls" error, and cannot work out why, please help !

using System;
using NUnit.Framework;
using TypeMock;

namespace TypeMockTests.Test
{
   /// <summary>
   /// Summary description for MainClassTests.
   /// </summary>
   [TestFixture]
   public class MainClassTests
   {
      [SetUp]
      public void SetUp()
      {
         MockManager.Init();
      }


      [Test]
      public void TestTheGetSquareFunctionWithCorrectValues()
      {
         MainClass rob = new MainClass();
         Assert.AreEqual(4,rob.GetSquare(2));
      }

      [Test]
      public void TestTheMockedClass()
      {
         
         Mock myMock = MockManager.Mock(typeof(MainClass));
         
         myMock.ExpectAndReturn("GetSquare",4);

         MainClass myClass = new MainClass();
         
         
         Assert.AreEqual(4,myClass.GetSquare(2));


      }

      [TearDown]
      public void TearDown()
      {
         MockManager.Verify();   
      }
   
   }
}

asked by robpearmain (2.8k points)

3 Answers

0 votes
Hi,
Change the namespace of MainClass, it cannot start with TypeMock, 8)
Sorry about this...
answered by scott (32k points)
0 votes
LOL, maybe needs adding to FAQ :D

This is such a good tool, many thanks for all your hard work
answered by robpearmain (2.8k points)
0 votes
Hi,
We should probrably do better then adding an FAQ.
TypeMock should fail with a nice message when trying to mock from a namespace that starts with TypeMock...
answered by scott (32k points)
...