How Dynamic Mock Objects can Auto Pilot

When creating a Mock Object from an interface, the object is set in Strict mode. This means that any unexpected call to the object will fail.
The reason is quite simple. It is because there is no real implementation of any methods.

Since version 3.6.1 Dynamic Mock Objects will have a real default implementation. The implementation will return default values when ever a method is called and will build properties to act as simple properties (after setting a property, you will be able to read it).

To enable this feature you will have to turn off the strictness of these mocks.

Here is an example interface

public interface IImplement { int MyProperty { get; set; } }

Here is test that shows the auto pilot property works.

Natural Mocks:

[Test] public void AutoPilotProperties() { IImplement mockImpl = (IImplement)RecorderManager.CreateMockedObject( typeof(IImplement), StrictFlags.ArbitraryMethodsAllowed); mockImpl.MyProperty = 10; Assert.AreEqual(10, mockImpl.MyProperty); }

Reflective mocks:

[Test] public void AutoPilotProperties() { MockObject mock = MockManager.MockObject(typeof(IImplement)); IImplement mockImpl = mock.Object as IImplement; mock.Strict = false; mockImpl.MyProperty = 10; Assert.AreEqual(10, mockImpl.MyProperty); }

31 October 2006 | .NET Tests | Comments | Print This Post

4 Responses to “How Dynamic Mock Objects can Auto Pilot”

  1. 1 Eli Lopian’s Blog (TypeMock) » Blog Archive » New and Noteworthy - Version 3.6.1 24 August 2007 @ 9:17 pm

    […] TypeMock.NET now creates a default implementation for interfaces and abstract methods. This allows natural property behavior and non strict method calls […]

  2. 2 teen mia hentai 5 September 2008 @ 3:14 am

    mia pussy hentai mia hentai teen

  3. 3 evista windows 20 September 2008 @ 10:09 am

    lcars evista lcars evista

  4. 4 Lucia Mcbride 13 November 2008 @ 3:02 am

    2zrl43zj259koxz7

Leave a Reply

  1.  
  2.  
  3.  
Search Development and Integrity Management by Eli Lopian

Navigation

Recent Posts

Categories

Archives

Managment