<?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>Ian Oxley &#187; unit testing</title>
	<atom:link href="http://ianoxley.com/tag/unit-testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://ianoxley.com</link>
	<description>Web Developer</description>
	<lastBuildDate>Tue, 11 Oct 2011 08:33:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>How To Reset Your SubSonic 3 ActiveRecord Test Repository For Each Unit Test</title>
		<link>http://ianoxley.com/2009/09/04/how-to-reset-your-subsonic-3-activerecord-test-repository-for-each-unit-test/</link>
		<comments>http://ianoxley.com/2009/09/04/how-to-reset-your-subsonic-3-activerecord-test-repository-for-each-unit-test/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 13:09:38 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[subsonic]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.strongasanox.co.uk/?p=171</guid>
		<description><![CDATA[When writing unit tests with SubSonic&#8217;s new built-in testing for ActiveRecord don&#8217;t forget that each time you call the Setup() method on your ActiveRecord object it adds records to any that have already been created. For example: [Test] public void Foo_Bar() { Foo.Setup(10); Assert.AreEqual(10, Foo.All().Count()); } [Test] public void Bar_Foo() { Foo.Setup(10); // This will [...]]]></description>
			<content:encoded><![CDATA[<p>When writing unit tests with <a href="http://subsonicproject.com/docs/Using_ActiveRecord#Testing">SubSonic&#8217;s new built-in testing for ActiveRecord</a> don&#8217;t forget that each time you call the <strong>Setup()</strong> method on your ActiveRecord object it adds records to any that have already been created. For example:</p>
<pre>[Test]
public void Foo_Bar() {
    Foo.Setup(10);
    Assert.AreEqual(10, Foo.All().Count());
}

[Test]
public void Bar_Foo() {
    Foo.Setup(10);

    // This will fail: Foo.All().Count() will return 20
    Assert.AreEqual(10, Foo.All().Count());
}</pre>
<p>To reset your test repositories you will need to call the <strong>ResetTestRepo()</strong> method prior to each test, which can be accomplished easily enough by adding the method call to your test&#8217;s <strong>[SetUp]</strong> method:</p>
<pre>[SetUp]
public void SetUp() {
    Foo.ResetTestRepo();
}

[Test]
public void Foo_Bar() {
    Foo.Setup(10);
    Assert.AreEqual(10, Foo.All().Count());
}

[Test]
public void Bar_Foo() {
    Foo.Setup(10);

    // Now Foo.All().Count() will return 10 and the test will pass
    Assert.AreEqual(10, Foo.All().Count());
}</pre>
<p>Hopefully this will save you a bit of time, as well as head scratching :p</p>
]]></content:encoded>
			<wfw:commentRss>http://ianoxley.com/2009/09/04/how-to-reset-your-subsonic-3-activerecord-test-repository-for-each-unit-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

