T.REST is available on NuGet and can be downloaded by using the Package Manager in Visual Studio. See package details

For configuring T.Rest, see the Configurations page

For more coding examples, check out Coding Examples

The following test is the most basic test you can write using T.REST:

[TestInitialize]
public void TestInitialize()
{
	RessourceFactory.Init(
		Assert.Fail,         
		Assert.AreEqual,     //Type comparison
		Assert.AreNotEqual,  //Int comparison
		Assert.AreEqual,     //Int comparison
Assert.AreNotEqual); //Bool comparison } [TestMethod] public void JqueryUIDemo() { var expected = new Dictionary<string, Type> { {"latitude", typeof (decimal)}, {"longitude", typeof (decimal)}, {"title", typeof(string)}, {"content", typeof(string)} }; var res = RessourceFactory.Create(new RestConfiguration { Url = "/svn/trunk/demos/json/demo.json", Host = "jquery-ui-map.googlecode.com", ExpectedObjectSignature = expected, ExpectArrayResult = true }); res.ValidateSignature(); }

 

Walkthrough:

  • In TestInitialize you specify the delegates which will be called during the various asserts. You can inject your own delegates or specify the ones in your testing framework shown above
  • You create a dictionary with the properties and their type which should match what you expect to be returned from your service call. T.REST uses NewtonSoft.Json internally to cast the service output to an object and the types of the various properties returned will be matched against the expected result.
  • You create a Ressource object using the RessourceFactory. You inject a RestConfiguration object into the factory in which you specify the host, the Url etc. (TODO: Page with doc of config properties

Once you call the extension method "ValidateSignature()" on your ressource object the following will be asserted by the framework:

  • That the REST ressource returns an object with properties
  • That the number of properties matches the number of properties in the expected result
  • That no properties were found which were not specified in the expected result
  • That the types of the properties returned by the REST ressource matches your expected result

The test passes if the above statements are satified.

Last edited Oct 17, 2012 at 8:55 PM by kerbou, version 11

Comments

No comments yet.