NUnit tests give different results for local vs. remote data portals

NUnit tests give different results for local vs. remote data portals

Old forum URL: forums.lhotka.net/forums/t/3841.aspx


CampbellCM posted on Friday, November 02, 2007

I'm having a problem where certain NUnit tests are succeeding when a local data portal is used and failing when a remote data portal is used.  The tests that are failing have a trailing // X and are at the bottom of the snippet below:

Guid guid = new Guid("CEC71B06-668D-4ae5-986A-F89919FC8AF7");

snippetType = SnippetType.NewSnippetType();
Assert.AreEqual(Guid.Empty, snippetType.ID);
Assert.AreEqual(string.Empty, snippetType.Description);

snippetType.ID = guid;
snippetType.Description = "abc";

Assert.AreEqual(true, snippetType.IsDirty);
Assert.AreEqual(true, snippetType.IsNew);
Assert.AreEqual(true, snippetType.IsSavable);
Assert.AreEqual(true, snippetType.IsValid);

snippetType.Save();

Assert.AreEqual(false, snippetType.IsDirty);    // X
Assert.AreEqual(false, snippetType.IsNew);      // X
Assert.AreEqual(false, snippetType.IsSavable);  // X
Assert.AreEqual(false, snippetType.IsDeleted);

I reviewed the Csla tests and the assumptions would appear to be correct in that after the initial save (which would be an insert) IsDirty, IsNew, and IsSavable should all be false.  When these test are run using a remote data portal the results are just the opposite (all true).  I know this can't be a bug so the question is: What am I doing wrong?

I'm using version 2.1.1 of Csla.

JoeFallon1 replied on Friday, November 02, 2007

This is wrong:

snippetType.Save();

You have to remember that a new BO is returned from the DataPortal so you have to update your reference. When the DP is local, your code works because the BO is updated in memory and the reference is still valid.

When remote, your reference is the OLD one - not the new one from the DP.

Try something like:

snippetType = snippetType.Save();

You should also clone your BO before hand - there is a bunch of stuff about this in the book and the eBook. I think Rocky is going to make Autocloning the default in the next version to point out bugs like this.

Joe

 

CampbellCM replied on Saturday, November 03, 2007

That was it alright.  Thanks Joe.

Copyright (c) Marimer LLC