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
.Net 1.1
NUnit 2.2
TypeMock 3.0.3.0

Test Fixture Code:
using System;
using NUnit.Framework;
using Rbsfm.Common.Sentinel.SessionState.WebServices.SessionStores;
using TypeMock;

namespace Rbsfm.Common.Sentinel.SessionState.WebServices
{
   [TestFixture]
   public class SessionPersistTest
   {
      protected SessionPersist sessionPersist;

      protected Mock mockStaticSessionStore;

      protected string expectedSessionId;
      protected string expectedSessionVariableName;
      protected string expectedSessionVariableValue;

      [SetUp]
      public void SetUp()
      {
         this.expectedSessionId = Guid.NewGuid().ToString();

         this.expectedSessionVariableName = "TestParam";
         this.expectedSessionVariableValue = "TestParamValue";

         MockManager.Init();

         this.mockStaticSessionStore = MockManager.MockAll(typeof(StaticSessionStore), Constructor.NotMocked);

         this.sessionPersist = new SessionPersist();
      }

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

      [Test]
      public void SetSessionDataTest()
      {
         this.mockStaticSessionStore.ExpectCall("SetSessionData").Args(this.expectedSessionId, this.expectedSessionVariableName, this.expectedSessionVariableValue);

         this.sessionPersist.SetSessionData(this.expectedSessionId, this.expectedSessionVariableName, this.expectedSessionVariableValue);
      }

      [Test]
      public void GetSessionDataTest()
      {
         this.mockStaticSessionStore.ExpectCall("GetSessionData").Args(this.expectedSessionId, this.expectedSessionVariableName);

         this.sessionPersist.GetSessionData(this.expectedSessionId, this.expectedSessionVariableName);   
      }

      [Test]
      public void ReleaseSession()
      {
         this.mockStaticSessionStore.ExpectCall("ReleaseSession").Args(this.expectedSessionId);

         this.sessionPersist.ReleaseSession(this.expectedSessionId);
      }
   }
}


These tests pass just fine when run in NUnit Gui application but fail as follows when run using:
tmockrunner nunit-console myTestAssembly.dll


NUnit version 2.2.0
Copyright (C) 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, C
harlie Poole.
Copyright (C) 2000-2003 Philip Craig.
All Rights Reserved.

OS Version: Microsoft Windows NT 5.1.2600.0    .NET Version: 1.1.4322.2052

......F.F.F
Tests run: 8, Failures: 3, Not run: 0, Time: 0.2812824 seconds

Failures:
1) Rbsfm.Common.Sentinel.SessionState.WebServices.SessionPersistTest.SetSessionD
ataTest :
TearDown : TypeMock.VerifyException :
TypeMock Verification: Method Rbsfm.Common.Sentinel.SessionState.WebServices.Ses
sionStores.StaticSessionStore.SetSessionData() has 1 more expected calls


--TearDown
   at TypeMock.MockManager.Verify()
   at Rbsfm.Common.Sentinel.SessionState.WebServices.SessionPersistTest.TearDown
() in c:devwebdotnet.1
bsfm.common.sentinel.sessionstate.webservices.test
sessionpersisttest.cs:line 38

2) Rbsfm.Common.Sentinel.SessionState.WebServices.SessionPersistTest.GetSessionD
ataTest :
TearDown : TypeMock.VerifyException :
TypeMock Verification: Method Rbsfm.Common.Sentinel.SessionState.WebServices.Ses
sionStores.StaticSessionStore.GetSessionData() has 1 more expected calls


--TearDown
   at TypeMock.MockManager.Verify()
   at Rbsfm.Common.Sentinel.SessionState.WebServices.SessionPersistTest.TearDown
() in c:devwebdotnet.1
bsfm.common.sentinel.sessionstate.webservices.test
sessionpersisttest.cs:line 38

3) Rbsfm.Common.Sentinel.SessionState.WebServices.SessionPersistTest.ReleaseSess
ion :
TearDown : TypeMock.VerifyException :
TypeMock Verification: Method Rbsfm.Common.Sentinel.SessionState.WebServices.Ses
sionStores.StaticSessionStore.ReleaseSession() has 1 more expected calls


--TearDown
   at TypeMock.MockManager.Verify()
   at Rbsfm.Common.Sentinel.SessionState.WebServices.SessionPersistTest.TearDown
() in c:devwebdotnet.1
bsfm.common.sentinel.sessionstate.webservices.test
sessionpersisttest.cs:line 38


I have TypeMock.out but it is very large and the mocked methods are not at the end of the file.

Please advise how I can forward the .out file.
asked by c0d3-m0nk3y (8.7k points)

2 Answers

0 votes
Hi,
There is no need to send the typemock.out file yet.
This case is normally due to the gui running in a different order then the console.

It seems as though the StaticSessionStore was called before MockManager.Init() was called. If it is instantiated in a test (which is run before MockManager.Init) then it won't be mocked.

To solve this just run MockManager.Init() in the other tests (even though you don't need to use any mocks) this will make sure that when StaticSessionStore is JITed the the mock code is insterted into the class.

In future versions we are going to solve this scenario.
answered by scott (32k points)
0 votes
Hi,
This is fixed in version 3.1, where automatic initilization is implemented for known testing frameworks
answered by scott (32k points)
...