Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Desktop Developer

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Another obscure difference between C# and VB.Net you probably don't know aboutUsing servicestack for the easyhttp integration tests »
    comments

    In my previous post I showed you how I used ServiceStack to do the integration tests with Easyhttp.

    I also used a different port for each test and thus a different instance of ServiceStack for each of these tests.

    Of course The Boss was not happy with this.

    So I went for a look on how to do this the better way.

    And I found this on Stackoverflow. So thanks to Jason Watts for helping me along.

    So the ServiceStackHost.cs file is still the same as before. But I created this class.

    1. using Machine.Specifications;
    2.  
    3. namespace EasyHttp.Specs.Helpers
    4. {
    5.     public class DataSpecificationBase : IAssemblyContext
    6.     {
    7.         private ServiceStackHost _appHost;
    8.         private int _port;
    9.  
    10.         void IAssemblyContext.OnAssemblyComplete()
    11.         {
    12.             _appHost.Dispose();    
    13.         }
    14.  
    15.         void IAssemblyContext.OnAssemblyStart()
    16.         {
    17.             _port = 16000;
    18.             var listeningOn = "http://localhost:" + _port + "/";
    19.             _appHost = new ServiceStackHost();
    20.             _appHost.Init();
    21.             _appHost.Start(listeningOn);
    22.         }
    23.  
    24.     }
    25. }

    And I removed the apphost field and init and teardwon code from the tests. So a test now looks like this.

    1. [Subject("HttpClient")]
    2.     public class when_making_a_GET_request_with_valid_uri
    3.     {
    4.         Establish context = () =>
    5.         {
    6.             httpClient = new HttpClient();
    7.         };
    8.  
    9.         Because of = () =>
    10.         {
    11.             httpResponse = httpClient.Get("http://localhost:16000");
    12.  
    13.         };
    14.  
    15.         It should_return_body_with_rawtext =
    16.             () => httpResponse.RawText.ShouldNotBeEmpty();
    17.  
    18.    
    19.         static HttpClient httpClient;
    20.         static HttpResponse httpResponse;
    21.     }

    It has no clue about apphost.

    And now the Boss is happy.

    And you can find all the code on Github.

    So now I know a bit more about mspec, servicestack and easyhttp. One is never to old to learn.

    About the Author

    User bio imageChris is awesome.
    Social SitingsTwitterHomePageLTD RSS Feed
    InstapaperVote on HN

    No feedback yet

    Leave a comment


    Your email address will not be revealed on this site.

    To mislead the spambots.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)