Telerik® JustMock™ by Progress

Used to disable the automatic generation of calls to Mock.Reset() in test methods by the profiler.

Namespace: Telerik.JustMock.Setup
Assembly: Telerik.JustMock (in Telerik.JustMock.dll) Version: 2013.3.1021.0 (2013.3.1021.0)

Syntax

C#
[AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public sealed class DisableAutomaticRepositoryResetAttribute : Attribute
Visual Basic
<AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple := False, Inherited := False)> _
Public NotInheritable Class DisableAutomaticRepositoryResetAttribute _
	Inherits Attribute

Remarks

When the JustMock profiler is enabled, it is quite necessary to call Mock.Reset() at the end of every test method that does mocking or calls other methods that do mocking. This way you'll be sure that no state leaks from test to test and your tests always run at top speed. The JustMock profiler automatically adds calls to Mock.Reset() to the end of every test method that is in an assembly that has a reference to the Telerik.JustMock assembly. If your test method looks like
CopyC#
[Test]
public void MyTest()
{
    ... // body of test
}
...then the profiler wraps it in a try/finally block like so:
CopyC#
[Test]
public void MyTest()
{
    try {
        ... // body of test
    } finally {
        Mock.Reset();
    }
}
...thus ensuring that Mock.Reset() is called at the end of every test method without any burden imposed on the test author. Sometimes this try/finally block gets in your way though. For example, try/catch/finally blocks change the lifetime of objects in such a way that objects referenced only by WeakReferences will not be collected in the scope they're handled if you call GC.Collect() in that same scope. Whenever you have a test that passes with the JustMock profiler disabled, but fails when the profiler is enabled, *and* you don't use mocking in that test, the issue may be resolved by decorating your test with this attribute.

Inheritance Hierarchy

System..::..Object
  System..::..Attribute
    Telerik.JustMock.Setup..::..DisableAutomaticRepositoryResetAttribute

See Also