Wednesday, August 31, 2011

HP's QuickTest Professional (QTP)

...is being set up for our full system tests this sprint.

we are using the LINQSPECS open source library and not just LINQ

http://linqspecs.codeplex.com

a test I broke

We have a test that starts out like so:

[TestMethod]

public void FooControllerViewAllActionSecurityTest()

{

   var actionName = "Index";

   var controller = new FooController();

   var type = controller.GetType();

   var authAttribute = GetAuthorizedRolesAttribute(type, actionName, new Type[] {

         typeof(FooModel), typeof(BarModel), typeof(int))

      });

 
 

...which does a few other complicated things to test security. Some of it is done by GetAuthorizedRolesAttribute which expects the appropriate parameters for an action method's definition to be handed into it. The test fails if the wrong parameters are handed in. I broke this test yesterday, but fixed it today.

one may bind to two models at once upon POST

[HttpPost]

public ActionResult Index(ModelOne modelOne, ModelTwo modelTwo)

{

   
Whatever...

}

Tuesday, August 30, 2011

What I did today!

Today:
  1. Today Kar-Khan pointed out to me the my get/setter-based approach to jumping through a bunch of hoops immediately upon model binding which I crafted here, refined here, and then had Joel refine here, is just goofy. It is better to just have plain Jane get/setters and then call a method to do more complicated things with them beyond get and set. It didn’t want to do this because it entails putting an extra line of code in the Controller, but boy is that ever the lesser of the two evils compared to the mess I've been making.
  2. I added the following to our Base Class for Repositories:

    public virtual IQueryable<T> FindFilteredSet(List<Specification<T>> specifications)

    {

       Specification<T> currentSpecification =

             new AdHocSpecification<T>(t => t != null);

       IQueryable<T> results =

             Session.Query<T>().Where(currentSpecification.IsSatisfiedBy());

       foreach(Specification<T> specification in specifications)

       {

          IQueryable<T> concatenatedResults =

                Session.Query<T>().FindAll(specification).FindAll(currentSpecification);

          currentSpecification = specification;

          results = concatenatedResults;

       }

       return results;

    }

     
     

    Joel refactored my work like so:

    public virtual IQueryable<T> FindFilteredSet(List<Specification<T>> specifications)

    {

       var query = Session.Query<T>();

       specifications.ForEach(spec => query.Where(spec.IsSatisfiedBy()));

       return query;

    }

     
     

    Joel told me that foreach is old school and that I should try to use Select instead where applicable although it is not applicable in this case.
  3. We are taking the approach above in lieu of chaining specs in the name of a cleaner process outside of logic nested in Controllers which may also be encapsulated to play nicely with a comparable means devised for filtering based upon custom attributes. (I am building specifications for filtering on the static parameters of objects and the static parameters of their children in this example.)

Ctrl-Period renames a variable

If you rename a variable where it is first instantiated and you wish to make the change cascade to everywhere the variable's name is used, press Ctrl-Period. I believe this is a shortcut of Visual Studio itself and not a shortcut of Resharper.

What do you want from me? It's so hard to tell!

How does one interact with a method with a complicated interface like so:

TryParseValue(this object value, Type propType, out object result, out string errorMsg)

 
 

  1. There are three values you must hand in and not four. The first value, this, is handed over by way of chaining on .TryParseValue(a,b,c) to the end of it.
  2. The first alert as to the desired shape that I saw when moving my mouse pointer over empty parenthesis was:
    (this object value, Type propType, out object result, out string errorMsg):bool
  3. .TryParseValue(typeof (Boolean), out myObject, out emptyString); is the ultimate shape of things. If one leaves off one of the outs in this call one will be flagged with: Argument is 'value' while parameter is declared as 'out' ...when one mouses over the stuff in parenthesis.