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
Here is our preview of our next version. you can download it here
Feel free to comment on this post or via e-mail.


Main Features
1. New NaturalMocks, return a mock that has default behavior
recorder.ReturnDefaultImplementation()

2. New NarturalMocks Ability to create return values within the record session, you can now do:
using (RecordExpectations recorder = RecorderManager.StartRecording()) 
{ 
  MockedClass.Method (); 
  recorder.Return(new SqlInt32(1)); 
}

3. New, can mock signed internal interfaces (.NET 2.0+)
[assembly: InternalsVisibleTo(MockManager.DynamicMocksAssembly)]

4. New, Generics code sugar. (.NET 2.0+)
import TypeMock.Generics;

Creating Mocks
Mock mock = Mock<TestedClass>.MockNextInstance();
Mock mockAll = Mock<TestedClass>.MockAll();
MockObject<TestedClass> mock = MockObject<TestedClass>.Create();
  TestedClass t = mock.Object;

Finding Mocks
Mock<TestedClass>.IsTypeMocked();
Mock<TestedClass>.GetMockAll();

Generic Methods (Reflective Mocks)
Mock m = Mock<GenMethodClass>.MockNextInstance();
m.AlwaysReturn("GenMethod", 11, Generic.Method<int>());

Check Argument Type
mock.ExpectCall("Method").Args(Check<Boolean>.AreSameType(), Check.IsEqual(10));

Natural Mocks (Mock Object – for interfaces etc,)
TestedClass mocked = MockObject<TestedClass>.CreateObject();
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
   mocked.getVar();
   recorder.Return(10);
}


5. Fixed, save user configuration in user application folder
6. Fixed, Better Message when reflective mocking a non existing method
7. Fixed. Mocking multiple Chained Static Methods using default RepeatAlways
using (RecordExpectations recorder = RecorderManager.StartRecording()) 
{ 
  recorder.DefaultBehavior.RepeatAlways(); 
  MockedClass.Service.foo(); 
  MockedClass.Service.bar(); 
}

8. Fixed. Build Server (run with Nant/MSBuild script) will not halt build to show message box when license is about to expire
9. Fixed. AspNetHostingPermission attributes fail NaturalMocks in .NET 1.1
10. Added "Fast Mode" output to log
11. Support 30 day Evaluation license once per computer.
12. Fixed Failure when mock returns a Generic Type or Types with Generic Parameters that are defined in the parent type.
13. Lower Memory Consumption
asked by scott (32k points)

12 Answers

0 votes
1. Why CAN'T I copy the dll locally?

It is bad practice to copy the dll locally, as this WILL lead to problems when upgrading. You should reference the dll for compile but use the GAC'ed TypeMock for run-time.

I'm sure you meant:
Mock<TestedClass> mock

Actually I think that most uses for Mocks will not use the Generic Property mock.MockedInstance and to cut down on writing more code it is easier to cast up and use
Mock mock


1. If AbstractTestClass is an abstract class
MockObject<AbstractTestClass> m2 = MockManager.MockObject<AbstractTestClass>();
Assert.AreEqual("unmocked", m2.Object.Value);

throws an exception:
Test method TestProject1.ProgramFixture.TestMethod4 threw exception: TypeMock.VerifyException:
TypeMock Verification: Unexpected Call to TestProject1.AbstractTestClass.get_Value().

even is AbstractTestClass has an implementation for Value

:idea: All MockObjects of Abstract classes are Strict by default. To call the original methods do the following:
m2.Strict = false;
This will also create default implementations to all abstract Properties.
:?: Perhaps we should rethink this and allow all concrete methods.

2. (this one probably doesn't belong here) what is the difference between calling MockManager.MockObject() and calling RecorderManager.CreateMockedObject(), apart from the return types, of course?

RecorderManager.CreateMockedObject(); is the same as:
MockManager.MockObject().Object. It is used for NaturalMocks.
answered by scott (32k points)
0 votes
Hi folks,

I have just uploaded a new version of TestDriven.NET (2.6 Beta) that includes some support for NUnit 2.4 extensibility. To get this to work you will need to copy your NUnit extension assemblies to a new folder here:

Program FilesTestDriven.NET 2.0ddins

If you're using the 'Test With... NUnit 2.4' button on the project context menu you will also need to copy your extensions here:

Program FilesTestDriven.NET 2.0NUnit.4ddins

Obviously this duplication isn't ideal! I'm working with Charlie Poole and Eli Lopian to find a more permanent solution.

Thanks, Jamie.

--
http://www.testdriven.net
http://weblogs.asp.net/nunitaddin
answered by Jamie (140 points)
...