platform/angel_container_generator/test/reflector_test.dart

53 lines
1.1 KiB
Dart
Raw Normal View History

2018-11-30 06:09:18 +00:00
import 'package:angel_container/angel_container.dart';
2018-11-30 05:32:49 +00:00
import 'package:angel_container_generator/angel_container_generator.dart';
import 'package:test/test.dart';
import 'reflector_test.reflectable.dart';
void main() {
initializeReflectable();
2018-11-30 06:09:18 +00:00
var artist = new Artist();
var reflector = const GeneratedReflector();
Container container;
setUp(() {
container = new Container(reflector);
container.registerSingleton(artist);
//container.registerSingleton(new Artist(name: 'Tobe Osakwe'));
});
2018-11-30 05:32:49 +00:00
group('reflectClass', () {
var mirror = reflector.reflectClass(Artist);
test('name', () {
expect(mirror.name, 'Artist');
});
});
2018-11-30 06:09:18 +00:00
test('inject constructor parameters', () {
var album = container.make<Album>();
print(album.title);
expect(album.title, 'flowers by ${artist.lowerName}');
});
2018-11-30 05:32:49 +00:00
}
@contained
class Artist {
2018-11-30 06:09:18 +00:00
//final String name;
//Artist({this.name});
String get lowerName {
//return name.toLowerCase();
return hashCode.toString().toLowerCase();
}
}
@contained
class Album {
final Artist artist;
Album(this.artist);
String get title => 'flowers by ${artist.lowerName}';
2018-11-30 05:32:49 +00:00
}