Enable cached engine returns for EngineService

This commit is contained in:
Marty Oehme 2018-08-25 14:51:28 +02:00
parent 66bf87d9d8
commit cc33628e5f
2 changed files with 23 additions and 2 deletions

View file

@ -5,13 +5,15 @@ import 'package:rules_of_living/src/Engine.dart';
class EngineService {
Engine _engine;
Engine get engine => _engine ?? create(null);
Engine get engine => _engine ?? createEngine(null);
Engine create(html.CanvasElement canvas) {
Engine createEngine(html.CanvasElement canvas) {
_engine = Engine(canvas);
return _engine;
}
void setCanvas(html.CanvasElement canvas) => engine.canvas = canvas;
void run() {
engine.running = true;
}

View file

@ -0,0 +1,19 @@
@TestOn('browser')
import 'package:test/test.dart';
import 'package:rules_of_living/service/engine_service.dart';
void main() {
EngineService sut;
setUp(() {
sut = EngineService();
});
test("EngineService creates an engine on demand", () {
expect(sut.engine, isNotNull);
});
test("EngineService returns the cached engine on subsequent requests", () {
expect(sut.engine, allOf(isNotNull, equals(sut.engine)));
});
}