-
Notifications
You must be signed in to change notification settings - Fork 0
Object disposal
xWellBehaved.net provides an easy way to ensure an object implementing IDisposable
is disposed after execution of a scenario.
This is done by simply calling the Using()
extension method immediately after creation of the IDisposable
object. The object is then registered by xWellBehaved.net for disposal immediately after all the steps in the scenario have been executed. xWellBehaved.net also guarantees disposal in the event of unhandled exceptions, rather like a C# using { }
block.
For instance, let us imagine our Calculator
is some bizarre steampunk museum piece which needs careful cooling down after usage and its Dispose()
method does this for us.
public class Calculator : IDisposable { ... }
[Scenario]
public void Addition(int x, int y, Calculator calculator, int answer)
{
"Given the number 1".x(() => x = 1);
"And the number 2".x(() => y = 2);
"And a calculator".x(context => calculator = new Calculator().Using(context));
"When I add the numbers together".x(() => answer = calculator.AssertNotNull().Add(x, y));
"Then the answer is 3".x(() => answer.AssertEqual(3));
}
context
is a context object managed by xWellBehave.net. Simply pass it through to the Using()
extension method.
- Home
- Quick start
-
Documentation
- Writing scenarios
- Running scenarios
- Package dependencies
- Debugging scenarios
- Assertions
- Step names
- Debugging Scenarios with examples
- Background methods
- TearDown methods
- Async steps
- Object disposal
- Rollback
- Skipping steps and scenarios
- Step metadata
- Continuing on failure
- Step filters
- Changes in xBehave.net version 2.0
- Changes since deriving from xBehave.net
- Extending xWellBehaved.net
- FAQ
- Known Issues
- Contributions