Skip to content

Instantly share code, notes, and snippets.

@MikeMitterer
Created August 12, 2014 15:39
Show Gist options
  • Save MikeMitterer/87d9d68d07caeac14781 to your computer and use it in GitHub Desktop.
Save MikeMitterer/87d9d68d07caeac14781 to your computer and use it in GitHub Desktop.
Test instance creation with Dart, Angular + DI
part of integration.test;
@angular.Injectable()
class Proxy {
final Logger _logger = new Logger("integration.test.Angular.Proxy");
final Completer<bool> _completer = new Completer<bool>();
static int _pcounter = 0;
Proxy({ final String name: "not set" }) {
_logger.info("Proxy #$_pcounter, Name: $name");
_pcounter++;
}
int get pcounter => _pcounter;
Future<bool> load() {
//_completer.completeError("Error");
new Timer(new Duration(seconds: 1),() {
_completer.completeError("Error");
});
return _completer.future;
}
}
class SuperProxy extends Proxy {
SuperProxy() : super(name: "super proxy");
}
class ProxyTestInstance1 {
final Proxy proxy;
ProxyTestInstance1(this.proxy);
}
class ProxyTestInstance2 {
final Proxy proxy;
ProxyTestInstance2(this.proxy);
}
class SampleModule2 extends angular.Module {
SampleModule2() {
bind(Proxy,toFactory: () => new Proxy(name: "module2"));
//bind(Proxy,toValue: new Proxy(name: "module2"));
//bind(Proxy);
//bind(Proxy, toImplementation: SuperProxy);
}
}
class SampleModule extends angular.Module {
SampleModule() {
install(new SampleModule2());
bind(Controller);
//bind(Proxy,toValue: new Proxy(name: "module1"));
bind(Proxy, toImplementation: SuperProxy);
bind(ProxyTestInstance1);
bind(ProxyTestInstance2);
}
}
testAngular() {
final Logger _logger = new Logger("integration.test.Angular");
group('Angular', () {
setUp(() {
amock.setUpInjector();
amock.module(new SampleModule());
});
test('> Instance', () {
amock.inject((final Proxy proxy1,final Proxy proxy2,final ProxyTestInstance2 pi1,final ProxyTestInstance2 pi2) {
expect(proxy1.pcounter,1);
expect(proxy2.pcounter,1);
expect(pi1.proxy.pcounter,1);
expect(pi2.proxy.pcounter,1);
proxy1.load().then(expectAsync((_) {
},count: 0))
.catchError(expectAsync((final String error) {
_logger.severe("Error: $error");
}));
});
}); // end of 'Instance' test
});
// end 'Angular' group
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment