Examples

Here are a few example of TripleA in action...

Example 1 - Verifying deployment of Sql Server permissions...

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.
[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());
        result.Dump();

        // using FluentAsserts nuget package
        result.Success.Should().BeTrue();
 }
...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


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 9, 2012 at 10:34 AM by jimbobdog, version 3

Comments

No comments yet.