<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>maonet technotes &#187; test</title>
	<atom:link href="http://maonet.wordpress.com/category/test/feed/" rel="self" type="application/rss+xml" />
	<link>http://maonet.wordpress.com</link>
	<description>IOC(SM):MOC(RM):TDD(NU):SCC(TFS):ORM(L2S):JSL(Jq):CIS(CC)</description>
	<lastBuildDate>Thu, 31 Dec 2009 17:16:53 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='maonet.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/27569a47b055d3d0ff1d52cf3b0ce0d7?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>maonet technotes &#187; test</title>
		<link>http://maonet.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://maonet.wordpress.com/osd.xml" title="maonet technotes" />
		<item>
		<title>No configuration Wcf host and client</title>
		<link>http://maonet.wordpress.com/2009/08/21/no-configuration-wcf-host-and-client/</link>
		<comments>http://maonet.wordpress.com/2009/08/21/no-configuration-wcf-host-and-client/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 16:13:27 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[WCF]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=727</guid>
		<description><![CDATA[Using Exception in Wcf should be very caucious, as I blogged before, wcf exception should be marked as Serializable, and implement all 4 ctor from base exception class. An unit-test for each exception might be overkill, but it&#8217;s worth to try. 
In-proc wcf host is neat for this purpose, by using channel Factory, client side [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=727&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Using Exception in Wcf should be very caucious, as I <a href="http://maonet.wordpress.com/2009/06/11/sending-customized-errorexception-to-wcf-client/">blogged </a>before, wcf exception should be marked as <span><span>Serializable, and implement all 4 ctor from base exception class. An unit-test for each exception might be overkill, but it&#8217;s worth to try. </span></span></p>
<p><span><span>In-proc wcf host is neat for this purpose, by using channel Factory, client side doesn&#8217;t need configuration either.</span></span></p>
<p><span><span>
<pre class="brush: csharp;">
    [TestFixture]
    public class MyDataNotFoundExceptionSpecs
    {
        private readonly ServiceHost _host;
        private const string _url = &quot;net.tcp://localhost:9000/TestException&quot;;

        public MyDataNotFoundExceptionSpecs()
        {
            _host = new ServiceHost(typeof(TestService));

            _host.AddServiceEndpoint(typeof(ITestService),
                new NetTcpBinding(), _url);
            _host.Open();
            Console.WriteLine(&quot;wcf service started.&quot;);
        }

        ~MyDataNotFoundExceptionSpecs()
        {
            _host.Close();
        }
            private ChannelFactory&lt;ITestService&gt; channelFactory;
            [SetUp]
            public void SetupChannelFacotry()
            {
                channelFactory = new ChannelFactory&lt;ITestService&gt;(
                   new NetTcpBinding(),
                   new EndpointAddress(_url));
            }
            [TearDown]
            public void CleanUpChannelFacotry()
            {
                    channelFactory.Abort();
            }
        [Test]
        [ExpectedException(typeof(FaultException&lt;MyDataNotFoundException&gt;))]
        public void should_passed_to_client()
        {
            ITestService proxy = channelFactory.CreateChannel();

            proxy.Ping(&quot;Frank&quot;);

          }

    }

    public class TestService : ITestService
    {
        public void Ping(string user)
        {
            throw new FaultException&lt;MyDataNotFoundException&gt;(new MyDataNotFoundException());
        }
    }

    [ServiceContract]
    public interface ITestService
    {
        [OperationContract]
        [FaultContract(typeof(MyDataNotFoundException))]
        void Ping(string user);
    }
</pre>
<p></span></span></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/727/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/727/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/727/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/727/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/727/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/727/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/727/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/727/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/727/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/727/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=727&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2009/08/21/no-configuration-wcf-host-and-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
		<item>
		<title>Test cascade delete using sql query</title>
		<link>http://maonet.wordpress.com/2009/08/05/test-cascade-delete-using-sql-query/</link>
		<comments>http://maonet.wordpress.com/2009/08/05/test-cascade-delete-using-sql-query/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 16:25:47 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=708</guid>
		<description><![CDATA[When first starting NH mapping, we just want to make sure the data is really being deleted, for cascaded child, some tricky code are needed to work around the strong relationship we created in domain entities. SqlQuery is one of those.


[Test]
 public void Should_delete_email()
 {
 // Retrieve
 Organization org = _repository.FetchById(8172);

 // Ensure org was [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=708&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>When first starting NH mapping, we just want to make sure the data is really being deleted, for cascaded child, some tricky code are needed to work around the strong relationship we created in domain entities. SqlQuery is one of those.</p>
<pre class="brush: csharp;">

[Test]
 public void Should_delete_email()
 {
 // Retrieve
 Organization org = _repository.FetchById(8172);

 // Ensure org was retrieved.
 Assert.That(org, Is.Not.Null);

 var emailToAdd = new Email(&quot;Home Alternate&quot;, &quot;x@y&quot;);
 org.AddEmail(emailToAdd);

 _repository.Update(org, org.LastModifiedDate);
Assert.That(emailToAdd.Id == 0);
_session.Flush();
Assert.That(emailToAdd.Id &gt; 0);

 // Delete
 org.DeleteEmail(emailToAdd);
 _session.Flush();

 // Ensure email data is physically deleted
 ISQLQuery query = _session.CreateSQLQuery(&quot;select * from Stakeholder_Email_CV where stakeholder_email_id = &quot; +
 emailToAdd.Id);
 Assert.That(query.List().Count == 0);

 }
</pre>
<p>Quite interesting testing code for NHibernate mapping.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/708/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/708/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/708/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/708/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/708/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/708/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/708/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/708/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/708/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/708/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=708&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2009/08/05/test-cascade-delete-using-sql-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
		<item>
		<title>Popup messagebox in ViewModel</title>
		<link>http://maonet.wordpress.com/2009/07/07/popup-messagebox-in-viewmodel/</link>
		<comments>http://maonet.wordpress.com/2009/07/07/popup-messagebox-in-viewmodel/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 21:36:02 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[MVP]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[MVVM]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=685</guid>
		<description><![CDATA[Very interesting topic, Jeremy&#8217;s IMessageBoxService idea is very easy to handle, unit-test. The pain is have to inject this IMessageBox to every class needed.
Glenn Block&#8217;s suggestion is using event handler, code can be a little bit cleanner. Test is a little bit harder.


[Test]
 public void should_validate_new_mail_role_and_raise_show_message_event()
 {
    var subscriber = MockRepository.GenerateMock&#60;IEventSubscriber&#62;();
     _emailRoleMaintViewModel.ShowMessageEvent
     += new System.EventHandler&#60;EventArgs&#60;string&#62;&#62;(subscriber.Handler);

     [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=685&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Very interesting topic, Jeremy&#8217;s IMessageBoxService idea is very easy to handle, unit-test. The pain is have to inject this IMessageBox to every class needed.</p>
<p><a href="http://tech.groups.yahoo.com/group/altdotnet/message/19840?threaded=1&amp;p=3">Glenn Block&#8217;s suggestion </a>is using event handler, code can be a little bit cleanner. Test is a little bit harder.</p>
<pre class="brush: csharp;">

[Test]
 public void should_validate_new_mail_role_and_raise_show_message_event()
 {
    var subscriber = MockRepository.GenerateMock&lt;IEventSubscriber&gt;();
     _emailRoleMaintViewModel.ShowMessageEvent
     += new System.EventHandler&lt;EventArgs&lt;string&gt;&gt;(subscriber.Handler);

     subscriber.Expect(x=&gt;x.Handler( _emailRoleMaintViewModel, new EventArgs&lt;string&gt;(&quot;&quot;) ))
     .IgnoreArguments();

     _emailRoleMaintViewModel.AddEmailRole(&quot;&quot;);

     subscriber.VerifyAllExpectations();

 }
</pre>
<p>More difficult problem is to get the confirmation from view, Glenn&#8217;s solution is &#8216;<em>to raise a separate event to indicate selection which the VM subscribes to</em>&#8216;. Too much overkill for a simple messagebox.</p>
<p><a href="http://www.codeplex.com/CompositeWPF/Thread/View.aspx?ThreadId=46353">Dong Scott&#8217; s post</a> about CancellableCommand is another option, ViewModel only focus on success logic, but give options to view to &#8216;cancel&#8217; the action. The comfirmation rending and analyzing code won&#8217;t be testable then, but who cares? It&#8217;s just a messagebox.</p>
<pre class="brush: csharp;">

public class CancellableCommand : RelayCommand
{

   public void Execute(object parameter)
   {
   var eventHandler = Executing;
   CancelEventArgs cancelEventArgs = new CancelEventArgs(true);
   if (eventHandler != null)
   {
     eventHandler(parameter, cancelEventArgs);
   }

   if (cancelEventArgs.Cancel) return;

    _execute(parameter);
   }

    public event CancelEventHandler Executing;

}

[Test]
 public void should_stop_if_view_cancel()
 {
 var subscriber = MockRepository.GenerateMock&lt;IEventSubscriber&lt;CancelEventArgs&gt;&gt;();
 _emailRoleMaintViewModel.DeleteCommandObject.Executing +=
 new CancelEventHandler(subscriber.Handler);

 subscriber.Expect(x =&gt; x.Handler(_emailRoleMaintViewModel, new CancelEventArgs(true)))
 .IgnoreArguments();

 _emailRoleMaintViewModel.DeleteCommandObject.Execute(&quot;&quot;);

 subscriber.VerifyAllExpectations();
 _mockLookupProxy.AssertWasNotCalled(x =&gt; x.DeleteEmailRole(null), opt =&gt; opt.IgnoreArguments());

 }

 [Test]
 public void should_delete_if_view_did_not_cancel()
 {
 var subscriber = MockRepository.GenerateMock&lt;IEventSubscriber&lt;CancelEventArgs&gt;&gt;();
 _emailRoleMaintViewModel.DeleteCommandObject.Executing +=
 new CancelEventHandler(subscriber.Handler);

 subscriber.Expect(x =&gt; x.Handler(_emailRoleMaintViewModel, new CancelEventArgs(true)))
 .IgnoreArguments()
 .Do(new EventHandler&lt;CancelEventArgs&gt;(
 (o, e) =&gt; { e.Cancel = false; }
 ));

 _emailRoleMaintViewModel.DeleteCommandObject.Execute(&quot;&quot;);

 subscriber.VerifyAllExpectations();
 _mockLookupProxy.AssertWasCalled(x =&gt; x.DeleteEmailRole(null), opt =&gt; opt.IgnoreArguments());
 }

    public interface IEventSubscriber&lt;TEventArgs&gt; where TEventArgs : EventArgs
    {
        void Handler(object sender, TEventArgs e);
    }
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/685/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/685/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/685/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/685/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/685/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/685/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/685/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/685/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/685/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/685/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=685&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2009/07/07/popup-messagebox-in-viewmodel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
		<item>
		<title>Should always ignoreArgument when AssertWasCalled</title>
		<link>http://maonet.wordpress.com/2008/11/28/should-always-ignoreargument-when-assertwascalled/</link>
		<comments>http://maonet.wordpress.com/2008/11/28/should-always-ignoreargument-when-assertwascalled/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 21:30:53 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[CSLA]]></category>
		<category><![CDATA[MVP]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[Rhino]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=326</guid>
		<description><![CDATA[I should have added this option in my test earlier, then I won&#8217;t waste 2+ hours today. The reason causing problem was very simple, AssertWasCalled() method in current verion RhinoMocks (3.5.0.1337 RC) doesn&#8217;t action consistently. I think it&#8217;s because comparing the object reference equalty. I had to add options=&#62;options.IgnoreArguments() to get around from this.
Here is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=326&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I should have added this option in my test earlier, then I won&#8217;t waste 2+ hours today. The reason causing problem was very simple, AssertWasCalled() method in current verion RhinoMocks (3.5.0.1337 RC) doesn&#8217;t action consistently. I think it&#8217;s because comparing the object reference equalty. I had to add options=&gt;options.IgnoreArguments() to get around from this.</p>
<p>Here is a piece of my MVP + CLSA test. Struggled for a while with Property setter, thanks God, it isn&#8217;t that hard.</p>
<pre class="brush: csharp;">

    [TestFixture]
    public class When_initializing_view : EstablishContext
    {
        [Test]
        public void should_call_view_setter_if_id_exists()
        {
            // Arrange
            _mockOrganizationRepository.Expect(x =&gt; x.FindById(1)).Return(_stubOrganizationDTO);

            _mockView = MockRepository.GenerateMock&lt;IEditDetailsView&lt;OrganizationBO&gt;&gt;();

            _presenter = new EditDetailsPresenter&lt;OrganizationBO&gt;(_mockView);

            // Action
            _presenter.InitViewFor(1);

            // Assert
            _mockView.AssertWasCalled(x =&gt; x.CurrentBO = null,
                options =&gt;options.IgnoreArguments() );
        }
    }
</pre>
<p>I then created a generic EditDetailsPresenter, worked as I expected with one concern left: How to mock DataPortal directly. Currently I am still mocking repository. Ideally I should mock DataPortal instead, otherwise I have to make sure there is at least one BO is fully functional.</p>
<p>Mocking DataPortal is very hard, because those Fecth, Create, Update and Delete are all static methods, I had to create an adapter to wrap those static methods, then using StructreMap again inside adapter enable switching between DataPortal and mock DomainDAO, here is what I have tried:</p>
<ol>
<li>Create DomainDAO and IDomainDAO,
<pre class="brush: csharp;">
public class DomainDAO&lt;BO&gt; : IDomainDAO&lt;BO&gt;
{
public BO Fetch(object criteria)
{
return DataPortal.Fetch&lt;BO&gt;(criteria);
}

public BO Create()
{
return DataPortal.Create&lt;BO&gt;();
}

public BO Update(BO bo)
{
return DataPortal.Update&lt;BO&gt;(bo);
}

public void Delete(object criteria)
{
DataPortal.Delete&lt;BO&gt;(criteria);
}
}

public interface IDomainDAO&lt;T&gt;
{
T Fetch(object criteria);
T Create();
T Update(T bo);
void Delete(object criteria);
}
</pre>
</li>
<li>Create DAOManager to Get DomainDAO:
<pre class="brush: csharp;">
public static class DAOManager
{
public static IDomainDAO&lt;BO&gt; DomainDAO&lt;BO&gt;()
{
return ObjectFactory.GetInstance&lt;IDomainDAO&lt;BO&gt;&gt;();
}
}
</pre>
</li>
<li>Change classic factory method in BO from DataPortal to this new DAOManager.
<pre class="brush: csharp;">
public static OrganizationBO GetOrganizationBO(int stakeholderId)
{
return DAOManager.DomainDAO&lt;OrganizationBO&gt;().Fetch(new SingleCriteria&lt;OrganizationBO, int&gt;(stakeholderId));
//            return DataPortal.Fetch&lt;OrganizationBO&gt;(new SingleCriteria&lt;OrganizationBO, int&gt;(stakeholderId));
}
</pre>
</li>
<li>The presenter testing code can be changed to:
<pre class="brush: csharp;">

[SetUp]
public void SetUp()
{
_mockService = MockRepository.GenerateMock&lt;IDomainDAO&lt;OrganizationBO&gt;&gt;();
ObjectFactory.Inject&lt;IDomainDAO&lt;OrganizationBO&gt;&gt;(_mockService);
}

[TearDown]
public void TearDown()
{
ObjectFactory.ResetDefaults();
}

[TestFixture]
public class When_initializing_view : EstablishContext
{
        [Test]
        public void should_call_view_setter_if_id_exists()
        {
            // Arrange
            // We don't need to set return value here.
            _mockService.Expect(x =&gt; x.Fetch(new SingleCriteria&lt;OrganizationBO, int&gt;(68190)));

            _mockView = MockRepository.GenerateMock&lt;IEditDetailsView&lt;OrganizationBO&gt;&gt;();

            _presenter = new EditDetailsPresenter&lt;OrganizationBO&gt;(_mockView);

            // Action
            _presenter.InitViewFor(68190);

            // Assert
            _mockView.AssertWasCalled(x =&gt; x.CurrentBO = null,
                options =&gt; options.IgnoreArguments() );
        }

        [Test]
        public void should_set_error_msg_in_view_if_id_not_exists()
        {
            // Arrange
            Exception ex = new Exception(&quot;Data Not Found&quot;, new DataNotFoundException());
            _mockService.Expect(x =&gt; x.Fetch(new SingleCriteria&lt;OrganizationBO, int&gt;(1)))
                .IgnoreArguments()
                .Throw(new DataPortalException(&quot;DataPortal.Fetch failed.&quot;,
                    ex,
                    null)); // See, we don't have to mock BO here, unless you try to read BO through exception in UI.

            _mockView = MockRepository.GenerateMock&lt;IEditDetailsView&lt;OrganizationBO&gt;&gt;();

            _presenter = new EditDetailsPresenter&lt;OrganizationBO&gt;(_mockView);

            // Action
            _presenter.InitViewFor(1);

            // Assert
            _mockView.AssertWasCalled(x =&gt; x.ShowError(null),
                options =&gt; options.IgnoreArguments() );
        }
</pre>
</li>
</ol>
<p>Fetch can be done this way, but I can&#8217;t mock Save() because it&#8217;s deep in Csla, unless I can override BusinessBase.Save() which is another mission impossible (too many internal classes involved). To make Csla TDD friendly, let ask for TypeMock to save us out.</p>
<pre class="brush: csharp;">
 [TestFixture]
    public class When_view_firing_save_event : EstablishContext
    {
        [Test]
        public void should_set_success_msg_and_set_new_BO_in_view_if_save_new_bo_succeed()
        {
            // Arrange
            OrganizationBO orgBo = DataPortal.Create&lt;OrganizationBO&gt;();
            orgBo.Name = &quot;test Org&quot;;
            Assert.That(orgBo.IsValid, orgBo.GetValidationMessage());

            _mockView = MockRepository.GenerateMock&lt;IEditDetailsView&lt;OrganizationBO&gt;&gt;();
            _mockView.Stub(x =&gt; x.CurrentBO).Return(orgBo).Repeat.Any();

            _presenter = new EditDetailsPresenter&lt;OrganizationBO&gt;(_mockView);

            // This won't work, because BusinessBase.Save() is tightly coupled to DataPortal.
            //_mockService.Expect(x =&gt; x.Update(orgBo)).IgnoreArguments();

            // Use TypeMock to mock DataPortal.Update() inside BusinessBase.Save()
            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                  // CAUTION: ALL calls here are mocked!!!
                  recorder.DefaultBehavior.IgnoreArguments();
                  recorder.ExpectAndReturn(DataPortal.Update(orgBo), orgBo);
            }

            // Action
            _mockView.Raise(x =&gt; x.RequestSave += null, this, EventArgs.Empty);

            // Assert
            _mockView.AssertWasCalled(x =&gt; x.CurrentBO = null,
                                      options =&gt; options.IgnoreArguments());

            _mockView.AssertWasCalled(x =&gt; x.ShowMessage(null),
                                      options =&gt; options.IgnoreArguments());

    }
</pre>
<p>We can remove DomainDAO then if using TypeMock to mock DataPortal.</p>
<p>The <a href="http://www.lhotka.net/weblog/CSLANETObjectFactoryAttribute.aspx">new ObjectFactory in CSLA 3.6</a> seems can make this mock easier, looks like your own ObjectFactory is not static class anymore, different than DataPortal. By creating your own IDataPortal or IObjectFactory, <a href="http://code.google.com/p/cslaptrackerfactory/source/browse/trunk/ProjectTrackerHybrid.Core/Framework/Factories/IBusinessBaseServerFactory.cs">as Ryan did</a>,  mocking those service layer objects should become possible. Someday I will look into this CSLA.ObjectFactory thing if we aren&#8217;t going to TypeMock. Rocky&#8217;s statement indicates this will be a lot of work:</p>
<blockquote><p>It is <em>very important</em> to realize that when using this factory model, the data portal does virtually nothing for you. It doesn&#8217;t automatically call MarkOld(), MarkNew() or MarkAsChild(). You assume <em>total responsibility</em> for creating and initializing the business object graph, and for setting the state of all objects in the graph.</p></blockquote>
<p>But it seems <a href="http://cslaptrackerfactory.googlecode.com/">Ryan&#8217;s ObjectFactroy sample code</a> already finished most of them. One thing doesn&#8217;t fit our situation is, we need IRepository&lt;&gt; changed to IDomainObjectRepository in Factory.</p>
<pre class="brush: csharp;">

        private readonly IRepository&lt;T&gt; _repository;
        public BusinessBaseServerFactory(IRepository&lt;T&gt; repository)
        {
            _repository = repository;
        }
</pre>
<p>So far, I think unless CSLA.ObjectFactory can provide an optional attribute something like &#8220;RepositoryType&#8221;, I have to create One ObjectFacotry per BO. Our libaray will become more messier.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/326/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=326&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2008/11/28/should-always-ignoreargument-when-assertwascalled/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
		<item>
		<title>Seperate concern between parent and child</title>
		<link>http://maonet.wordpress.com/2008/11/21/seperate-concern-between-parent-and-child/</link>
		<comments>http://maonet.wordpress.com/2008/11/21/seperate-concern-between-parent-and-child/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 06:39:09 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[CSLA]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=315</guid>
		<description><![CDATA[Do we need to separate concern between parent object and its child? Say we have a stakeholder BO, which can have multiple email BOs, (an email BO collection). Then where should we place those specs/unit-tests for email BO?
Because emailBO is a child BO, the normal way to save it should be only through stakeholderBO.Save(). It&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=315&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Do we need to separate concern between parent object and its child? Say we have a stakeholder BO, which can have multiple email BOs, (an email BO collection). Then where should we place those specs/unit-tests for email BO?</p>
<p>Because emailBO is a child BO, the normal way to save it should be only through stakeholderBO.Save(). It&#8217;s possible that stakeholderBO might still be work-in-progress, or having problem caused by other childBO, e.g., telephoneBO. Or more likely, it&#8217;s not finish yet. Can we still work on EmailBO without worry too much about it&#8217;s parent &#8211; StakeholderBO?</p>
<p>So seperate concern is necessary. We need an interface to implement design-by-contract.</p>
<p>Create an IStakeholder interface, mock it in emailBO unit-test. (Thanks to Rhino, we don&#8217;t need worry about data portal any more. ) But we need to explicitly call SetParent() in emailBOCollection to simulate the LoadProperty behavior in stakeholderBO.</p>
<p>The test code:</p>
<pre class="brush: csharp;">

            // Arrange
            var emailRepository = MockRepository.GenerateMock&lt;IEmailRepository&gt;();
            ObjectFactory.Inject&lt;IEmailRepository&gt;(emailRepository);

            EmailDTO OneValidTestDTO = new EmailDTO()
                                           {
                                               Address = &quot;2@d.c&quot;, EmailRole = &quot;Home&quot;,
                                               StakeholderId = 123, StakeholderEmailId = 456
                                           };

            emailRepository.Expect(x =&gt; x.Insert(null)).IgnoreArguments().Return(OneValidTestDTO);
            // or play the new inline constraints syntax
            emailRepository.Expect(x =&gt; x.Insert(Arg&lt;EmailDTO&gt;.Is.Anything)).Return(OneValidTestDTO); 

            IStakeholder mockStakeholderBO = MockRepository.GenerateMock&lt;IStakeholder&gt;();  

            // Action
            EmailBOCollection emails = EmailBOCollection.NewEmailBOCollection();

            // SetStakeholder is created in EmailBOCollection to call private SetParent through reflection.
            // This is optional because the second parm in DataPortal.UpdateChild() will be passed
            // to child_XYZ() as the parameter which is the real parent.
            // emails.SetStakeholder(mockStakeholderBO);   // IStakeholder should extend csla.IParent.

            var newEmail = emails.AddNew();
            // Make this new EmailBO valid.
            newEmail.Address = &quot;1@dc.com&quot;;
            newEmail.EmailRole = &quot;Home&quot;;

            Assert.That(emails[0].BrokenRulesCollection, Is.Empty, emails[0].BrokenRulesCollection.ToString());

            // this is to simulate the parent.Save() in the real world,
            DataPortal.UpdateChild(emails, mockStakeholderBO);
            // We don't want and can't call stakeholder.Save() here

            // Assert
            Assert.That(emails[0].StakeholderEmailId == OneValidTestDTO.StakeholderEmailId);
            Assert.That(emails[0].StakeholderId == OneValidTestDTO.StakeholderId);  

            // Reset to default
            ObjectFactory.ResetDefaults();
</pre>
<p>Unfortunately, SetParent(IParent) is a private method in IEditableObject and IEditableCollection. I had to create a public wrapper in my base class.</p>
<pre class="brush: csharp;">

        public void SetStakeholder(IParent parent)
        {
            object[] parm = new object[] { parent };

            var method = this.GetType().GetMethod(&quot;Csla.Core.IEditableCollection.SetParent&quot;, BindingFlags.Instance | BindingFlags.NonPublic);

            method.Invoke(this, parm);
        }
</pre>
<p>But, later I figured out it&#8217;s not necessary, only if I am doing some parent-related validation in emailBO, say, an Organization type stakeholder can not have home email role.</p>
<p>Dataportal.Update() method is key to simulate parent.Save(), this old (3.0) syntax works great in my mock/TDD solution to CSLA.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/315/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/315/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/315/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/315/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/315/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/315/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/315/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/315/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/315/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/315/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=315&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2008/11/21/seperate-concern-between-parent-and-child/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
		<item>
		<title>Aptana studio</title>
		<link>http://maonet.wordpress.com/2008/10/06/aptana-studio/</link>
		<comments>http://maonet.wordpress.com/2008/10/06/aptana-studio/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 02:51:18 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=245</guid>
		<description><![CDATA[I wish I had used Aptana studio (Radrails) 2 years ago, so my ruby coding experience could be more fun. This IDE is very close to Visual studio + Resharper for CSharp coding. The intelligence looks a little bit werid, might because there are too many method in ruby&#8217;s object type.
What else I like very [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=245&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I wish I had used Aptana studio (Radrails) 2 years ago, so my ruby coding experience could be more fun. This IDE is very close to Visual studio + Resharper for CSharp coding. The intelligence looks a little bit werid, might because there are too many method in ruby&#8217;s object type.</p>
<p>What else I like very much includes:</p>
<ol>
<li>Unite-test view, exactly same as Junit in eclipse. Once I run one of the test case, it seems no way back to the full list. Unless I re-run the class level test or select the latest test I had run.</li>
<li>Outline view, can even launch unit-test directly. But for the method level unit-test I had to hard type in class name and method name, why no smart drop down list available?</li>
<li>Ruby core api help window, not that help than MS one, but better than nothing.</li>
<li>Code compete, for method, if block, etc. Same as Resharper does for CSharp.</li>
<li>Open declaration, very useful, F3, just like Ctrl+B in R#. But it seems not very stable, I kept getting error &#8220;select text not in a ruby &#8230;&#8221;, switch to eclipse, work for a while, then got the same problem again. For some reason, my home pc just work fine. Need to figure this out someday.</li>
<li>Looks like this aptana studio can also do php and python coding, even ajax javascript, WOW!</li>
</ol>
<p><a href="http://maonet.files.wordpress.com/2008/10/aptana-studio_strange_unit_test_window1.jpg"><img class="alignnone size-full wp-image-247" title="aptana-studio_strange_unit_test_window1" src="http://maonet.files.wordpress.com/2008/10/aptana-studio_strange_unit_test_window1.jpg?w=570&#038;h=484" alt="" width="570" height="484" /></a></p>
<p>The annoying part for Ruby coding is environment config. For some reason my libxml didn&#8217;t work on my windows env, figured out almost whole day, then it magiclly starts to word. Still don&#8217;t know why. Probably I should copy those lib2xml.dll into windows system folder, and then copy the xml folder under $ruby\lib\ruby\site_ruby\1.8. But I was too tired of copying those folders, don&#8217;t know what one did the work. Anyway, it works now, PFM.</p>
<p>Those files are needed for libxml running on windows.</p>
<ol>
<li>ruby\lib\ruby\site_ruby\1.8\xml\libxml.rb</li>
<li>ruby\lib\ruby\site_ruby\1.8\i386-msvcrt\libxml_so.so</li>
<li>ruby\lib\ruby\site_ruby\1.8\libxml.rb</li>
</ol>
<p>I also got a problem on installing log4r, tried gem install, update_rubygems, didn&#8217;t work, always got a loaderror. I tried &#8220;ruby -e &#8216;require &#8220;log4r&#8221;&#8216;, the log4r already shonw in the list, but why still loaderror?</p>
<p>I ended up with download the tgz file, and run the ruby install.rb, it seems this process is doing lots of file links afterwards. So, it works. A new folder log4r was created under &#8220;ruby\lib\ruby\site_ruby\1.8\&#8221;, different than gem install.</p>
<p>Look into log4r, 5 methods in it, debug, info, warn, error and fatal, extact same as log4net. I remeber somewhere in my app I use a trace, it seems not a standard one.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/245/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=245&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2008/10/06/aptana-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>

		<media:content url="http://maonet.files.wordpress.com/2008/10/aptana-studio_strange_unit_test_window1.jpg" medium="image">
			<media:title type="html">aptana-studio_strange_unit_test_window1</media:title>
		</media:content>
	</item>
		<item>
		<title>Repository pattern in CSLA</title>
		<link>http://maonet.wordpress.com/2008/10/06/repository-pattern-in-csla/</link>
		<comments>http://maonet.wordpress.com/2008/10/06/repository-pattern-in-csla/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 15:51:53 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[CSLA]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[StructureMap]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=240</guid>
		<description><![CDATA[

We use Repository Pattern inside our CSLA BO to extract data access code into a separate class – repository object,  because we use interface IRepository to loose couple BO and concrete Repository object and implement “design by contract”, so BO doesn’t care which technology repository is using, either using ADO.net or Linq to SQL, or [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=240&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://maonet.files.wordpress.com/2008/10/csla_repository.jpg"><img class="alignnone size-full wp-image-241" title="csla_repository" src="http://maonet.files.wordpress.com/2008/10/csla_repository.jpg?w=604&#038;h=471" alt="" width="604" height="471" /></a></p>
<p><!--[if gte mso 9]&gt;  Normal 0   false false false         MicrosoftInternetExplorer4  &lt;![endif]--><!--[if gte mso 9]&gt;   &lt;![endif]--></p>
<p>We use Repository Pattern inside our CSLA BO to extract data access code into a separate class – repository object,  because we use interface IRepository to loose couple BO and concrete Repository object and implement “design by contract”, so BO doesn’t care which technology repository is using, either using ADO.net or Linq to SQL, or NHinbernate or Entity Framework .</p>
<p class="MsoNormal">The benefits of using this model include:</p>
<ul style="margin-top:0;" type="disc">
<li class="MsoNormal">Loose      coupling between BL and DAL</li>
<li class="MsoNormal">Easy      to switch to different Data Access technology</li>
<li class="MsoNormal">Central      place to control and switch IOC container</li>
</ul>
<p>Updated at Feb. 09, 2009:<br />
Found <a href="http://debasishg.blogspot.com/2007/02/domain-driven-design-use-orm-backed.html">this post</a> about the difference between DAO and Repository pattern. Yes, my model is more similar to DAO, because I was following one Repo/DAO per table rule. In fact, I&#8217;m on the progress of switching to the new Csla.ObjectFactory which is a real repository class, or, at lease, can be a repository wrapper, as Ryan did in his example.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/240/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=240&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2008/10/06/repository-pattern-in-csla/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>

		<media:content url="http://maonet.files.wordpress.com/2008/10/csla_repository.jpg" medium="image">
			<media:title type="html">csla_repository</media:title>
		</media:content>
	</item>
		<item>
		<title>Rollback db unit test</title>
		<link>http://maonet.wordpress.com/2008/09/17/rollback-db-unit-test/</link>
		<comments>http://maonet.wordpress.com/2008/09/17/rollback-db-unit-test/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 19:56:45 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[test]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[RollBack]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=224</guid>
		<description><![CDATA[I couldn&#8217;t make Roy&#8217;s XtUnit working in my test cases. Tried to switch to MbUnit, but Resharper 4 still doesn&#8217;t support it yet. Later, I found there are some posts (here, and here) pointing out the very easy solution for this: System.Transactions.TransactionScope.
I then adopt this trick, created my own DBTestFixtureInTheRollBackTransactionclass.
It works, and like the author [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=224&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I couldn&#8217;t make <a href="http://weblogs.asp.net/rosherove/archive/2004/07/12/180189.aspx">Roy&#8217;s XtUnit</a> working in my test cases. Tried to switch to MbUnit, but Resharper 4 still doesn&#8217;t support it yet. Later, I found there are some posts (<a href="http://yellowduckguy.spaces.live.com/Blog/cns!DA380C13569E8907!128.entry">here</a>, and <a href="http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!155.entry">here</a>) pointing out the very easy solution for this: System.Transactions.TransactionScope.</p>
<p>I then adopt this trick, created my own DBTestFixtureInTheRollBackTransactionclass.</p>
<p>It works, and like the author said, <span>embarrassingly simple!</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/maonet.wordpress.com/224/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/maonet.wordpress.com/224/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/224/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=224&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2008/09/17/rollback-db-unit-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
		<item>
		<title>jQuery releases Javascript pain</title>
		<link>http://maonet.wordpress.com/2008/07/30/jquery-releases-javascript-pain/</link>
		<comments>http://maonet.wordpress.com/2008/07/30/jquery-releases-javascript-pain/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 19:18:15 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=164</guid>
		<description><![CDATA[I have a html page to display xml files from the same server. The reasons I didn&#8217;t use the server side script includes

ruby needs rails, but I don&#8217;t want to create an application for this single page. I tried to run ruby as cgi, no success.
maggiePie can make php eaiser, but I think it&#8217;s still [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=164&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have a html page to display xml files from the same server. The reasons I didn&#8217;t use the server side script includes</p>
<ol>
<li>ruby needs rails, but I don&#8217;t want to create an application for this single page. I tried to run ruby as cgi, no success.</li>
<li>maggiePie can make php eaiser, but I think it&#8217;s still kind of overkill for this simple use.</li>
</ol>
<p>Then I turned to client-side javascript. At first I use this function to load xml file:</p>
<blockquote><p>function loadXMLtoDIV(file, div_name) {</p>
<p>var xmlDoc = null;</p>
<p>var moz = (typeof document.implementation != &#8216;undefined&#8217;)<br />
&amp;&amp; (typeof document.implementation.createDocument != &#8216;undefined&#8217;);<br />
var ie = (typeof window.ActiveXObject != &#8216;undefined&#8217;);</p>
<p>if (moz) {</p>
<p>xmlDoc = document.implementation.createDocument(&#8220;&#8221;, &#8220;&#8221;, null);<br />
xmlDoc.load(file);<br />
xmlDoc.onload = function() { readXML(xmlDoc, div_name); };</p>
<p>} else if (ie) {</p>
<p>xmlDoc = new ActiveXObject(&#8220;Microsoft.XMLDOM&#8221;);<br />
xmlDoc.async = false;<br />
while(xmlDoc.readyState != 4) {};<br />
xmlDoc.load(file);<br />
readXML(xmlDoc, div_name);<br />
}</p>
<p>}</p></blockquote>
<p>It worked very well, and I like it until I tried use jQuery:</p>
<blockquote><p>function XmlOnLoad( xmlData, divId ){</p>
<p>// Get the first 2 items<br />
var jItems = jQuery(&#8216;item:lt(2)&#8217;, xmlData);</p>
<p>var jDiv = $( divId );</p>
<p>// reset.<br />
jDiv.html(&#8221;);</p>
<p>jItems.each(<br />
function( ){<br />
jDiv.append( $(this).find(&#8216;pubDate&#8217;).text() + &#8216; : &#8216; +$(this).find(&#8216;title&#8217;).eq(0).text() +&#8217;&lt;br/&gt;&#8217;);<br />
}<br />
);<br />
}<br />
function GetXMLData(file, divId){<br />
$.get(file,{},<br />
function(xmlData, status) {<br />
XmlOnLoad(xmlData, divId);<br />
} );</p>
<p>}</p></blockquote>
<p>And another benefit from jQuery is, I can move those &#8216;behavior&#8217; from the presentation part. This jQuery &#8216;onload&#8217; function is to add an universal click event to all the itemlist class div. By doing this my html elements look much neater.</p>
<blockquote><p>$(function(){</p>
<p>$(&#8220;div.itemlist&#8221;).each(</p>
<p>function(n){<br />
var current = this;</p>
<p>$(&#8220;&lt;a href=&#8221;&gt;See latest items &#8230; &lt;/a&gt;&#8221;).click(  function(event){<br />
GetXMLData(   &#8220;#&#8221;+current.id); return false;}  ).appendTo($(this));<br />
}<br />
);</p>
<p>})</p></blockquote>
<p>One thing I still don&#8217;t understand, if I tried to load too many xml file into the page elements, some xml files just missed. jQuery still doesn&#8217;t fix this problem. But coverting from loading to ajax using jQuery is so easy, so I didn&#8217;t spent too much time on it at all.</p>
<p>For those TDD fans, you want to look in this <a href="http://www.lostechies.com/blogs/chad_myers/archive/2008/08/28/getting-started-with-jquery-qunit-for-client-side-javascript-testing.aspx">QUnit intro</a>.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/maonet.wordpress.com/164/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/maonet.wordpress.com/164/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/164/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=164&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2008/07/30/jquery-releases-javascript-pain/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
		<item>
		<title>Test Authorizatoin Rules in CSLA</title>
		<link>http://maonet.wordpress.com/2008/05/09/test-authorizatoin-rules-in-csla/</link>
		<comments>http://maonet.wordpress.com/2008/05/09/test-authorizatoin-rules-in-csla/#comments</comments>
		<pubDate>Sat, 10 May 2008 06:08:40 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[CSLA]]></category>
		<category><![CDATA[MoQ]]></category>
		<category><![CDATA[Rhino]]></category>
		<category><![CDATA[TypeMock]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=116</guid>
		<description><![CDATA[To test CSLA BO&#8217;s authorization settings, I have to mock the IPrincipal.IsInRole method, RhinoMock example like this:

        [Test]
        [ExpectedException(&#34;System.Security.SecurityException&#34;)]
        public void CanHideForUnAuthorizedUser()
        {
     [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=116&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>To test CSLA BO&#8217;s authorization settings, I have to mock the IPrincipal.IsInRole method, RhinoMock example like this:</p>
<pre class="brush: csharp;">
        [Test]
        [ExpectedException(&quot;System.Security.SecurityException&quot;)]
        public void CanHideForUnAuthorizedUser()
        {
            MockRepository mocks = new MockRepository();
            IPrincipal mockPrincipal = (IPrincipal)mocks.CreateMock&lt;IPrincipal&gt;();
            Csla.ApplicationContext.User = mockPrincipal;

            using (mocks.Record())
            {

                Expect.Call(mockPrincipal.IsInRole(&quot;user&quot;)).Return(false);

            }// Replay and validate interaction
            Order obj = null;
            using (mocks.Playback())
            {
                obj = Order.GetOrder(new Guid(&quot;c512e473-19fd-401c-80f6-055cf239e461&quot;));

            }// Post-interaction assertions
            Assert.IsNull(obj);

        }

         [Test]
        public void CanGetOrderUsingTypeMock()
        {

            // Setup Stud Data to be returned from mocked repository.
            // This code could be moved into record expectation block
            // but we assume everything inside that block is mocked.
            // to reduce confusion, just leave it here.
            // In fact , this mode is faster comparing the other one.
            OrderDTO stubOrderDTO = new OrderDTO();
            stubOrderDTO._OrderNumber = &quot;12345&quot;;

            // Everything inside recorder block will be mocked.
            // expect the settng return value line: recorder.Return()
            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                // Don't have to mock the IPricipal object &quot;User&quot;
                // Here TypeMock is too powerful. no need to think.
                Csla.ApplicationContext.User.IsInRole(&quot;user&quot;);
                recorder.Return(true);

                OrderRepository mockRepository = new OrderRepository();
                mockRepository.GetById(Guid.Empty);
                recorder.Return(stubOrderDTO);
            }

            Order p = Order.GetOrder(Guid.Empty);
            Assert.IsNotNull(p);
            Assert.AreEqual(&quot;12345&quot;, p.OrderNumber);
        }
</pre>
<p>After using typemock for a while, I suddenly tired of Rhino&#8217;s record-play syntax, looking into <a href="http://code.google.com/p/moq/wiki/QuickStart">MoQ&#8217;s doc</a>, it&#8217;s very similar to TypeMock, but it&#8217;s LinQ syntax (var and Lamba) are only available on 3.5 framework.</p>
<p>If using MoQ, the Rhino example will shorten to:</p>
<pre class="brush: csharp;">

       [Test]
        [ExpectedException(&quot;System.Security.SecurityException&quot;)]
        public void CanHideForUnAuthorizedUser()
        {
            var mock = new Mock&lt;IPrincipal&gt;();
            mock.Expect(x =&gt; x.IsInRole(&quot;user&quot;)).Returns(true);
            Csla.ApplicationContext.User = mock;

            var obj = Order.GetOrder(new Guid(&quot;c512e473-19fd-401c-80f6-055cf239e461&quot;));
        }
</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/maonet.wordpress.com/116/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/maonet.wordpress.com/116/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/116/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=116&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2008/05/09/test-authorizatoin-rules-in-csla/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
	</channel>
</rss>