-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_resolve.cpp
More file actions
115 lines (88 loc) · 3.53 KB
/
Copy pathauto_resolve.cpp
File metadata and controls
115 lines (88 loc) · 3.53 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <catch2/catch.hpp>
#include <mosure/inversify.hpp>
#include "mock/fizz.hpp"
#include "mock/qux.hpp"
#include "mock/symbols.hpp"
namespace inversify = mosure::inversify;
SCENARIO("container resolves automatic values", "[resolve]") {
GIVEN("A container with automatic unique_ptr binding") {
inversify::Container<
symbols::foo,
symbols::bar,
symbols::autoFizzUnique,
symbols::autoFizzShared
> container;
container.bind<symbols::foo>().toConstantValue(10);
container.bind<symbols::bar>().toConstantValue(1.618);
container.bind<symbols::autoFizzUnique>().to<Fizz>();
WHEN("the dependency is resolved") {
auto result = container.get<symbols::autoFizzUnique>();
auto foo = result->buzz();
THEN("the correct value is returned") {
REQUIRE(foo == 10);
REQUIRE(result->counter == 1);
}
}
WHEN("multiple dependencies are resolved") {
auto result1 = container.get<symbols::autoFizzUnique>();
auto result2 = container.get<symbols::autoFizzUnique>();
result1->buzz();
result2->buzz();
THEN("the values are unique") {
REQUIRE(result1->counter == 1);
REQUIRE(result2->counter == 1);
REQUIRE(result1 != result2);
}
}
}
GIVEN("A container with automatic singleton shared_ptr binding") {
inversify::Container<
symbols::foo,
symbols::bar,
symbols::autoFizzUnique,
symbols::autoFizzShared
> container;
container.bind<symbols::foo>().toConstantValue(10);
container.bind<symbols::bar>().toConstantValue(1.618);
container.bind<symbols::autoFizzShared>().to<Fizz>().inSingletonScope();
WHEN("the dependency is resolved") {
auto result = container.get<symbols::autoFizzShared>();
auto foo = result->buzz();
THEN("the correct value is returned") {
REQUIRE(foo == 10);
REQUIRE(result->counter == 1);
}
}
WHEN("multiple dependencies are resolved") {
auto result1 = container.get<symbols::autoFizzShared>();
auto result2 = container.get<symbols::autoFizzShared>();
result1->buzz();
result2->buzz();
THEN("the values are equal") {
REQUIRE(result1->counter == 2);
REQUIRE(result2->counter == 2);
REQUIRE(result1 == result2);
}
}
}
GIVEN("A container with automatic nested bindings") {
inversify::Container<
symbols::foo,
symbols::bar,
symbols::autoFizzShared,
symbols::autoQuxUnique
> container;
container.bind<symbols::foo>().toConstantValue(10);
container.bind<symbols::bar>().toConstantValue(1.618);
container.bind<symbols::autoFizzShared>().to<Fizz>().inSingletonScope();
container.bind<symbols::autoQuxUnique>().to<Qux>();
WHEN("the dependency is resolved") {
auto result = container.get<symbols::autoQuxUnique>();
auto foo = result->buzz();
THEN("the correct value is returned") {
REQUIRE(foo == 15);
}
}
}
}