davezych / shience

A .NET port(ish) of Github's Scientist library. (https://github.com/github/scientist)
MIT License
9 stars 1 forks source link

Use dynamic for contexts #5

Closed davezych closed 8 years ago

davezych commented 8 years ago

Right now the contexts param of the test method is a params object[]. Should it use dynamic?

MovGP0 commented 8 years ago

I would go for both and also provide an overload with IEmunerable contexts.

Personally, I prefer serializing the context in form of an dynamic object using a high-performance JSON library like Jil.

MovGP0 commented 8 years ago

The advantage of using an dynamic object is that I can preserve the name of the parameters inside the object:

var userCanRead = Shience.New<bool>()
   .Test(() => UserPermissions.CheckUser(currentUser), () => User.Can(currentUser, Permission.Read))
    .WithContext(new {
        @class: nameof(MyClass), 
        method: nameof(Display), 
        currentUser, 
        timestamp: DateTime.UtcNow 
    })
    .Execute();

Logging should ideally also provide the name and position of the code under test using reflection out of the box (think CallerMemberNameAttribute).