This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test("POST /books creates a new book", () async { | |
var request = app.client.request("/books") | |
..json = { | |
"title": "Dart: Scalable Application Development", | |
"author": "Davy Mitchell, Sergey Akopkokhyants, Ivo Balbaert", | |
"year": 2007 | |
}; | |
expectResponse(await request.post(), 200, | |
body: partial({ | |
"id": 4, // updated primary key from db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'harness/app.dart'; | |
import 'package:fave_reads/model/book.dart'; | |
Future main() async { | |
TestApplication app = new TestApplication(); | |
setUpAll(() async { | |
await app.start(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'dart:async'; | |
import 'dart:convert'; | |
main() async { | |
Uri apiUrl = Uri.parse("https://swapi.co/api/people/1"); // Star Wars API | |
HttpClientRequest request = await new HttpClient().getUrl(apiUrl); | |
HttpClientResponse response = await request.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
print("This is my first Dart program."); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "dart:io"; | |
void main() { | |
HttpServer.bind("localhost", 8080).then((HttpServer server) { | |
server.listen((HttpRequest request) { | |
request.response.write("Hello world"); | |
request.response.close(); | |
}); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ‘../fave_reads.dart’; | |
import ‘./author.dart’; | |
class Book extends ManagedObject<_Book> implements _Book {} | |
class _Book { | |
@managedPrimaryKey | |
int id; | |
String title; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Populate DB | |
var books = [ | |
new Book() | |
..title = "Head First Design Patterns" | |
..authors = (new ManagedSet() | |
..add(new Author()..name = "Bert Bates") | |
..add(new Author()..name = "Kathy Sierra") | |
..add(new Author()..name = "Eric Freeman")) | |
..year = 2004, | |
new Book() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Query for books | |
await Future.forEach(books, (Book b) async { | |
var query = new Query<Book>()..values = b; | |
var insertedBook = await query.insert(); | |
// Query for authors | |
await Future.forEach(b.authors, (Author a) async { | |
var query = new Query<Author>() | |
..values = a | |
..values.book = insertedBook; // Reference to its associated book, which becomes a foreign key column `book_id` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
// ... | |
test("GET /books returns list of books", () async { | |
// .. | |
// .. | |
expectResponse(response, 200, body: allOf([ | |
hasLength(greaterThan(0)), | |
everyElement(partial( | |
{ | |
"title": isString, |