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); }
4 Comments to “How Dynamic Mock Objects can Auto Pilot”
Recent Posts
- Top 5 questions to ask when checking references
- Unacceptable: Unit testing will take 20 years to catch on
- The 4 reasons why we DIDN’T choose Oslo
- Typemock Academy Launch
- The First Rule to Software Craftsmanship
Categories
- .NET Tests
- Agile
- Code Integrity
- Community
- Debugging
- Fun
- Management for Geeks
- Marketing
- Product
- Release
- Reviews
- SharePoint
- TDD
- Time Management
- Uncategorized
- Unit Tests
Archives
- August 2010
- May 2010
- April 2010
- March 2010
- February 2010
- December 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- December 2008
- November 2008
- August 2008
- July 2008
- May 2008
- April 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006

[...] TypeMock.NET now creates a default implementation for interfaces and abstract methods. This allows natural property behavior and non strict method calls [...]
mia pussy hentai mia hentai teen
lcars evista lcars evista
2zrl43zj259koxz7