Golem.Rest, Technical Details - ProtoTest/ProtoTest.Golem GitHub Wiki

===== ###Extensions You can use extension methods in C# to add functions to classes. This means you can create more complex setup routines, add include them in the Given/When/Then methods.

An example extension method to get a customer ID:

    public static class GivenExtensions
    {
        public static Given CustomerId(this Given given)
        {
            string id = given.Domain("http://www.thomas-bayer.com")
                 .When.Get("/sqlrest/CUSTOMER")
                 .Then.GetStringFromBody("//CUSTOMER[10]/text()");

            return given.Token("CustomerId", id);
        }
    }

And a test that uses the extension method. You can see we store the customerID to a variable called CustomerId and we can reference that later in our test:

        [Test]
        public void TestExtension()
        {
            Given.CustomerId()
                .When.Get("/sqlrest/CUSTOMER/{CustomerId}").
                Then.Verify().ResponseCode(HttpStatusCode.OK);
        }