Sunday, March 7, 2010

AxUnit Unit Testing framework

I'm doing unit testing in my daily work and welcome the SysTest unit testing framework that was provided with Dynamics ax 4.0.

It works well, but I like the assertion syntax found in NUnit better, so I decided to implement my own extension to the SysTest framework.

Now you can write assertions like this:

    assert.that(actual, is.equalTo(expected));
    assert.that(0.3333, is.equalTo(0.33).within(2).decimals());
    assert.that(actual != null);

I think the syntax makes the test more readable.

You can download the framework at Codeplex

Wednesday, July 29, 2009

LINQ inside X++ ?

LINQ (Language INtegrated Query) in C# is simply a work of art. 
It's a good example of "Less is more".
With a few lines of code you can express an otherwise complex operation.


In X++ something similar can be done with queries in sql tables, but not in an Array og List object.
As a hobby project, I created a small Domain Specific Language called "AxLINQ", that can make this possible.


Example (C#)
List<string> names = new List<string>();

var query = from name in names
order by name
select "Name: " + name;

Example (X++)
str name;
Array     names = new Array(Types::String);
AxLINQ_IQueryable axQuery = xfrom(name).in(names)
.orderBy(name)
.select("Name: " + name);

The axQuery object can give you an enumerator, to enumerate the ordered list of names.


AxLINQ implements the standard operators of SELECT, WHERE, ORDER BY, GROUP BY, JOIN and several other functions like DISTINCT, ANY, COUNT, MAX, MIN etc.

Download and try for yourself

If you wish to try it out, you can download the framework at http://axlinq.codeplex.com