<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Elegant Code &#187; Event Sourcing</title>
	<atom:link href="http://elegantcode.com/category/event-sourcing/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Sun, 12 Feb 2012 04:40:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>CQRS &#8211; Event Versioning</title>
		<link>http://elegantcode.com/2010/02/09/cqrs-event-versioning/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cqrs-event-versioning</link>
		<comments>http://elegantcode.com/2010/02/09/cqrs-event-versioning/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 23:37:28 +0000</pubDate>
		<dc:creator>Mark Nijhof</dc:creator>
				<category><![CDATA[CQRS]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Event Sourcing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/02/09/cqrs-event-versioning/</guid>
		<description><![CDATA[When using Event Sourcing you store your events in an Event Store. This Event Store can only insert new events and read historical events, nothing more nothing less. So when you change your domain logic and also the events belonging to this behavior, then you cannot go back into the Event Store and do a [...]]]></description>
			<content:encoded><![CDATA[<p>When using Event Sourcing you store your events in an Event Store. This Event Store can only insert new events and read historical events, nothing more nothing less. So when you change your domain logic and also the events belonging to this behavior, then you cannot go back into the Event Store and do a one time convert of all the historical events belonging to the same behavior. The Event Store needs to stay intact, that is one of its powers.</p>
<p>So you make a new version of the original event, this new version carries more or less information then the original one. Lets take a look at a very simple example:</p>
<div style="padding-bottom: 10px; margin: 0px; font-family: monaco,verdana; background: rgb(22,36,51); color: white; font-size: 10pt; overflow: scroll; padding-top: 10px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 1</span>&#160;<span style="color: #0080c0">namespace</span> Fohjin<span style="color: aqua">.</span>DDD<span style="color: aqua">.</span>Events<span style="color: aqua">.</span>Account</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 2</span> {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 3</span>&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Serializable</span>]</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 4</span>&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">class</span> <span style="color: #2b91af">CashWithdrawnEvent</span> : <span style="color: #2b91af">DomainEvent</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 5</span>&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 6</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">decimal</span> Balance { <span style="color: #0080c0">get</span>; <span style="color: #0080c0">private</span> <span style="color: #0080c0">set</span>; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 7</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">decimal</span> Amount { <span style="color: #0080c0">get</span>; <span style="color: #0080c0">private</span> <span style="color: #0080c0">set</span>; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 8</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 9</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> CashWithdrawnEvent(<span style="color: #0080c0">decimal</span> balance, <span style="color: #0080c0">decimal</span> amount)</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 10</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 11</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Balance <span style="color: aqua">=</span> balance;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 12</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Amount <span style="color: aqua">=</span> amount;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 13</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 14</span>&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 15</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 16</span>&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Serializable</span>]</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 17</span>&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">class</span> <span style="color: #2b91af">CashWithdrawnEvent_v2</span> : <span style="color: #2b91af">DomainEvent</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 18</span>&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 19</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">decimal</span> Balance { <span style="color: #0080c0">get</span>; <span style="color: #0080c0">private</span> <span style="color: #0080c0">set</span>; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 20</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">decimal</span> Amount { <span style="color: #0080c0">get</span>; <span style="color: #0080c0">private</span> <span style="color: #0080c0">set</span>; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 21</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">Guid</span> AtmId { <span style="color: #0080c0">get</span>; <span style="color: #0080c0">private</span> <span style="color: #0080c0">set</span>; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 22</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 23</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> CashWithdrawnEvent_v2(<span style="color: #0080c0">decimal</span> balance, <span style="color: #0080c0">decimal</span> amount, <span style="color: #0080c0">Guid</span> atmId)</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 24</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 25</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Balance <span style="color: aqua">=</span> balance;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 26</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Amount <span style="color: aqua">=</span> amount;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 27</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AtmId <span style="color: aqua">=</span> atmId;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 28</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 29</span>&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 30</span> }</pre>
</div>
<p>This to me looks like a natural evolution for this type of event, so how do you deal with this. Because after having used the system, before adding this extension there have been many cash withdrawals. So all these events are in the Event Store, they cannot be altered, and when you retrieve an Aggregate Root from the Event Store all these historical events need to be processed in order to restore the internal state.</p>
<p>Now what you don’t want is to maintain code in the Aggregate Root that knows how to handle these old event versions, sure one version is ok, but what about one hundred different versions? Also we are not just talking about just in the Aggregate Root, also the different event handlers need to be kept and maintained.</p>
<p>The better approach is to have a mechanism that you can hook-up with different event convertors. Then when an event is retrieved from the Event Store it first goes through this pipeline of convertors to be converted to the latest event version.</p>
<p>Now I wanted to do this properly and write some actual code for this, and then blog about it, but someone kept nagging me about it, so here is a very rough spike instead, first some tests:</p>
<div style="padding-bottom: 10px; margin: 0px; font-family: monaco,verdana; background: rgb(22,36,51); color: white; font-size: 10pt; overflow: scroll; padding-top: 10px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 1</span>&#160;<span style="color: #0080c0">namespace</span> Test<span style="color: aqua">.</span>Fohjin<span style="color: aqua">.</span>DDD<span style="color: aqua">.</span>Spike</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 2</span> {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 3</span>&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">class</span> <span style="color: #2b91af">Spike_test_1</span> : <span style="color: #2b91af">BaseTestFixture</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 4</span>&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 5</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">private</span> <span style="color: #0080c0">object</span> ConvertedEvent;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 6</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 7</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">protected</span> <span style="color: #0080c0">override</span> <span style="color: #0080c0">void</span> When()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 8</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 9</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent <span style="color: aqua">=</span> <span style="color: #0080c0">new</span> EventConvertor()<span style="color: aqua">.</span>Convert(<span style="color: #0080c0">new</span> <span style="color: #2b91af">CashWithdrawnEvent</span>(<span style="color: yellow">10.0M</span>, <span style="color: yellow">20.0M</span>));</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 10</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 11</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 12</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Then</span>]</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 13</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">void</span> The_converted_event_is_the_latest_version()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 14</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 15</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>WillBeOfType<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>();</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 16</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 17</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 18</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Then</span>]</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 19</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">void</span> The_converted_event_wil_contain_the_correct_data()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 20</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 21</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>As<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>()<span style="color: aqua">.</span>Balance<span style="color: aqua">.</span>WillBe(<span style="color: yellow">10.0M</span>);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 22</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>As<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>()<span style="color: aqua">.</span>Amount<span style="color: aqua">.</span>WillBe(<span style="color: yellow">20.0M</span>);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 23</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>As<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>()<span style="color: aqua">.</span>AtmId<span style="color: aqua">.</span>WillBe(<span style="color: #0080c0">string</span><span style="color: aqua">.</span>Empty);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 24</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 25</span>&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 26</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 27</span>&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">class</span> <span style="color: #2b91af">Spike_test_2</span> : <span style="color: #2b91af">BaseTestFixture</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 28</span>&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 29</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">private</span> <span style="color: #0080c0">object</span> ConvertedEvent;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 30</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 31</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">protected</span> <span style="color: #0080c0">override</span> <span style="color: #0080c0">void</span> When()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 32</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 33</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent <span style="color: aqua">=</span> <span style="color: #0080c0">new</span> EventConvertor()<span style="color: aqua">.</span>Convert(<span style="color: #0080c0">new</span> <span style="color: #2b91af">CashWithdrawnEvent_v2</span>(<span style="color: yellow">10.0M</span>, <span style="color: yellow">20.0M</span>, <span style="color: #a31515">&quot;12345&quot;</span>));</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 34</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 35</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 36</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Then</span>]</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 37</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">void</span> The_converted_event_is_the_latest_version()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 38</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 39</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>WillBeOfType<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>();</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 40</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 41</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 42</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Then</span>]</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 43</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">void</span> The_converted_event_wil_contain_the_correct_data()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 44</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 45</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>As<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>()<span style="color: aqua">.</span>Balance<span style="color: aqua">.</span>WillBe(<span style="color: yellow">10.0M</span>);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 46</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>As<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>()<span style="color: aqua">.</span>Amount<span style="color: aqua">.</span>WillBe(<span style="color: yellow">20.0M</span>);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 47</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>As<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>()<span style="color: aqua">.</span>AtmId<span style="color: aqua">.</span>WillBe(<span style="color: #a31515">&quot;12345&quot;</span>);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 48</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 49</span>&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 50</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 51</span>&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">class</span> <span style="color: #2b91af">Spike_test_3</span> : <span style="color: #2b91af">BaseTestFixture</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 52</span>&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 53</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">private</span> <span style="color: #0080c0">object</span> ConvertedEvent;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 54</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 55</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">protected</span> <span style="color: #0080c0">override</span> <span style="color: #0080c0">void</span> When()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 56</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 57</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent <span style="color: aqua">=</span> <span style="color: #0080c0">new</span> EventConvertor()<span style="color: aqua">.</span>Convert(<span style="color: #0080c0">new</span> <span style="color: #2b91af">CashWithdrawnEvent_v3</span>(<span style="color: yellow">10.0M</span>, <span style="color: yellow">20.0M</span>, <span style="color: #a31515">&quot;12345&quot;</span>));</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 58</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 59</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 60</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [Then]</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 61</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">void</span> The_converted_event_is_the_latest_version()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 62</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 63</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>WillBeOfType<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>();</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 64</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 65</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 66</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [Then]</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 67</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">void</span> The_converted_event_wil_contain_the_correct_data()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 68</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 69</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>As<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>()<span style="color: aqua">.</span>Balance<span style="color: aqua">.</span>WillBe(<span style="color: yellow">10.0M</span>);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 70</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>As<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>()<span style="color: aqua">.</span>Amount<span style="color: aqua">.</span>WillBe(<span style="color: yellow">20.0M</span>);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 71</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>As<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>()<span style="color: aqua">.</span>AtmId<span style="color: aqua">.</span>WillBe(<span style="color: #a31515">&quot;12345&quot;</span>);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 72</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 73</span>&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 74</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 75</span>&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">class</span> <span style="color: #2b91af">Spike_test_4</span> : <span style="color: #2b91af">BaseTestFixture</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 76</span>&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 77</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">private</span> <span style="color: #0080c0">object</span> ConvertedEvent;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 78</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 79</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">protected</span> <span style="color: #0080c0">override</span> <span style="color: #0080c0">void</span> When()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 80</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 81</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent <span style="color: aqua">=</span> <span style="color: #0080c0">new</span> EventConvertor()<span style="color: aqua">.</span>Convert(<span style="color: #0080c0">new</span> <span style="color: #2b91af">CashWithdrawnEvent_v4</span>(<span style="color: yellow">10.0M</span>, <span style="color: yellow">20.0M</span>, <span style="color: #a31515">&quot;12345&quot;</span>));</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 82</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 83</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 84</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [Then]</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 85</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">void</span> The_converted_event_is_the_latest_version()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 86</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 87</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>WillBeOfType<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>();</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 88</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 89</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 90</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Then</span>]</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 91</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">void</span> The_converted_event_wil_contain_the_correct_data()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 92</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 93</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>As<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>()<span style="color: aqua">.</span>Balance<span style="color: aqua">.</span>WillBe(<span style="color: yellow">10.0M</span>);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 94</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>As<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>()<span style="color: aqua">.</span>Amount<span style="color: aqua">.</span>WillBe(<span style="color: yellow">20.0M</span>);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 95</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConvertedEvent<span style="color: aqua">.</span>As<span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span>()<span style="color: aqua">.</span>AtmId<span style="color: aqua">.</span>WillBe(<span style="color: #a31515">&quot;12345&quot;</span>);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 96</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 97</span>&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 98</span> }</pre>
</div>
<p>So basically some tests to confirm the correct conversion from one event to another event, now below here is the full implementation:</p>
<div style="padding-bottom: 10px; margin: 0px; font-family: monaco,verdana; background: rgb(22,36,51); color: white; font-size: 10pt; overflow: scroll; padding-top: 10px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 1</span>&#160;<span style="color: #0080c0">namespace</span> Test<span style="color: aqua">.</span>Fohjin<span style="color: aqua">.</span>DDD<span style="color: aqua">.</span>Spike</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 2</span> {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 3</span>&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">class</span> <span style="color: #2b91af">EventConvertor</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 4</span>&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 5</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">private</span> <span style="color: #0080c0">readonly</span> <span style="color: #2b91af">Dictionary</span><span style="color: aqua">&lt;</span><span style="color: #2b91af">Type</span>, <span style="color: #2b91af">Func</span><span style="color: aqua">&lt;</span><span style="color: #0080c0">object</span>, <span style="color: #0080c0">object</span><span style="color: aqua">&gt;&gt;</span> _convertors;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 6</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 7</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> EventConvertor()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 8</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160;&#160; 9</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _convertors <span style="color: aqua">=</span> <span style="color: #0080c0">new</span> <span style="color: #2b91af">Dictionary</span><span style="color: aqua">&lt;</span><span style="color: #2b91af">Type</span>, <span style="color: #2b91af">Func</span><span style="color: aqua">&lt;</span><span style="color: #0080c0">object</span>, <span style="color: #0080c0">object</span><span style="color: aqua">&gt;&gt;</span>();</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 10</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; RegisterEventConvertors();</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 11</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 12</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 13</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">private</span> <span style="color: #0080c0">void</span> RegisterEventConvertors()</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 14</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 15</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _convertors<span style="color: aqua">.</span>Add(<span style="color: #0080c0">typeof</span>(<span style="color: #2b91af">CashWithdrawnEvent</span>), x <span style="color: aqua">=&gt;</span> <span style="color: #0080c0">new</span> <span style="color: #2b91af">CashWithdrawnEventConvertor</span>()<span style="color: aqua">.</span>Convert((<span style="color: #2b91af">CashWithdrawnEvent</span>)x));</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 16</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _convertors<span style="color: aqua">.</span>Add(<span style="color: #0080c0">typeof</span>(<span style="color: #2b91af">CashWithdrawnEvent_v2</span>), x <span style="color: aqua">=&gt;</span> <span style="color: #0080c0">new</span> <span style="color: #2b91af">CashWithdrawnEvent_v2Convertor</span>()<span style="color: aqua">.</span>Convert((<span style="color: #2b91af">CashWithdrawnEvent_v2</span>)x));</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 17</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _convertors<span style="color: aqua">.</span>Add(<span style="color: #0080c0">typeof</span>(<span style="color: #2b91af">CashWithdrawnEvent_v3</span>), x <span style="color: aqua">=&gt;</span> <span style="color: #0080c0">new</span> <span style="color: #2b91af">CashWithdrawnEvent_v3Convertor</span>()<span style="color: aqua">.</span>Convert((<span style="color: #2b91af">CashWithdrawnEvent_v3</span>)x));</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 18</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 19</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 20</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">object</span> Convert(<span style="color: #0080c0">object</span> soureEvent)</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 21</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 22</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Func</span><span style="color: aqua">&lt;</span><span style="color: #0080c0">object</span>, <span style="color: #0080c0">object</span><span style="color: aqua">&gt;</span> convertor;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 23</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">return</span> _convertors<span style="color: aqua">.</span>TryGetValue(soureEvent<span style="color: aqua">.</span>GetType(), <span style="color: #0080c0">out</span> convertor) </pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 24</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: aqua">?</span> Convert(convertor(soureEvent)) </pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 25</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; : soureEvent;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 26</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 27</span>&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 28</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 29</span>&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">interface</span> <span style="color: #2b91af">IEventConvertor</span><span style="color: aqua">&lt;</span>TSourceEvent, TTargetEvent<span style="color: aqua">&gt;</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 30</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">where</span> TSourceEvent : <span style="color: #2b91af">IDomainEvent</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 31</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">where</span> TTargetEvent : <span style="color: #2b91af">IDomainEvent</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 32</span>&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 33</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TTargetEvent Convert(TSourceEvent sourceEvent);</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 34</span>&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 35</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 36</span>&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">class</span> <span style="color: #2b91af">CashWithdrawnEventConvertor</span> : <span style="color: #2b91af">IEventConvertor</span><span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent</span>, <span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 37</span>&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 38</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #2b91af">CashWithdrawnEvent_v4</span> Convert(<span style="color: #2b91af">CashWithdrawnEvent</span> sourceEvent)</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 39</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 40</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">var</span> theEvent <span style="color: aqua">=</span> <span style="color: #0080c0">new</span> <span style="color: #2b91af">CashWithdrawnEvent_v4</span>(sourceEvent<span style="color: aqua">.</span>Balance, sourceEvent<span style="color: aqua">.</span>Amount, <span style="color: #0080c0">string</span><span style="color: aqua">.</span>Empty)</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 41</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 42</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AggregateId <span style="color: aqua">=</span> sourceEvent<span style="color: aqua">.</span>AggregateId</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 43</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; };</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 44</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (theEvent <span style="color: #0080c0">as</span> <span style="color: #2b91af">IDomainEvent</span>)<span style="color: aqua">.</span>Version <span style="color: aqua">=</span> (sourceEvent <span style="color: #0080c0">as</span> <span style="color: #2b91af">IDomainEvent</span>)<span style="color: aqua">.</span>Version;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 45</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">return</span> theEvent;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 46</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 47</span>&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 48</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 49</span>&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">class</span> <span style="color: #2b91af">CashWithdrawnEvent_v2Convertor</span> : <span style="color: #2b91af">IEventConvertor</span><span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v2</span>, <span style="color: #2b91af">CashWithdrawnEvent_v3</span><span style="color: aqua">&gt;</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 50</span>&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 51</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #2b91af">CashWithdrawnEvent_v3</span> Convert(<span style="color: #2b91af">CashWithdrawnEvent_v2</span> sourceEvent)</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 52</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 53</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">var</span> theEvent <span style="color: aqua">=</span> <span style="color: #0080c0">new</span> <span style="color: #2b91af">CashWithdrawnEvent_v3</span>(sourceEvent<span style="color: aqua">.</span>Balance, sourceEvent<span style="color: aqua">.</span>Amount, sourceEvent<span style="color: aqua">.</span>AtmId)</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 54</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 55</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AggregateId <span style="color: aqua">=</span> sourceEvent<span style="color: aqua">.</span>AggregateId</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 56</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; };</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 57</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (theEvent <span style="color: #0080c0">as</span> <span style="color: #2b91af">IDomainEvent</span>)<span style="color: aqua">.</span>Version <span style="color: aqua">=</span> (sourceEvent <span style="color: #0080c0">as</span> <span style="color: #2b91af">IDomainEvent</span>)<span style="color: aqua">.</span>Version;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 58</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">return</span> theEvent;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 59</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 60</span>&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 61</span>&#160;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 62</span>&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #0080c0">class</span> <span style="color: #2b91af">CashWithdrawnEvent_v3Convertor</span> : <span style="color: #2b91af">IEventConvertor</span><span style="color: aqua">&lt;</span><span style="color: #2b91af">CashWithdrawnEvent_v3</span>, <span style="color: #2b91af">CashWithdrawnEvent_v4</span><span style="color: aqua">&gt;</span></pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 63</span>&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 64</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">public</span> <span style="color: #2b91af">CashWithdrawnEvent_v4</span> Convert(<span style="color: #2b91af">CashWithdrawnEvent_v3</span> sourceEvent)</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 65</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 66</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">var</span> theEvent <span style="color: aqua">=</span> <span style="color: #0080c0">new</span> <span style="color: #2b91af">CashWithdrawnEvent_v4</span>(sourceEvent<span style="color: aqua">.</span>Balance, sourceEvent<span style="color: aqua">.</span>Amount, sourceEvent<span style="color: aqua">.</span>AtmId)</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 67</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 68</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AggregateId <span style="color: aqua">=</span> sourceEvent<span style="color: aqua">.</span>AggregateId</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 69</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; };</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 70</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (theEvent <span style="color: #0080c0">as</span> <span style="color: #2b91af">IDomainEvent</span>)<span style="color: aqua">.</span>Version <span style="color: aqua">=</span> (sourceEvent <span style="color: #0080c0">as</span> <span style="color: #2b91af">IDomainEvent</span>)<span style="color: aqua">.</span>Version;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 71</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0080c0">return</span> theEvent;</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 72</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 73</span>&#160;&#160;&#160;&#160; }</pre>
<pre style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; background: rgb(22,36,51); padding-top: 0px"><span style="background: #121e31">&#160;&#160; 74</span> }</pre>
</div>
<p>This implementation is definitely not very elegant (so it doesn’t really belong on this blog) but hey it does show you how a possible solution would work. When building this yourself you might want to use conventions to auto register the convertors and chain them together during configuration so there is no need for the recursive functionality.</p>
<p>Also look at the jump from version 1 to version 4, this is an optimization to speed up the conversion. You would do this after a few versions, not for each version.</p>
<p>I’ll be adding a proper solution to the example in the near future, something that you would just plug the convertors in and the system would figure out how to handle them itself.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/02/09/cqrs-event-versioning/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>CQRS &#8211; Event Sourcing</title>
		<link>http://elegantcode.com/2010/02/05/cqrs-event-sourcing/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cqrs-event-sourcing</link>
		<comments>http://elegantcode.com/2010/02/05/cqrs-event-sourcing/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 17:02:48 +0000</pubDate>
		<dc:creator>Mark Nijhof</dc:creator>
				<category><![CDATA[CQRS]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Event Sourcing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/02/05/cqrs-event-sourcing/</guid>
		<description><![CDATA[My new blog is at at http://cre8ivethought.com/blog/index come and follow me there. -Mark Nijhof So after reading this blog post by Rob Conery about Reporting In NoSQL where he explains very well what the problem is when using a RDBMS for persisting the state of your domain, or really anything that is written with Object [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><em>My new blog is at at <a href="http://cre8ivethought.com/blog/index">http://cre8ivethought.com/blog/index</a> come and follow me there.</p>
<p>-Mark Nijhof</em></p>
</blockquote>
<p>So after reading this blog post by Rob Conery about <a href="http://blog.wekeroad.com/2010/02/05/reporting-in-nosql" target="_blank">Reporting In NoSQL</a> where he explains very well what the problem is when using a RDBMS for persisting the state of your domain, or really anything that is written with Object Orientation in mind.</p>
<p>His solution to the problem is to use a object database or a document database for persisting the state of your object structure. And I do agree that this is a valuable approach to solve the problem.</p>
<p>But I would like to talk about a different approach, which is called <a href="http://martinfowler.com/eaaDev/EventSourcing.html" target="_blank">Event Sourcing</a>; a pattern thought of by Martin Fowler that, “<i>Captures all changes to an application state as a sequence of events.</i>”</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="chipper" border="0" alt="chipper" align="right" src="http://elegantcode.com/wp-content/uploads/2010/02/chipper.jpg" width="240" height="159" />Hey that is interesting, so instead of trying to store the object tree in a whole, we just store all the individual state changes that the object tree encapsulates; meaning all the state changes that have happened during the complete lifetime of the object tree. These state changes are being represented in the form of events. And such an event is nothing more then a <a href="http://en.wikipedia.org/wiki/Plain_Old_CLR_Object" target="_blank">Plain Old CLR Object</a>, so not an actual .Net event.</p>
<p>And the objects are also re-constructed from the same events by applying all the state changes that they represent, and thus coming back to the previous state in the identical way that it came there originally.</p>
<p>Now the interesting part with respect to persistence is that these events are being serialized using a technique you like (Binary, JSon or custom) and this serialized event (object) is persisted in an event store, and this event store will threat all serialized events equally. </p>
<p>This event store can be based on an object database, document database, file system or even a RDBMS, you basically need to have one collection that describes all the different objects that the event store has persisted this includes the Id and the Version. Then another collection will contain all the serialized events for each different object and they should be retrievable by the object Id ordered by their Version. So to simplify this, in a RDBMS this would mean 2 tables, in total.</p>
<p>So there is no impendence mismatch between the domain (object structure) and the persistence layer anymore. Which would mean that it is should pass Rob’s criteria&#8217;s as well.</p>
<p>But hey it doesn’t stop there, you get a real <a href="http://martinfowler.com/eaaDev/AuditLog.html" target="_blank">audit log</a> for free a well. And you have the ability to replay all the events to abstract new information about certain state changes. For example a web store is in business for 6 months and now they would like to know when and where an item is being removed from the shopping cart. With an event store you will have this information from the start of the system, and you didn’t have to think about it straight from the start.</p>
<p>And this also enables an easier swift to an Event Driven Architecture as well, because you can start publishing the events outside of the domain and have different behavior or processes react on them.</p>
<p>In my <a href="http://github.com/MarkNijhof/Fohjin/tree/master/Fohjin.DDD.Example/" target="_blank">example</a> I use a combination of CQRS and Event Sourcing and this makes a very powerful solution. I would recommend that when you are when applying CQRS you would do that in combination with Event Sourcing to get a very flexible system without much more complexity then just applying CQRS.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/02/05/cqrs-event-sourcing/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

