Added tests for JSON serialization
This commit is contained in:
parent
fc5c786b00
commit
5ade16fc3d
5 changed files with 319 additions and 1 deletions
116
pubspec.lock
116
pubspec.lock
|
@ -7,6 +7,12 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.1.3+1"
|
version: "0.1.3+1"
|
||||||
|
analyzer:
|
||||||
|
description:
|
||||||
|
name: analyzer
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.27.2"
|
||||||
args:
|
args:
|
||||||
description:
|
description:
|
||||||
name: args
|
name: args
|
||||||
|
@ -19,6 +25,18 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.11.0"
|
version: "1.11.0"
|
||||||
|
barback:
|
||||||
|
description:
|
||||||
|
name: barback
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.15.2+8"
|
||||||
|
boolean_selector:
|
||||||
|
description:
|
||||||
|
name: boolean_selector
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.2"
|
||||||
charcode:
|
charcode:
|
||||||
description:
|
description:
|
||||||
name: charcode
|
name: charcode
|
||||||
|
@ -43,6 +61,12 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.1"
|
version: "1.1.1"
|
||||||
|
csslib:
|
||||||
|
description:
|
||||||
|
name: csslib
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.13.2"
|
||||||
discoveryapis_generator:
|
discoveryapis_generator:
|
||||||
description:
|
description:
|
||||||
name: discoveryapis_generator
|
name: discoveryapis_generator
|
||||||
|
@ -55,6 +79,12 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.0+13"
|
version: "0.2.0+13"
|
||||||
|
glob:
|
||||||
|
description:
|
||||||
|
name: glob
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.3"
|
||||||
googleapis:
|
googleapis:
|
||||||
description:
|
description:
|
||||||
name: googleapis
|
name: googleapis
|
||||||
|
@ -67,12 +97,24 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.27.1"
|
version: "0.27.1"
|
||||||
|
html:
|
||||||
|
description:
|
||||||
|
name: html
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.12.2+2"
|
||||||
http:
|
http:
|
||||||
description:
|
description:
|
||||||
name: http
|
name: http
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.11.3+7"
|
version: "0.11.3+7"
|
||||||
|
http_multi_server:
|
||||||
|
description:
|
||||||
|
name: http_multi_server
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.2"
|
||||||
http_parser:
|
http_parser:
|
||||||
description:
|
description:
|
||||||
name: http_parser
|
name: http_parser
|
||||||
|
@ -97,12 +139,36 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.9.3"
|
version: "0.9.3"
|
||||||
|
package_config:
|
||||||
|
description:
|
||||||
|
name: package_config
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.1.5"
|
||||||
path:
|
path:
|
||||||
description:
|
description:
|
||||||
name: path
|
name: path
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.9"
|
version: "1.3.9"
|
||||||
|
plugin:
|
||||||
|
description:
|
||||||
|
name: plugin
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.1.0"
|
||||||
|
pool:
|
||||||
|
description:
|
||||||
|
name: pool
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.2.4"
|
||||||
|
pub_semver:
|
||||||
|
description:
|
||||||
|
name: pub_semver
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.3.0"
|
||||||
quiver:
|
quiver:
|
||||||
description:
|
description:
|
||||||
name: quiver
|
name: quiver
|
||||||
|
@ -115,6 +181,36 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.5.6+1"
|
version: "0.5.6+1"
|
||||||
|
shelf:
|
||||||
|
description:
|
||||||
|
name: shelf
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.6.5+2"
|
||||||
|
shelf_static:
|
||||||
|
description:
|
||||||
|
name: shelf_static
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.4"
|
||||||
|
shelf_web_socket:
|
||||||
|
description:
|
||||||
|
name: shelf_web_socket
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.1"
|
||||||
|
source_map_stack_trace:
|
||||||
|
description:
|
||||||
|
name: source_map_stack_trace
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.4"
|
||||||
|
source_maps:
|
||||||
|
description:
|
||||||
|
name: source_maps
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.10.1+1"
|
||||||
source_span:
|
source_span:
|
||||||
description:
|
description:
|
||||||
name: source_span
|
name: source_span
|
||||||
|
@ -139,6 +235,12 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.1.5"
|
version: "0.1.5"
|
||||||
|
test:
|
||||||
|
description:
|
||||||
|
name: test
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.12.15+1"
|
||||||
typed_data:
|
typed_data:
|
||||||
description:
|
description:
|
||||||
name: typed_data
|
name: typed_data
|
||||||
|
@ -157,10 +259,22 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.9.0+3"
|
version: "0.9.0+3"
|
||||||
|
watcher:
|
||||||
|
description:
|
||||||
|
name: watcher
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.9.7+2"
|
||||||
|
web_socket_channel:
|
||||||
|
description:
|
||||||
|
name: web_socket_channel
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.4"
|
||||||
yaml:
|
yaml:
|
||||||
description:
|
description:
|
||||||
name: yaml
|
name: yaml
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.9"
|
version: "2.1.9"
|
||||||
sdk: ">=1.16.0 <2.0.0"
|
sdk: ">=1.16.0 <1.20.0"
|
||||||
|
|
|
@ -7,3 +7,4 @@ environment:
|
||||||
dependencies:
|
dependencies:
|
||||||
rpc: "^0.5.6+1"
|
rpc: "^0.5.6+1"
|
||||||
logging: "^0.11.3"
|
logging: "^0.11.3"
|
||||||
|
test: "^0.12.15+1"
|
||||||
|
|
101
test/TitamaIo_test.dart
Normal file
101
test/TitamaIo_test.dart
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
import '../lib/common/messages.dart';
|
||||||
|
import '../lib/server/titamaio.dart';
|
||||||
|
|
||||||
|
String jsonContent = '[{"title":"UlmApi","time":"18:00","day":"Monday","kind":"Lab","place":"Weinhof9","prof":"","turnin":"","id":0},{"title":"CCC Ulm","time":"20:00","day":"Monday","kind":"Meeting","place":"Cafe Einstein","prof":"","turnin":"","id":1}]';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
group("JSON Serialization", () {
|
||||||
|
|
||||||
|
test("writeJson() writes a course list as a JSON object to a file.", () async {
|
||||||
|
|
||||||
|
List<Course> _courses = new List<Course>();
|
||||||
|
|
||||||
|
Course course = new Course();
|
||||||
|
|
||||||
|
course
|
||||||
|
..title = "UlmApi"
|
||||||
|
..time = "18:00"
|
||||||
|
..day = "Monday"
|
||||||
|
..id = 0
|
||||||
|
..kind = "Lab"
|
||||||
|
..place = "Weinhof9"
|
||||||
|
..prof = ""
|
||||||
|
..turnin = "";
|
||||||
|
|
||||||
|
_courses.add(course);
|
||||||
|
|
||||||
|
course = new Course();
|
||||||
|
|
||||||
|
course
|
||||||
|
..title = "CCC Ulm"
|
||||||
|
..time = "20:00"
|
||||||
|
..day = "Monday"
|
||||||
|
..id = 1
|
||||||
|
..kind = "Meeting"
|
||||||
|
..place = "Cafe Einstein"
|
||||||
|
..prof = ""
|
||||||
|
..turnin = "";
|
||||||
|
|
||||||
|
_courses.add(course);
|
||||||
|
|
||||||
|
TitamaIo io = new TitamaIo();
|
||||||
|
|
||||||
|
await io.writeJson(_courses);
|
||||||
|
|
||||||
|
String content = await new File('data.json').readAsString();
|
||||||
|
|
||||||
|
expect(content, equals(jsonContent));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
test("readJson() reads the JSON storage file and parses it", () async {
|
||||||
|
|
||||||
|
final filename = "data.json";
|
||||||
|
|
||||||
|
List<Course> _courses = new List<Course>();
|
||||||
|
|
||||||
|
Course course = new Course();
|
||||||
|
|
||||||
|
course
|
||||||
|
..title = "UlmApi"
|
||||||
|
..time = "18:00"
|
||||||
|
..day = "Monday"
|
||||||
|
..id = 0
|
||||||
|
..kind = "Lab"
|
||||||
|
..place = "Weinhof9"
|
||||||
|
..prof = ""
|
||||||
|
..turnin = "";
|
||||||
|
|
||||||
|
_courses.add(course);
|
||||||
|
|
||||||
|
course = new Course();
|
||||||
|
|
||||||
|
course
|
||||||
|
..title = "CCC Ulm"
|
||||||
|
..time = "20:00"
|
||||||
|
..day = "Monday"
|
||||||
|
..id = 1
|
||||||
|
..kind = "Meeting"
|
||||||
|
..place = "Cafe Einstein"
|
||||||
|
..prof = ""
|
||||||
|
..turnin = "";
|
||||||
|
|
||||||
|
_courses.add(course);
|
||||||
|
|
||||||
|
await new File(filename).writeAsString(jsonContent);
|
||||||
|
|
||||||
|
TitamaIo io = new TitamaIo();
|
||||||
|
|
||||||
|
List<Course> courses = await io.readJson();
|
||||||
|
|
||||||
|
expect(courses, equals(_courses));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
101
test/TitamaIo_test.dart~
Normal file
101
test/TitamaIo_test.dart~
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
import '../lib/common/messages.dart';
|
||||||
|
import '../lib/server/titamaio.dart';
|
||||||
|
|
||||||
|
String jsonContent = '[{"title":"UlmApi","time":"18:00","day":"Monday","kind":"Lab","place":"Weinhof9","prof":"","turnin":"","id":0},{"title":"CCC Ulm","time":"20:00","day":"Monday","kind":"Meeting","place":"Cafe Einstein","prof":"","turnin":"","id":1}]';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
group("JSON Serialization", () {
|
||||||
|
|
||||||
|
test("writeJson() writes a course list as a JSON object to a file.", () async {
|
||||||
|
|
||||||
|
List<Course> _courses = new List<Course>();
|
||||||
|
|
||||||
|
Course course = new Course();
|
||||||
|
|
||||||
|
course
|
||||||
|
..title = "UlmApi"
|
||||||
|
..time = "18:00"
|
||||||
|
..day = "Monday"
|
||||||
|
..id = 0
|
||||||
|
..kind = "Lab"
|
||||||
|
..place = "Weinhof9"
|
||||||
|
..prof = ""
|
||||||
|
..turnin = "";
|
||||||
|
|
||||||
|
_courses.add(course);
|
||||||
|
|
||||||
|
course = new Course();
|
||||||
|
|
||||||
|
course
|
||||||
|
..title = "CCC Ulm"
|
||||||
|
..time = "20:00"
|
||||||
|
..day = "Monday"
|
||||||
|
..id = 1
|
||||||
|
..kind = "Meeting"
|
||||||
|
..place = "Cafe Einstein"
|
||||||
|
..prof = ""
|
||||||
|
..turnin = "";
|
||||||
|
|
||||||
|
_courses.add(course);
|
||||||
|
|
||||||
|
TitamaIo io = new TitamaIo();
|
||||||
|
|
||||||
|
await io.writeJson(_courses);
|
||||||
|
|
||||||
|
String content = await new File('data.json').readAsString();
|
||||||
|
|
||||||
|
expect(content, equals(jsonContent));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
test("readJson() reads the JSON storage file and parses it", () async {
|
||||||
|
|
||||||
|
final filename = "data.json";
|
||||||
|
|
||||||
|
List<Course> _courses = new List<Course>();
|
||||||
|
|
||||||
|
Course course = new Course();
|
||||||
|
|
||||||
|
course
|
||||||
|
..title = "UlmApi"
|
||||||
|
..time = "18:00"
|
||||||
|
..day = "Monday"
|
||||||
|
..id = 0
|
||||||
|
..kind = "Lab"
|
||||||
|
..place = "Weinhof9"
|
||||||
|
..prof = ""
|
||||||
|
..turnin = "";
|
||||||
|
|
||||||
|
_courses.add(course);
|
||||||
|
|
||||||
|
course = new Course();
|
||||||
|
|
||||||
|
course
|
||||||
|
..title = "CCC Ulm"
|
||||||
|
..time = "20:00"
|
||||||
|
..day = "Monday"
|
||||||
|
..id = 1
|
||||||
|
..kind = "Meeting"
|
||||||
|
..place = "Cafe Einstein"
|
||||||
|
..prof = ""
|
||||||
|
..turnin = "";
|
||||||
|
|
||||||
|
_courses.add(course);
|
||||||
|
|
||||||
|
await new File(filename).writeAsString(jsonContent);
|
||||||
|
|
||||||
|
TitamaIo io = new TitamaIo();
|
||||||
|
|
||||||
|
List<Course> courses = await io.readJson();
|
||||||
|
|
||||||
|
expect(courses, equals(_courses));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
1
test/packages
Symbolic link
1
test/packages
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../packages
|
Reference in a new issue