-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder_test.go
55 lines (41 loc) · 1.06 KB
/
builder_test.go
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
package di
import (
"testing"
"github.com/fluffy-bunny/fluffy-dozm-di/reflectx"
)
func TestContainerBuilder_Contains(t *testing.T) {
b := Builder()
AddTransient[int](b, func() int { return 1 })
if !b.Contains(reflectx.TypeOf[int]()) {
t.Error("assertion failed")
}
if b.Contains(reflectx.TypeOf[*int]()) {
t.Error("assertion failed")
}
if b.Contains(reflectx.TypeOf[string]()) {
t.Error("assertion failed")
}
}
func TestContainerBuilder_Remove(t *testing.T) {
b := Builder()
AddTransient[int](b, func() int { return 1 })
AddTransient[int](b, func() int { return 2 })
AddTransient[string](b, func() string { return "a" })
if !b.Contains(reflectx.TypeOf[int]()) {
t.Error("assertion failed")
}
b.Remove(reflectx.TypeOf[int]())
if b.Contains(reflectx.TypeOf[int]()) {
t.Error("assertion failed")
}
if !b.Contains(reflectx.TypeOf[string]()) {
t.Error("assertion failed")
}
c := b.Build()
if _, err := TryGet[int](c); err == nil {
t.Error("assertion failed")
}
if _, err := TryGet[string](c); err != nil {
t.Error("assertion failed")
}
}