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
Can not run example in nunit still? Very frustrated!
Have "run mocking_on.bat" before load dll in nunit, still get the prompt "MockInserter not running, please run mocking_on.bat..."


BTW, HOW TO POST A SCREEN SNAP??? That could make troubles easier to be understood.[/url]
asked by kyue (4.6k points)

9 Answers

0 votes
Hi,

First try running the tests from the command line.

Program FilesTypeMock.NETTypeMock.NETmocking_on.bat
Program FilesNUnit 2.2in
unit-console.exe <your-dll>


Next in Visual Studio with TestDriven.NET:
1. Verify that the Addin is loaded (You will see 'Disable TypeMock' in the Tools Menu)
2. Restart the Rocket (in the notifications area)
3. Run Tests

Remember, TypeMock has to be enabled BEFORE the testing executable is run. So if you run the GUI, you must start it after turning on mocks.
answered by scott (32k points)
0 votes
Hi, I am newbiew. And i encoutered the same problem when I use the sample code to compile.

Because I cannot succeed to compile it. However, these code is from the TypeMock document. It should be excuted successfully.

The error message is that "Error 1, Expected class, delegate, enum, interface, or struct". It showed that " public bool is worng, could help for this? Thanks.

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using TypeMock;


   public bool IsAuthenticated(string name,string password)
   { 
      Logger.Log(Logger.NORMAL,"Entering Authentication");
      try 
      {
            // do something
            int Results = DoSelect(statement);
            bool isOk = Results==1;
            if (isOk) 
            {
                  Logger.Log(Logger.NORMAL,"User Authenticated "+name);
            } 
            else 
            {
                  Logger.Log(Logger.SECURITY,"User login failed "+name);
            }
            return isOk;
      } 
      catch (Exception ex) 
      {
            Logger.Log(Logger.FAILED,"Login system failure",ex);
            // handle exception
      }
   }

 [TestFixture]
    public class AccountTest
    {

        [Test]
        public void Authenticated()
        {
            Authentication authenticator = new Authentication();
            // Initialize Type Mocks (This can be done in the [Setup])
            MockManager.Init();
            // the Logger class is now being mocked
            Mock logMock = MockManager.Mock(typeof(Logger));
            // set up our expectations for 2 Log calls in IsAuthenticated 
            // 1) "Entering Authentication" Log at first line 
            // 2) "User login failed user" Log 
            logMock.ExpectCall("Log");
            logMock.ExpectCall("Log");

            // authentication should fail
            Assert.IsFalse(authenticator.IsAuthenticated("user", "password"));
            // Verify that all calls were made (This can be done in the [Teardown]) 
            MockManager.Verify();
        }
    }
answered by flying13 (1.2k points)
0 votes
Thanks for quick reply.
But didn't get at this part still, "2. Restart the Rocket (in the notifications area) ", what do you mean notifications area please?
answered by kyue (4.6k points)
0 votes
I cannot find any icon related with the TypeMock in the notification area
(the rightdown area of desktop)
answered by flying13 (1.2k points)
0 votes
The icon in the notification area is the TestDriven.NET addin icon. This is an addin that enables running NUnit right out of the Visual Studio.
It is NOT part of TypeMock.NET.
If you use this addin and you enable TypeMock, remember to restart the rocket :-)

If you are looking for examples, please use the examples that are supplied with the installation:
Browse: Program FilesTypeMock.NETTypeMock.NETExamplescsharp
and Program FilesTypeMock.NETTypeMock.NETExamplesVB.NET


flying13: Where did you get the example from?
answered by scott (32k points)
0 votes

flying13: Where did you get the example from?


The code I used is all from "Working with TypeMock.NETThe First Mock of User Guide of TypeMock.NET.
answered by flying13 (1.2k points)
0 votes
The code I used is all from "Working with TypeMock.NETThe First Mock of User Guide of TypeMock.NET.


I hope you found the examples already.
The User Guide just shows parts of the code and not the complete code.
answered by scott (32k points)
0 votes
I got around this by adding a link to the nunit gui in the external tools menu of VS.

As long as the tools menu add-in is enabled in VS just launch your gui from the link you add to the tools menu and it works just fine.

Saves me messing around with bat files etc. and is handy having the gui link directly in your ide :D

Hope this helps.
answered by c0d3-m0nk3y (8.7k points)
0 votes
Hi,
This should be much easier in version 3.1 (Professional and Enterprise Editions)
with Nantand MSBuildintegration.
We also have examples ready for Visual Studio 2003 and 2005. (although some will not work without an enterprise license)
answered by scott (32k points)
...