<?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>ORTHOcoders &#187; Testing</title>
	<atom:link href="http://orthocoders.com/tag/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://orthocoders.com</link>
	<description>U can code it, we can help</description>
	<lastBuildDate>Fri, 13 Jan 2012 07:16:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Real world BDD introduction</title>
		<link>http://orthocoders.com/2010/05/26/real-world-bdd-introduction/</link>
		<comments>http://orthocoders.com/2010/05/26/real-world-bdd-introduction/#comments</comments>
		<pubDate>Thu, 27 May 2010 02:58:40 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[PrairieDevCon]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://orthocoders.com/?p=162</guid>
		<description><![CDATA[Getting ready for PrairieDevCon Next week I’ll be presenting at the PrairieDevCon in Regina and one of my presentations is about Behavior Driven Development, how to apply it using .NET tools like SpecFlow, Nunit, Watin, Cassini, MbUnit, etc. Because is a Dojo/Code with me presentation I’m planning to do a BDD exercise with all the [...]]]></description>
			<content:encoded><![CDATA[<h3>Getting ready for PrairieDevCon</h3>
<p>Next week I’ll be presenting at the <a href="http://www.prairiedevcon.com" target="_blank">PrairieDevCon</a> in Regina and one of my presentations is about Behavior Driven Development, how to apply it using .NET tools like SpecFlow, Nunit, Watin, Cassini, MbUnit, etc.</p>
<p>Because is a Dojo/Code with me presentation I’m planning to do a BDD exercise with all the attendees to show them how to describe a new feature using BDD and implement it together.</p>
<p>We will start with a project that has one feature implemented, and will code together the second feature using full BDD and TDD.</p>
<p>So, what should I use to illustrate BDD? No other than my old friend the MediaLibrary example that I used quite a few times, but now including a full BDD implementation.</p>
<h3>MediaLibrary</h3>
<p>The MediaLibrary project is a web application that  allows the user to register and catalog his collection of movies, books, games, etc.</p>
<p>I’m using GitHub to publish the code we are going to use in the Dojo. Right now the latest version represents the code that I’m going to start with.</p>
<p>If you would like to check out the code I’m going to use please go to the <a href="http://orthocoders.com/prairiedevcon/" target="_blank">PrairieDevCon page</a> on my blog and get the code from <a href="http://github.com/amirci/Media-Library-Demo-PrairieDevCon-2010" target="_blank">GitHub</a>, read the README file to verify you have the requirements installed and the application is working.</p>
<p>Do you have everything installed? Did you read the README file? Cool, open the solution and let’s move on!</p>
<h3>Using BDD</h3>
<p>Behavior Driven Development is a term used to describe (in our case) development that starts by writing the feature (or user story) that we want to implement. Once we have the feature, we will use a “story runner” that will run the feature we just wrote and show if the story is actually implemented as we wanted or not yet. If it is, good, everything should be “green”. If not, we get a “red”, and we have to add code and implement more functionality to make it pass.</p>
<p>To write the user story we are going to use a particular syntax from the Gherkin language. The Gherkin language has very few rules, please read the introduction for Cucumber from <a title="http://wiki.github.com/aslakhellesoy/cucumber/gherkin" href="http://wiki.github.com/aslakhellesoy/cucumber">Aslak Hellesoy</a>.</p>
<p>Let’s see the feature that it’s implemented in the code, <em>Browse Movies:</em></p>
<pre class="code"><span style="color: blue;">Feature: </span>Browse Movies
    As a User
    I want to Browse Movies
    So I can see the contents of the library

    <span style="color: blue;">Scenario: </span>Browse available movies
        <span style="color: blue;">Given </span><span style="color: green;">I have the following movies:
          </span>| title           |
          | Blazing Saddles |
          | Space Balls     |
        <span style="color: blue;">When </span><span style="color: green;">I go to </span><span style="color: red;">Movies
        </span><span style="color: blue;">Then </span><span style="color: green;">I should see in the listing:
          </span>| title             |
          | Blazing Saddles   |
          | Space Balls       |</pre>
<p>What is most important here is to look at the scenario. The scenario is describing that if you have movies A, B and C in the library, when you browse you should see the same movies on the <em>Movies</em> page.</p>
<p>Now if we want to check the feature manually, what would we do? Something like this:</p>
<ol>
<li>Add the movies to the storage</li>
<li>Start the web application</li>
<li>Launch the browser</li>
<li>Go to the movies page</li>
<li>Check that all the movies in the storage are listed in the browser</li>
</ol>
<p>The thing is that I don’t want to validate each feature (with many scenarios) manually, I’d like the scenario/feature runner to do that for me, add the movies, launch the browser and check, everything automated following the steps I wrote in my scenario.</p>
<p>Probable we could manage to write code that will do that for us, now, the question is how the scenario runner translates this feature into actual code? If we were using rails we could use <em>Cucumber, </em>but luckily for the .NET world we can use <a href="http://www.specflow.org">SpecFlow</a> (<em><a href="http://ironruby.net/download">IronRuby</a></em> too, but that’s another post).</p>
<h3>Given That I have the following movies</h3>
<p>Specflow is a tool that understands <a href="http://wiki.github.com/aslakhellesoy/cucumber/gherkin">Gherkin</a> and generates an <a href="http://nunit.org/">NUnit</a> test for every feature that we use. Being an NUnit test, simplifies how we going to run the specification. Just run the NUnit test with your favorite test runner: <a href="http://www.jetbrains.com/resharper/">ReSharper</a>, NUnit (console or GUI), <a href="http://www.gallio.org">MbUnit</a>, etc.</p>
<p>Each scenario is composed by a series of steps, each step is identified by a Gherkin keyword, in our feature we found <em>Given, When</em> and <em>Then.</em></p>
<p>The NUnit test has code for each scenario and will invoke the steps indicated in the scenario.</p>
<p>In order to do so, Specflow uses the text that we write in the step, to match the code.</p>
<p>Let’s look at our first step “Given I have the following movies:”. In order to implement the step, in the code, you will find a method that looks like:</p>
<pre class="code">[<span style="color: #2b91af;">Given</span>(<span style="color: #a31515;">@"I have the following movies:"</span>)]
<span style="color: blue;">public void </span>AddMovies(<span style="color: #2b91af;">Table </span>movies)
{
    movies.Rows.ForEach(row =&gt; AddMovieToStorage(row[<span style="color: #a31515;">"title"</span>]));
}</pre>
<p>The <em>Given</em> attribute is used to match the text we wrote in the scenario, to indicate the the method <em>AddMovies</em> should be called when the step is invoked.</p>
<p>The step in the scenario indicates that the method receives a series of rows should be passed as parameter (first row is the title, every column separated by “|”), that is why it receives a <em>Table</em>.</p>
<p>In the implementation for each movie in the table, the title will be added to the storage. Check the method <em>AddMoviesToStorage</em> for more details.</p>
<p>Now that we setup our storage we are ready to move on and launch the browser.</p>
<h3>When I go to Movies</h3>
<p>The next step to implement implies opening the browser and going to the <em>Movies </em>page to see the listing<em>.</em></p>
<p>Now, to do so we need two things, first the web application running and then to launch a browser to go the actual page.</p>
<p>To run the application I’m going to use <a href="http://www.asp.net/downloads/archived-v11/cassini">Cassini</a> web server. The setup of the features will start the web server and stop it when it’s not needed any more. We can see the implementation in the <em>Browser </em>class under Utililty.</p>
<pre class="code"><span style="color: blue;">static </span>Browser()
{
    WebServer = <span style="color: blue;">new </span><span style="color: #2b91af;">Server</span>(Port, <span style="color: #a31515;">"/"</span>, GetPhysicalPath());
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>With the server running, we now need to launch the browser and automate the checking for all the movies.</p>
<p>For that we are going to use<em> </em>Watin. <a href="http://watin.sourceforge.net/">Watin</a> (Web automation test in .NET) is a library that helps us to manipulate the browser (based on <a href="http://watir.com/">Watir</a>) and also give us all the HTML for the page we are visiting.</p>
<p>We can see the use of the <em>IE </em>instance in the <em>Browser</em> class:</p>
<pre class="code"><span style="color: blue;">public static void </span>InitializeBrowser()
{
    WebServer.Start();

    Instance = <span style="color: blue;">new </span><span style="color: #2b91af;">IE</span>(ApplicationURL);
}

<span style="color: blue;">public static void </span>ShutdownBrowser()
{
    Instance.Close();

    WebServer.Stop();
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Now that we have our server running, and our <em>IE</em> instance, we only need to go to the right path. In this case we want to go to “/Movies”. For that let’s look at the <em>NavigationSteps class:</em></p>
<pre class="code">[<span style="color: #2b91af;">When</span>(<span style="color: #a31515;">@"I go to (.*)"</span>)]
<span style="color: blue;">public void </span>WhenIGoToPage(<span style="color: blue;">string </span>pageName)
{
    <span style="color: #2b91af;">Browser</span>.GoTo(PathFor(pageName));
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The step uses the browser to navigate to the right page. The page is passed as a parameter that we can see in the attribute as a regular expression.</p>
<p>So far, so good. Now, our last step is to check for the movies in the page to make sure that all of them are in the list.</p>
<h3>Then I should see in the listing</h3>
<p>To implement the last step in our scenario we are going to use the following implementation:</p>
<pre class="code">[<span style="color: #2b91af;">Then</span>(<span style="color: #a31515;">@"I should see in the listing:"</span>)]
<span style="color: blue;">public void </span>AssertListingContains(<span style="color: #2b91af;">Table </span>movies)
{
    <span style="color: blue;">var </span>expected = movies.Rows.Select(row =&gt; row[<span style="color: #a31515;">"title"</span>]);

    <span style="color: blue;">var </span>listing = <span style="color: blue;">this</span>.Page.Listing;

    listing.Should().Have.SameSequenceAs(expected);
}</pre>
<p>Again we are using a step that takes a table as parameter, so we iterate thru the table and get the titles of all the movies that should be in the page.</p>
<p>The code has no mysteries except the <em>Page</em> property.</p>
<pre class="code"><span style="color: blue;">public </span>ListingSteps()
{
    <span style="color: blue;">this</span>.Page = <span style="color: blue;">new </span><span style="color: #2b91af;">BrowseMoviesPage</span>();
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The <em>Page</em> property is initialized in the constructor and the goal of the <em>BrowseMoviesPage</em> is to abstract the internals of how the movies are listed in the page. For example, right now the view that implements the listing of movies uses a table for each movie, however it could use a <em>DIV</em> or some other tag. Here is the implementation:</p>
<pre class="code"><span style="color: blue;">public </span><span style="color: #2b91af;">IEnumerable</span>&lt;<span style="color: blue;">string</span>&gt; Listing
{
    <span style="color: blue;">get
    </span>{
        <span style="color: blue;">var </span>elements = <span style="color: #2b91af;">Browser</span>.Instance.TableCells.Where(cell =&gt; cell.ClassName == <span style="color: #a31515;">"title"</span>);

        <span style="color: blue;">return </span>elements.Select(e =&gt; e.InnerHtml.Trim());
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>As we can see, the code is getting all the table cells where the <em>CSS</em> class is <em>title</em> and then getting the inner html and trimming it.</p>
<p>If we would have to use this code every time we want to check the listing we would have code duplication, plus if the implementation of the view changes, we would have to modify each piece of code that refers to this page. Using the <em>PageObject</em> pattern we avoid code duplication and it’s easy to change the implementation.</p>
<p>And voila! We got all our steps implemented.</p>
<h3>What’s next?</h3>
<p>If you join me next week on the Prairie Dev Con, we will implement the next feature together “<em>Add Movies”.</em></p>
<p>What’s so cool about BDD? Please go ahead and run “rake test:features” on the command line, and you’ll see that the steps for the second feature are still pending, that means that they are not implemented yet.</p>
<p>Writing the feature first we manage to describe what we want, and implementing step by step we make sure that we are working towards make the feature pass. BDD on the outside and TDD on the inside.</p>
<p>Hope to see you all next week in the conference!</p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2010/05/26/real-world-bdd-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Database Testing Automation</title>
		<link>http://orthocoders.com/2009/01/29/database-testing-automation/</link>
		<comments>http://orthocoders.com/2009/01/29/database-testing-automation/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 05:18:32 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://orthocoders.com/?p=10</guid>
		<description><![CDATA[Why testing? If you are wondering why you should test your code or why using Test Driven Development is a great advantage then please check Wikipedia, AgileData and Kent Beck&#8217;s book. If you are convinced so far, please read on. Testing Automation Writing tests allow us to prove that our code work as expected. Having [...]]]></description>
			<content:encoded><![CDATA[<h2>Why testing?</h2>
<p>If you are wondering why you should test your code or why using Test Driven Development is a great advantage then please check <a title="Wikipedia TDD" href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank">Wikipedia</a>, <a title="Scott W. Ambler TDD" href="http://http://www.agiledata.org/essays/tdd.html">AgileData </a>and <a title="Kent Beck: TDD by example" href="http://http://www.amazon.com/Test-Driven-Development-Addison-Wesley-Signature/dp/0321146530">Kent Beck&#8217;s book</a>. If you are convinced so far, please read on.</p>
<h2>Testing Automation</h2>
<p>Writing tests allow us to prove that our code work as expected. Having tests written also allow us to run all our tests every time new code is added to make sure that nothing broke so far.</p>
<p>Continuous Integration is a common practice used to build, test and deploy every time the code changes in the repository. Because the build script is run from our CI server,  our tests should be designed and written to run without external dependencies or with few as possible. If you want to read more about continuous integration you can read <a title="Martin Fowler's CI" href="http://http://martinfowler.com/articles/continuousIntegration.html">Martin Fowler&#8217;s article about it</a>.</p>
<h2>I have a DB, where should I start?</h2>
<p>First of all we need to model our Data Access Layer (DAL for short) to provide access to the storage.</p>
<p>The <em>DAL </em>provides the interfaces and classes that will abstract our application from our target storage. Thus if we decide to use <a title="LINQ 2 SQL" href="http://msdn.microsoft.com/en-us/library/bb425822.aspx" target="_blank"><em>LINQ to SQL</em></a> or <em><a title="ADO EF" href="http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx" target="_blank">ADO Entity Framework</a> </em>or <a title="Castle AR" href="http://www.castleproject.org/ActiveRecord/" target="_blank"><em>Castle ActiveRecord</em></a> as implementation the <em>DAL </em>does not change and does not impact the rest of our application. Different needs may require different <em>DAL </em>implementations, we can even use <a title="REST" href="http://en.wikipedia.org/wiki/Representational_State_Transfer" target="_blank">REST</a> services to access our storage with the same <em>DAL</em>.</p>
<p>As an example to illustrate the testing let&#8217;s imagine we have a <em>DAL</em> to represent a media library. A media library is a library that stores DVDs, games, music for a user. Here is a small diagram to describe the structure I&#8217;m planning to use:</p>
<h2><a href="http://orthocoders.com/wp-content/uploads/2009/01/diagram.png"><img class="aligncenter size-full wp-image-11" title="DAL Diagram DbTest" src="http://orthocoders.com/wp-content/uploads/2009/01/diagram.png" alt="DAL Diagram DbTest" width="499" height="385" /></a></h2>
<h2>DAL, SHMAL, what about testing?</h2>
<p>So far, so good. We have our <em>DAL </em>and before writing our first class, let&#8217;s think about what we need to write the test.</p>
<p>The test should check that our concrete <em>DAL</em> implementation is querying/modifying the database in the expected way. In order to do that, I can think of the following requirements:</p>
<ul>
<li>Try to minimize dependencies (if possible) with the database in order to run the test stand alone.</li>
<li>Each test should start from a valid clean database (need a way of create/drop the schema).</li>
<li>The database should be deleted after the tests are done.</li>
</ul>
<p>Because we have the same requirements for all our tests I think a base class would suit our needs and provide common functionality. Let&#8217;s call it <em>BaseDbTest</em>.</p>
<p>To fulfill our requirements I&#8217;m going to take advantage of MbUnit initialization and clean up events:</p>
<ul>
<li><em>FixtureSetUp</em>: Runs before all the tests in the class are run.</li>
<li><em>SetUp</em>: Runs before each test is run.</li>
<li><em>TearDown</em>: Runs after each test is run.</li>
<li><em>FixtureTearDown</em>: Runs after all the test in the class are run.</li>
</ul>
<p>So, how to use these events for our goal? Let&#8217;s see:</p>
<ul>
<li><em>FixtureSetUp</em>: Create the database and initialize framework.</li>
<li><em>SetUp</em>: Create the schema and populate the database.</li>
<li><em>TearDown</em>: Drop the schema.</li>
<li><em>FixtureTearDown</em>: Drop database.</li>
</ul>
<p>And here is the code for the test:</p>
<pre class="csharp" name="code">        ///
        /// Creates the schema for an empty database
        ///
        [SetUp]
        public void BeforeEachTest()
        {
            CreateSchema();
        }

        ///
        /// Drops the schema to clean the database
        ///
        [TearDown]
        public void AfterEachTest()
        {
            DropSchema();
        }

        ///
        /// Creates a temporary database using a temporary file name and
        /// initializes the entities using the connection string to that database
        ///
        [FixtureSetUp]
        public void BeforeAllTheTests()
        {
            CreateDatabase();
            InitializeFramework();
        }

        ///
        /// Clears up the resources and deletes the database file used
        ///
        [FixtureTearDown]
        public void AfterAllTheTests()
        {
            DeleteDatabase();
        }
</pre>
<p>That&#8217;s  a good start. Now we have to think about which database we are going to use for the testing.</p>
<p>Because we would like to minimize the dependencies with any database in order to run the tests in any environment I&#8217;m going to use a <a title="SQL CE" href="http://en.wikipedia.org/wiki/SQL_Server_Compact" target="_blank">SQL CE</a> database. <em>SQL CE</em> uses a file as storage and we can generate the file when we need it and then delete it.</p>
<p>So here is the implementation to create and delete the database using <em>SQL CE</em>:</p>
<pre name="code" class="csharp">
        ///
<summary>
        /// Creates the database file using a temporary file name
        /// </summary>

        private void CreateDatabase()
        {
            this.DatabaseFileName = Path.GetTempFileName();

            DeleteDatabase();

            var engine = new SqlCeEngine(this.ConnectionString);

            engine.CreateDatabase();
        }

        ///
<summary>
        /// Deletes the database file
        /// </summary>

        private void DeleteDatabase()
        {
            File.Delete(this.DatabaseFileName);
        }

        ///
<summary>
        /// Filename to use for the database
        /// </summary>

        protected string DatabaseFileName { get; set; }
</pre>
<p>Now, we need to create/drop the schema and initialize the framework. To do that we need to chose which framework we are going to use, in this case I&#8217;m using <em>Castle ActiveRecord</em> to do it:</p>
<pre name="code" class="csharp">
        ///
<summary>
        /// Creates the schema to run the tests
        /// </summary>

        virtual protected void CreateSchema()
        {
            // log the creation script
            // ActiveRecordStarter.GenerateCreationScripts( "c:\\temp\\create.sql");

            ActiveRecordStarter.CreateSchema();
        }

        ///
<summary>
        /// Connection string to use
        /// </summary>

        protected string ConnectionString
        {
            get
            {
                return String.Format( "Data Source={0};", this.DatabaseFileName);
            }
        }

        ///
<summary>
        /// Creates the properties and initializes the framework using ActiveRecordStarter
        /// </summary>

        private void InitializeFramework()
        {
            var properties = new Dictionary&lt;String, String&gt;
                                 {
                                     //{"hibernate.show_sql", "true"},
                                     {"hibernate.connection.driver_class", "NHibernate.Driver.SqlServerCeDriver"},
                                     {"hibernate.dialect", "NHibernate.Dialect.MsSqlCeDialect"},
                                     {"hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider"},
                                     {"hibernate.connection.connection_string", this.ConnectionString}
                                 };

            var source = new InPlaceConfigurationSource();

            source.Add( typeof(ActiveRecordBase), properties);

            ActiveRecordStarter.ResetInitializationFlag();

            ActiveRecordStarter.Initialize( typeof( MediaElement ).Assembly, source );
        }

        ///
<summary>
        /// Drops the schema after running the tests
        /// </summary>

        virtual protected void DropSchema()
        {
            ActiveRecordStarter.DropSchema();
        }
</pre>
<p>Voilá, that&#8217;s it. <em>Castle ActiveRecord</em> provides a very convenient way of creating and dropping the schema using the <em>ActiveRecordStarter</em> class. Be mindful that the <em>InitializeFramework</em> runs once before per test class, thus we need to reset the initialization to avoid error messages using <em>ActiveRecordStarter.ResetInitializationFlag()</em>.</p>
<h2>Last but not least, our first test</h2>
<p>To test our implementation let&#8217;s start with IMediaLibrary implementation to check that the following cases are true:</p>
<ul>
<li>When calling <em>Contents</em> all the media in the database is returned.</li>
<li>When calling <em>Users</em> all the users in the database are returned.</li>
<li>When adding media to the library the media is stored</li>
</ul>
<p>Without further ado:</p>
<pre name="code" class="csharp">
        ///
<summary>
        /// Tests that all the users in the database are returned
        /// </summary>

        [Test]
        public void WhenAskingForTheUsersAllTheUsersShouldBeReturned()
        {
            var expected = factory.LotsOf&lt;IUser&gt;();

            var actual = this.mediaLib.Users;

            Assert.IsNotNull( actual, "The users should not be null" );

            var eSorted = expected.OrderBy(e => ((User)e).Id);
            var aSorted = expected.OrderBy(a => ((User)a).Id);

            Assert.Over.Pairs(aSorted, eSorted, Assert.AreEqual);
        }

        ///
<summary>
        /// Tests that all the media in the database is returned
        /// </summary>

        [Test]
        public void WhenAskingForTheMediaAllTheContentsShouldBeReturned()
        {
            var expected = factory.LotsOf&lt;IMediaElement&gt;();

            var actual = this.mediaLib.Contents;

            Assert.IsNotNull(actual, "The users should not be null");

            var eSorted = expected.OrderBy(e => ((MediaElement)e).Id);
            var aSorted = expected.OrderBy(a => ((MediaElement)a).Id);

            Assert.Over.Pairs( aSorted, eSorted, Assert.AreEqual );
        }

        ///
<summary>
        /// Tests that when adding new media the collection grows
        /// </summary>

        [Test]
        public void WhenAddingNewMediaTheCollectionShouldHaveOneMore()
        {
            var oldContents = this.mediaLib.Contents;

            var oldCount = oldContents.Count();

            var user = factory.OneUser();

            var added = this.mediaLib.AddMedia&lt;IMovieElement&gt;( "Test", user );

            var actualContents = this.mediaLib.Contents;

            Assert.IsNotNull( added );
            Assert.AreEqual( oldCount + 1 , actualContents.Count(), "The count should be increased by one");
            Assert.AreEqual( added, actualContents.Last() );
        }
</pre>
<p>To generate another test we just need to write a new class and inherit from <em>BaseDbTest</em>. </p>
<p>To download the full example please click here <a href='http://orthocoders.com/wp-content/uploads/2009/01/dbtest.zip'>DbTest source code</a>.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2009/01/29/database-testing-automation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

