Programming, technology, and CRM – from a Belgian programmer exiled to Missouri
  • rss
  • Home
  • Soft Gallery
    • autosvnbackup.sh
    • VBScript Snippets
  • Contact Me
  • Welcome

Unit Testing SLX – 7.2.2 Update

Nicolas Galler | March 11, 2008

A 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.

Categories
Saleslogix
Tags
Favorites
Comments rss
Comments rss
Trackback
Trackback

« DST Strikes Again Sticking it to SLXWEBMM.DLL »

One Response to “Unit Testing SLX – 7.2.2 Update”

  1. Chivinou [ʃivinu] » On the Coolness of unit-testing Saleslogix says:
    March 20, 2008 at 3:23 pm

    [...] 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 [...]

Leave a Reply

Click here to cancel reply.

Categories

  • Dojo (1)
  • Experiments (4)
  • Force.com (2)
  • Interesting (1)
  • Javascript (3)
  • MSCRM (1)
  • Programming (63)
  • Rant (3)
  • Saleslogix (41)
  • Tricks (8)
  • Uncategorized (32)

Post History

  • 2011
    • January (3)
    • February (2)
    • March (1)
  • 2010
    • January (3)
    • March (3)
    • April (2)
    • August (2)
    • October (4)
    • November (1)
    • December (2)
  • 2009
    • March (2)
    • April (1)
    • May (3)
    • June (3)
    • July (1)
    • September (3)
    • October (2)
    • December (5)
  • 2008
    • January (9)
    • February (4)
    • March (9)
    • April (1)
    • May (5)
    • June (8)
    • July (1)
    • August (2)
    • September (1)
    • November (1)
    • December (3)
  • 2007
    • January (3)
    • February (7)
    • March (1)
    • April (3)
    • May (6)
    • June (2)
    • July (1)
    • August (2)
    • September (5)
    • October (3)
    • November (5)
    • December (4)
  • 2006
    • January (2)
    • September (1)
    • November (3)
    • December (4)
  • 2005
    • April (1)

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox