2021-05-14 07:41:25 +00:00
|
|
|
import 'package:angel3_container/angel3_container.dart';
|
2018-08-26 22:55:21 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
void main() {
|
2021-03-18 00:21:42 +00:00
|
|
|
late Container container;
|
2018-08-26 22:55:21 +00:00
|
|
|
|
|
|
|
setUp(() {
|
2019-10-12 13:34:15 +00:00
|
|
|
container = Container(const EmptyReflector())
|
|
|
|
..registerSingleton<Song>(Song(title: 'I Wish'))
|
2019-04-10 19:20:02 +00:00
|
|
|
..registerNamedSingleton('foo', 1)
|
2018-08-26 22:55:21 +00:00
|
|
|
..registerFactory<Artist>((container) {
|
2019-10-12 13:34:15 +00:00
|
|
|
return Artist(
|
2018-08-26 22:55:21 +00:00
|
|
|
name: 'Stevie Wonder',
|
|
|
|
song: container.make<Song>(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-10 19:20:02 +00:00
|
|
|
test('hasNamed', () {
|
|
|
|
var child = container.createChild()..registerNamedSingleton('bar', 2);
|
|
|
|
expect(child.hasNamed('foo'), true);
|
|
|
|
expect(child.hasNamed('bar'), true);
|
|
|
|
expect(child.hasNamed('baz'), false);
|
|
|
|
});
|
|
|
|
|
2018-08-26 22:55:21 +00:00
|
|
|
test('has on singleton', () {
|
2021-10-04 05:13:56 +00:00
|
|
|
var result = container.has<Song>();
|
|
|
|
expect(result, true);
|
2018-08-26 22:55:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('has on factory', () {
|
|
|
|
expect(container.has<Artist>(), true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('false if neither', () {
|
|
|
|
expect(container.has<bool>(), false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class Artist {
|
2021-03-18 00:21:42 +00:00
|
|
|
final String? name;
|
|
|
|
final Song? song;
|
2018-08-26 22:55:21 +00:00
|
|
|
|
|
|
|
Artist({this.name, this.song});
|
|
|
|
}
|
|
|
|
|
|
|
|
class Song {
|
2021-03-18 00:21:42 +00:00
|
|
|
final String? title;
|
2018-08-26 22:55:21 +00:00
|
|
|
|
|
|
|
Song({this.title});
|
|
|
|
}
|