import 'dart:async'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_container/mirrors.dart'; import 'package:angel_seeder/angel_seeder.dart'; import 'package:test/test.dart'; void main() { test('create one', () async { var app = Angel(reflector: MirrorsReflector()) ..use('/todos', TodoService()); await app.configure(seed( 'todos', SeederConfiguration(delete: false, count: 10, template: { 'text': (Faker faker) => 'Clean your room, ${faker.person.name()}!', 'completed': false }))); var todos = await app.findService('todos')!.index(); print('Todos: \n${todos.map((todo) => " - $todo").join("\n")}'); expect(todos, isList); expect(todos, hasLength(10)); }); } class TodoService extends Service { final List todos = []; @override Future> index([params]) => myData(); Future> myData() { var completer = Completer>(); completer.complete(todos); return completer.future; } @override Future create(data, [params]) async { if (data is Todo) { todos.add(data..id = todos.length.toString()); return data; } else if (data is Map) { todos.add(Todo.fromJson(data)..id = todos.length.toString()); return data; } else { throw AngelHttpException.badRequest(); } } } class Todo extends Model { final String? text; final bool? completed; Todo({String? id, this.text, this.completed = false}) { this.id = id; } factory Todo.fromJson(Map data) => Todo( id: data['id'] as String?, text: data['text'] as String?, completed: data['completed'] as bool?); @override String toString() => '${completed! ? "Complete" : "Incomplete"}: $text'; }