Unit Testing SLX – 7.2.2 Update
Nicolas Galler | March 11, 2008A follow up to my post, Unit Testing SLX. The post was written on Saleslogix 7.2.1 and there have been several very, very good improvements in the last service pack. So much in fact that unit testing and external access might actually be viable. Most importantly, transactions are now well supported, and inserts actually work. I have not tried on a production application yet but it should actually now be possible to use the SLX 7.2 libraries for external database access from our own components (eg integration services, external web services, etc).
The setup is the same as before, so please read the original posts for details on that. Here is an example test using a transaction:
using (IDBConnectionWrapper con = new DBConnectionWrapper()) { String histId = (String)con.GetField("top 1 historyid", "history", "1=1 order by newid()"); IHistory history; using (TransactionScope tx = new TransactionScope()) { history = EntityFactory.GetById<IHistory>(histId); history.UserDef1 = new Random().Next().ToString(); history.Save(); using (ISession sess = new SessionScopeWrapper(false)) { IDbCommand cmd = sess.Connection.CreateCommand(); cmd.CommandText = "SELECT USERDEF1 FROM HISTORY WHERE HISTORYID='" + histId + "'"; sess.Transaction.Enlist(cmd); Assert.AreEqual(history.UserDef1, (String)cmd.ExecuteScalar()); cmd.Dispose(); } tx.VoteRollBack(); } // make sure the transaction rolled back Assert.AreNotEqual(history.UserDef1, (String)con.GetField("USERDEF1", "HISTORY", "HISTORYID=?", histId)); }
In order to setup the test harness I have created a NUnit SetupFixture class. It has a Setup method which runs before every test of the project (actually before each test within the same namespace as the setup fixture, which works well for this case):
/// <summary> /// A setup fixture helper. /// </summary> [SetUpFixture] public class TestSetupBase { /// <summary> /// Setup helper (this does the setup with the default files) /// </summary> [SetUp] public virtual void Setup() { // setup using the default file this.Setup("dynamicMethods.xml"); } public virtual void Setup(String methodsFile) { // ... } /// <summary> /// Teardown helper. /// </summary> [TearDown] public virtual void TearDown() { // ... } }
If anyone is interested feel free to download it. You’ll have to adjust the references to point to the various Saleslogix assemblies, log4net, NUnit, and NHibernate. To reuse the library in a separate project I can create a TestSetup class in the same namespace as my tests, inheriting from the one in TestSupport (and optionally passing a different path to the dynamicMethods.xml file, since this should be the one from the site deployed by AA) and making sure to link to the Sage.Entity.Interface and Sage.SalesLogix.Entities from the deployed web site (so that they contain the custom entities). Also make sure that the app.config file defines a connection string named “ConnectionString”.
Next step – test the group builder side. This should be pretty interesting.






[...] unit testing. You will want to check this post on how to set your environment up for unit testing: Unit Testing SLX – 7.2.2 Update. If you need any help send me an email or a [...]