Hi Scott,
First off thanks for the speedy reply, I've only made a few posts on the forum but all of them have been replied to quickly.
Anyway I'm not sure that not calling
Verify explains what I'm getting. If the class was already mocked then this line would cause a
TypeMockException to be thrown:
Mock mockForToTest = MockManager.MockAll(typeof(ToTest), Constructor.NotMocked);
What I'm seeing does not seem to be that
ToTest class is already mocked when
Mocked runs, its actually that I'm failing to mock the class at all.
To try and show this I've added the
Verify call (I forgot to put it in my example) and an
Assert that verifies that the class has not already run to try and prove that this is the case.
Also the
Unmocked test does run first in this case, to prove this I've added a
Debug.WriteLine to each test. The output you get is:
------ Test started: Assembly: TypemockTest.dll ------
Unmocked
Mocked
TestCase 'ErrorWithMocking.Tests.Mocked' failed: The class is not mocked
d:documents and settingsdevmy documentsisual studio projectsserviceschapter1 ypemocktestclass1.cs(43,0): at ErrorWithMocking.Tests.Mocked()
1 succeeded, 1 failed, 0 skipped, took 0.19 seconds.
---------------------- Done ----------------------
I may be being dumb here but I can't see why the mocking is failing.
using System;
using System.Diagnostics;
using NUnit.Core;
using NUnit.Framework;
using TypeMock;
namespace ErrorWithMocking
{
[TestFixture]
public class Tests
{
[TearDown]
public void TearDown()
{
MockManager.Verify();
}
[Test]
public void UnMocked()
{
Debug.WriteLine("Unmocked");
ToTest toTest = new ToTest();
Assert.IsFalse(toTest.Mocked, "The class should not be mocked");
}
[Test]
public void Mocked()
{
Debug.WriteLine("Mocked");
MockManager.Init();
Assert.IsFalse(MockManager.IsTypeMockedAll(typeof(ToTest)));
Mock mockForToTest = MockManager.MockAll(typeof(ToTest), Constructor.NotMocked);
mockForToTest.ExpectGetAlways("Mocked", true);
ToTest toTest = new ToTest();
Assert.IsTrue(toTest.Mocked, "The class is not mocked");
}
}
internal class ToTest
{
internal bool Mocked
{
get
{
return false;
}
}
}
}