Class DisableAutomaticRepositoryResetAttribute
Used to disable the automatic generation of calls to Mock.Reset() in test methods by the profiler.
Inheritance
Inherited Members
Namespace: Telerik.JustMock.Setup
Assembly: Telerik.JustMock.dll
Syntax
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public sealed class DisableAutomaticRepositoryResetAttribute : Attribute, _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
[Test]
public void MyTest()
{
... // body of test
}
...then the profiler wraps it in a try/finally block like so:
[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.
Constructors
DisableAutomaticRepositoryResetAttribute()
Declaration
public DisableAutomaticRepositoryResetAttribute()
Properties
AllowMocking
Allow the use of the mocking API inside this method. You must explicitly call Mock.Reset() at the end of your test method.
Declaration
public bool AllowMocking { get; set; }
Property Value
System.Boolean
|