Total Pageviews

Thursday, October 11, 2012

Rhino Mocks and mocking Out/Ref params


Today I was in the process of mocking out a service call for an application I was working on.  But the method I wanted to mock took a out parameter in its signature.  Normally this is not an issue, but since this out parameter result was used in my code, I needed to setup an expectation on that value.
Fortunately for us, Rhino handles this pretty easily.  In order to set expectations on an Our or Ref all I need to do is add a call to the OutRef() method on my Expect call.

_findTask.Stub(
  a => a.TryFind(somePoint, out coordinates, out coordinatesSuggestions))
.Return(results)
.OutRef(coordinates = new List(), 
       coordinatesSuggestions  new List());

Windy — jQuery slider plugin with a cool effect




Here are the demonstration and sources.

For proper work you need to create an UL element with the wi-container class.

<ul id="wi-el" class="wi-container"> <li> <img src="images/demo1/1.jpg" alt="image1"/> <h4>Coco Loko</h4> <p>Total bicycle rights in blog four loko raw denim ex.</p> </li> <li> <!-- ... --> </li> <li> <!-- ... --> </li> <li> <!-- ... --> </li> <!-- ... --> </ul>

Browser without support of CSS 3D transition and transform will render the standart slider animation.

Wednesday, October 10, 2012

Unit testing code that uses HttpContext.Current.Session


Use can simply use this class to set up a fake one :)

private static void SetFakeHttpContext()
{
    var httpRequest = new HttpRequest("", "http://yoursite/", "");
    var stringWriter = new StringWriter();
    var httpResponce = new HttpResponse(stringWriter);
    var httpContext = new HttpContext(httpRequest, httpResponce);

    var sessionContainer = new HttpSessionStateContainer("id", 
                            new SessionStateItemCollection(),
                            new HttpStaticObjectsCollection(), 
                            10, 
                            true,
                            HttpCookieMode.AutoDetect,
                            SessionStateMode.InProc, 
                            false);

    httpContext.Items["AspSession"] = typeof (HttpSessionState).GetConstructor(
                BindingFlags.NonPublic | BindingFlags.Instance,
                null, CallingConventions.Standard,
                new[] {typeof (HttpSessionStateContainer)},
                null)
                .Invoke(new object[] {sessionContainer});

    HttpContext.Current = httpContext;
}