Skip to content

Instantly share code, notes, and snippets.

@KevM
Created March 16, 2012 21:39
Show Gist options
  • Save KevM/2052900 to your computer and use it in GitHub Desktop.
Save KevM/2052900 to your computer and use it in GitHub Desktop.
CSharp test fixture that creates a case using a webservice based on the Dovetail SDK
using System;
using System.Collections.Specialized;
using System.Net;
using System.Web.Script.Serialization;
using NUnit.Framework;
namespace Micros.Clarify.Webservices.Tests
{
public class CreateCaseResult
{
public string Id { get; set; }
}
[TestFixture]
public class micros_web_service_example
{
[Test]
public void create_case_api_example()
{
//api url
const string createCaseUrl = "http://localhost:39656/api/cases/create/";
//particular to the submitting site
const string authToken = "7B118ABB-43C0-4215-A1D4-D536843728B5";
const string propertyCode = "0595";
const string summary = "This is the case title";
const string notes = "These are case notes.";
const string alternateCaseId = "12345";
var postData = new NameValueCollection
{
{"authToken", authToken},
{"propertyCode", propertyCode},
{"summary", summary},
{"notes", notes},
{"AlternateCaseID", alternateCaseId}
};
var webClient = new WebClient();
webClient.Headers.Add("Accept", "application/json");
var response = webClient.UploadValues(createCaseUrl, postData);
var json = System.Text.Encoding.UTF8.GetString(response);
Console.WriteLine("json returned is: {0} ", json);
var result = new JavaScriptSerializer().Deserialize<CreateCaseResult>(json);
Assert.IsNotNullOrEmpty(result.Id);
Console.WriteLine("Case {0} was created.", result.Id);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment