private static AsyncDelegation NewAD(string baseUri) { RestFacilitator restFacilitator = new RestFacilitator(); RestService restService = new RestService(restFacilitator, baseUri); AsyncDelegation asyncDelegation = new AsyncDelegation(restService); return asyncDelegation; }
void requesting_haikus_from_twitter() { before = () => facilitator = new RestFacilitator("http://search.twitter.com"); act = () => json = facilitator.Get("search.json", new { q = "#haiku" }); it["finds tweets"] = () => { var tweets = (json.results as IEnumerable<dynamic>).Select(s => s.text); tweets.Count().should_be_greater_than(0); }; it["finds max_id"] = () => ((int)json.max_id).should_not_be(0); it["find refresh url"] = () => (json.refresh_url as string).should_not_be_empty(); }
void before_each() { ResetDbs(); Rest = new RestFacilitator("http://localhost:3000"); }
static void Main(string[] args) { restFacilitator = new RestFacilitator("http://*****:*****@example.com"); Reset(); "\nrequesting root, this was returned:".Write(); var root = restFacilitator.Get("/"); (JsonString.Parse(root) as string).Write(); var createUser = (root.Links as object).Link("CreateUser"); "this is the rel that was given for CreateUser:"******"creating user\n".Write(); user = restFacilitator.Post(createUser); "post complete this is the entity that was returned:".Write(); (JsonString.Parse(user) as string).Write(); "woo hoo, we have a user, time to list blogs".Write(); var blogsUrl = (user.Links as IEnumerable<dynamic>).Link("GetBlogPosts"); "here is the payload returned by following the GetBlogPosts link".Write(); var blogPosts = restFacilitator.Get(blogsUrl); (JsonString.Parse(blogPosts) as string).Write(); var addPostUrl = (blogPosts.Links as object).Link("AddPost"); var title = Guid.NewGuid().ToString(); "add a blog with title {0}\n".With(title).Write(); blogPosts = restFacilitator.Post(addPostUrl, new { title, body = "Body for {0}".With(title) }); "here are all the blogs posts for this user".Write(); JsonString.Parse(blogPosts as object).Write(); "for each blog post here is detail".Write(); foreach (var blog in blogPosts.Items) { var blogDetailUrl = (blog.Links as object).Link("Detail"); var blogDetail = restFacilitator.Get(blogDetailUrl); JsonString.Parse(blogDetail as object).Write(); "appending hi to the end of blog post".Write(); var updateUrl = (blogDetail.Links as object).Link("Update"); restFacilitator.Post(updateUrl, new { title = blogDetail.Title, body = blogDetail.Body + " Hello" }); } "getting the blogs again and delete them all".Write(); blogsUrl = (user.Links as IEnumerable<dynamic>).Link("GetBlogPosts"); blogPosts = restFacilitator.Get(blogsUrl); foreach (var blog in blogPosts.Items) { var blogDetailUrl = (blog.Links as object).Link("Detail"); var blogDetail = restFacilitator.Get(blogDetailUrl); JsonString.Parse(blogDetail as object).Write(); var deleteUrl = (blogDetail.Links as IEnumerable<dynamic>).Link("Delete"); restFacilitator.Delete(deleteUrl); } blogPosts = restFacilitator.Get(blogsUrl); var items = blogPosts.Items as IEnumerable<dynamic>; "blog count is {0}".With(items.Count()).Write(); }