{"id":157,"date":"2007-04-30T20:39:44","date_gmt":"2007-05-01T02:39:44","guid":{"rendered":"http:\/\/jameskovacs.com\/2007\/05\/01\/Rhino+Mocks+305+Released+With+Explicit+RecordPlayback"},"modified":"2007-04-30T20:39:44","modified_gmt":"2007-05-01T02:39:44","slug":"rhino-mocks-305-released-with-explicit-recordplayback","status":"publish","type":"post","link":"https:\/\/www.jameskovacs.com\/index.php\/2007\/04\/30\/rhino-mocks-305-released-with-explicit-recordplayback\/","title":{"rendered":"Rhino Mocks 3.0.5 Released with Explicit Record\/Playback"},"content":{"rendered":"<p>A few days ago, I read Kyle Baley&#8217;s <a href=\"http:\/\/kyle.baley.org\/RhinoMocksOrQuotHowToExplainTheIntroductoryChapterOfAMockFrameworkquot.aspx\">post<\/a> about learning Rhino Mocks. Like many folks, he initially had trouble understanding Rhino Mocks&#8217; record\/playback metaphor. Then during the <a href=\"http:\/\/www.calgarycodecamp.com\/\">Calgary Code Camp<\/a>, an attendee kindly pointed out that I had forgotten mockRepository.ReplayAll() in my unit test &#8211; fortunately before I actually ran it. Then yesterday I was catching up on my blog reading and saw <a href=\"http:\/\/ayende.com\/Blog\/archive\/2007\/04\/28\/A-developer-so-retarded.aspx\">this post<\/a> from Oren discussing various people forgetting to call mockRepository.ReplayAll(), including Oren himself.<\/p>\n<p>I thought to myself, Rhino Mocks has a very nice fluent interface, but doesn&#8217;t make its Record\/Playback explicit. What would I want my code to look like if it did support explicit Record\/Playback? So I grabbed the source from Subversion, put on my TDD hat, and came up with this failing test:<\/p>\n<div style=\"FONT-SIZE: 11pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas, Lucida Console, monospace\">\n<pre style=\"MARGIN: 0px\">[<span style=\"COLOR: #2b91af\">Test<\/span>]<\/pre>\n<pre style=\"MARGIN: 0px\"><span style=\"COLOR: blue\">public<\/span> <span style=\"COLOR: blue\">void<\/span> CanRecordPlayback() {<\/pre>\n<pre style=\"MARGIN: 0px\">&nbsp;&nbsp;&nbsp; <span style=\"COLOR: #2b91af\">MockRepository<\/span> mockRepository = <span style=\"COLOR: blue\">new<\/span> <span style=\"COLOR: #2b91af\">MockRepository<\/span>();<\/pre>\n<pre style=\"MARGIN: 0px\">&nbsp;&nbsp;&nbsp; <span style=\"COLOR: #2b91af\">IFoo<\/span> mockedFoo = mockRepository.CreateMock&lt;<span style=\"COLOR: #2b91af\">IFoo<\/span>&gt;();<\/pre>\n<pre style=\"MARGIN: 0px\">&nbsp;&nbsp;&nbsp; <span style=\"COLOR: blue\">using<\/span>(mockRepository.Record()) {<\/pre>\n<pre style=\"MARGIN: 0px\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style=\"COLOR: #2b91af\">Expect<\/span>.Call(mockedFoo.Bar()).Return(42);<\/pre>\n<pre style=\"MARGIN: 0px\">&nbsp;&nbsp;&nbsp; }<\/pre>\n<pre style=\"MARGIN: 0px\">&nbsp;&nbsp;&nbsp; <span style=\"COLOR: blue\">using<\/span>(mockRepository.Playback()) {<\/pre>\n<pre style=\"MARGIN: 0px\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style=\"COLOR: #2b91af\">Fooz<\/span> fooz = <span style=\"COLOR: blue\">new<\/span> <span style=\"COLOR: #2b91af\">Fooz<\/span>(mockedFoo);<\/pre>\n<pre style=\"MARGIN: 0px\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fooz.Barz();<\/pre>\n<pre style=\"MARGIN: 0px\">&nbsp;&nbsp;&nbsp; }<\/pre>\n<pre style=\"MARGIN: 0px\">}<\/pre>\n<\/div>\n<p><!--EndFragment--><\/p>\n<p>A few minutes later, I had working code for the Record and Playback methods, all the unit tests passed, I created a patch, and emailed&nbsp;it to Oren for his thoughts on the new syntax. He liked it so much that&nbsp;he included&nbsp;the new syntax in <a href=\"http:\/\/www.ayende.com\/Blog\/archive\/2007\/05\/01\/Rhino-Mocks-3.0.5-Released.aspx\">Rhino Mocks 3.0.5<\/a>, which he just released today.<\/p>\n<p>A few things to note about the new syntax. Expectations are grouped in the Record block. Exercising the mocks occurs in the Playback() block. ReplayAll()&nbsp;and VerifyAll() are called implicitly after the Playback() and Record() blocks, respectively.<\/p>\n<p>Time between initial idea and&nbsp;production deployment: Less than 24 hours. How is that for great turn-around? Thanks, Oren. I&#8217;m proud to have committed to such a widely-used (and respected) project!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few days ago, I read Kyle Baley&#8217;s post about learning Rhino Mocks. Like many folks, he initially had trouble understanding Rhino Mocks&#8217; record\/playback metaphor. Then during the Calgary Code Camp, an attendee kindly pointed out that I had forgotten mockRepository.ReplayAll() in my unit test &#8211; fortunately before I actually ran it. Then yesterday I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-157","post","type-post","status-publish","format-standard","hentry","category-dotnettools","category-agile"],"_links":{"self":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts\/157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/comments?post=157"}],"version-history":[{"count":0,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts\/157\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/media?parent=157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/categories?post=157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/tags?post=157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}