forked from dartist/redis_client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_serializer_tests.dart
76 lines (58 loc) · 2.19 KB
/
redis_serializer_tests.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
library redis_serializer_tests;
import 'dart:convert';
import 'package:unittest/unittest.dart';
import 'package:redis_client/redis_client.dart';
class A {
String value;
A(this.value);
toJson() {
var data = {
'value' : value
};
return JSON.encode(data);
}
A.fromJson(json) {
var data = JSON.decode(json);
value = data['value'];
}
}
main() {
group('JSONRedisSerializer tests', () {
RedisSerializer serializer = new JsonRedisSerializer();
group('can encode-decode:', () {
test('nulls', () {
var serializedNull = serializer.serialize(null);
var deserializedNull = serializer.deserialize(serializedNull);
expect(serializedNull, equals(deserializedNull));
});
test('strings', () {
var serializedString = serializer.serialize('some-string');
var deserializedString = serializer.deserialize(serializedString);
expect(deserializedString, equals('some-string'));
});
test('lists', () {
var serializedList = serializer.serialize(['some-string', 4]);
var deserializedList = serializer.deserialize(serializedList);
expect(deserializedList, equals(['some-string', 4]));
});
test('sets', () {
var serializedSet = serializer.serialize(new Set.from(['some-string', 4]));
var deserializedSet = serializer.deserialize(serializedSet);
expect(deserializedSet, equals(new Set.from(['some-string', 4])));
});
test('dates', () {
DateTime now = new DateTime.now().toUtc();
var serializedDate = serializer.serialize(now);
DateTime justNow = serializer.deserialize(serializedDate);
expect(now, equals(justNow));
});
//TODO: need some work to support instantiation from deserializer
test('custom classes', () {
A a = new A('some-value');
var serializedA = serializer.serialize(a);
A deserializedA = new A.fromJson(serializer.deserialize(serializedA));
expect(deserializedA.value, equals(a.value));
});
});
});
}