This project is read-only.


The type of test framework you use dictates how you use TripleA with it. It supports regular "unit test" methods where you arrange, act, assert within the test method and Bdd style frameworks (like StoryQ, MSpec etc) that provide their own sequence of arrange, act, assert steps (Given/When/Then, Because/Of/It).

Bdd Style Frameworks

If you use a BDD style framework like StoryQ or MSpec then you should follow the instructions here.

Plain Old Unit Tests

Completely standard "unit test" style approach - in this case you need to create a "Session", set it up and then execute it. Here TripleA brings its own pipeline (sequence) and executes the steps you have configured it for.

Scenario - you have just done a deployment that should have run a script that modified the permissions on a Sql Server database; a new custom role was created and a specific user should have been made a member of this role.

Here we create a "Session" and call the "Setup" method - this gives us access to the "config" object where we use the fluent interface to access our extension methods; we add the steps to assert the deployment script has done its job correctly. We then "Execute" the session to produce a "result" - this object contains a master status property called "Success" that can be asserted against - if any of the steps failed then this will be "false"; also provided it is detailed information about the result of each step including the duration and if it did fail, the exception that it raised. Finally these step results are "Dumped" - output to Trace/Console so you can see the information in the test output.

// NUnit test
public void DbPermissionsAreSweeeeet()
    var session = Session.Setup<TestContext>(
        config =>
             // note "DbCnnStringId" is the connection string id in app.config
             config.SqlServerHasLogin("DbCnnStringId", "DbUser")
                 .SqlServerDatabaseHasUser("DbCnnStringId", "MyDb", "DbUser")
                 .UserIsInSqlServerDatabaseRole("DbCnnStringId", "MyDb", "DbUser", "db_datareader", "db_datawriter", "my_custom_role");

        var result = session.Execute(new TestContext());

        // using FluentAsserts nuget package
...and these are example outputs as written by the "Dump()" method (it's virtual so you can override it to do whatever you want - default is Console.WriteLine()).
Result: True
Duration: 1080ms
Step Results:
    [0 'SqlServer2008AssertLoginStep`1'] => Ok in 359.0643ms
    [1 'SqlServer2008AssertUserStep`1'] => Ok in 343.6447ms
    [2 'SqlServer2008AssertRolesStep`1'] => Ok in 377.4569ms failed...
Result: False
Duration: 1263ms
Step Results:
    [0 'SqlServer2008AssertLoginStep`1'] => Ok in 341.5693ms
    [1 'SqlServer2008AssertUserStep`1'] => Ok in 447.2431ms
    [2 'SqlServer2008AssertRolesStep`1'] => Failed in 474.044ms; Details => User 'DbUser' is not in role(s): my_custom_role

Last edited Aug 15, 2012 at 7:56 PM by jimbobdog, version 6


No comments yet.