/
MockObject.winxed
37 lines (32 loc) · 1.29 KB
/
MockObject.winxed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Mock Object Library
The MockObject library is an extension library to Rosella.Test for
creating tests with mock objects.
This namespace provides some convenience routines for working with
mock objects.
*/
namespace Rosella.MockObject
{
const string DEFAULT_MOCK_FACTORY_KEY = "Rosella.MockObject.default_factory";
// Get a default MockObject.Factory instance from the global registry.
// MockObject.Factory is not a typed ObjectFactory, so a global
// instance can typically be used without causing too many problems.
function default_mock_factory()
{
return Rosella.Globals.autoget_global(DEFAULT_MOCK_FACTORY_KEY,
function() { return new Rosella.MockObject.Factory(); }
);
}
// Set a new MockObject instance in the global instance registry.
// This is useful for situations where we need to inject new default
// behavior, but can have negative effects if used improperly.
function set_default_mock_factory(var factory)
{
Rosella.Globals.register_global(DEFAULT_MOCK_FACTORY_KEY, factory);
}
// Use the default MockObject.Factory instance to create a new
// mock controller for the given type.
function get_controller(var type)
{
return default_mock_factory().create_typed(type);
}
}