1 /**
2  * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved.
3  * Authors: Jacob Carlborg
4  * Version: Initial created: Aug 6, 2011
5  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6  */
7 module spec.serialization.Event;
8 
9 import dspec.Dsl;
10 
11 import mambo.core..string;
12 import mambo.serialization.Serializer;
13 import mambo.serialization.Events;
14 import mambo.serialization.archives.XmlArchive;
15 import spec.serialization.Util;
16 
17 Serializer serializer;
18 XmlArchive!(char) archive;
19 
20 int[] arr;
21 
22 class Foo
23 {
24 
25 	void serializing ()
26 	{
27 		arr ~= 1;
28 	}
29 
30 	void serialized ()
31 	{
32 		arr ~= 2;
33 	}
34 	
35 	void deserializing ()
36 	{
37 		arr ~= 3;
38 	}
39 	
40 	void deserialized ()
41 	{
42 		arr ~= 4;
43 	}
44 	
45 	mixin OnSerializing!(serializing);
46 	mixin OnSerialized!(serialized);
47 	mixin OnDeserializing!(deserializing);
48 	mixin OnDeserialized!(deserialized);
49 }
50 
51 unittest
52 {
53 	archive = new XmlArchive!(char);
54 	serializer = new Serializer(archive);
55 
56 	describe! "serialization events" in {
57 		it! "all four events should be triggered when serializing and deserializing" in {
58 			serializer.serialize(new Foo);
59 			serializer.deserialize!(Foo)(archive.untypedData);
60 
61 			assert(arr == [1, 2, 3, 4]);
62 		};
63 	};
64 }