public void BuildBaseString_TwitterExample() { NameValueCollection collectedParameters = new NameValueCollection(); collectedParameters.Add("oauth_consumer_key", "GDdmIQH6jhtmLUypg82g"); collectedParameters.Add("oauth_signature_method", SigningSupport.HMAC_SHA1_SIGNATURE_NAME); collectedParameters.Add("oauth_timestamp", 2468013579L.ToString()); collectedParameters.Add("oauth_nonce", 1357924680.ToString()); collectedParameters.Add("oauth_version", "1.0"); collectedParameters.Add("oauth_callback", "http://localhost:3005/the_dance/process_callback?service_provider_id=11"); String baseString = SigningSupport.BuildBaseString(HttpMethod.POST, "https://api.twitter.com/oauth/request_token", collectedParameters); String[] baseStringParts = baseString.Split('&'); Assert.AreEqual(3, baseStringParts.Length); Assert.AreEqual("POST", baseStringParts[0]); Assert.AreEqual("https%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token", baseStringParts[1]); String[] parameterParts = baseStringParts[2].Split(new string[] { "%26" }, StringSplitOptions.None); Assert.AreEqual(6, parameterParts.Length); Assert.AreEqual("oauth_callback%3Dhttp%253A%252F%252Flocalhost%253A3005%252Fthe_dance%252Fprocess_callback%253Fservice_provider_id%253D11", parameterParts[0]); Assert.AreEqual("oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g", parameterParts[1]); Assert.AreEqual("oauth_nonce%3D1357924680", parameterParts[2]); Assert.AreEqual("oauth_signature_method%3DHMAC-SHA1", parameterParts[3]); Assert.AreEqual("oauth_timestamp%3D2468013579", parameterParts[4]); Assert.AreEqual("oauth_version%3D1.0", parameterParts[5]); }
public void BuildBaseString_SpecificationExample() { NameValueCollection collectedParameters = new NameValueCollection(); collectedParameters.Add("b5", "=%3D"); collectedParameters.Add("a3", "a"); collectedParameters.Add("c@", ""); collectedParameters.Add("a2", "r b"); collectedParameters.Add("c2", ""); collectedParameters.Add("a3", "2 q"); collectedParameters.Add("oauth_consumer_key", "9djdj82h48djs9d2"); collectedParameters.Add("oauth_signature_method", SigningSupport.HMAC_SHA1_SIGNATURE_NAME); collectedParameters.Add("oauth_timestamp", 2468013579L.ToString()); collectedParameters.Add("oauth_nonce", 1357924680.ToString()); collectedParameters.Add("oauth_version", "1.0"); collectedParameters.Add("oauth_token", "kkk9d7dh3k39sjv7"); string baseString = SigningSupport.BuildBaseString(HttpMethod.POST, "http://example.com/request", collectedParameters); string[] baseStringParts = baseString.Split('&'); Assert.AreEqual(3, baseStringParts.Length); Assert.AreEqual("POST", baseStringParts[0]); Assert.AreEqual("http%3A%2F%2Fexample.com%2Frequest", baseStringParts[1]); String[] parameterParts = baseStringParts[2].Split(new string[] { "%26" }, StringSplitOptions.None); Assert.AreEqual(12, parameterParts.Length); Assert.AreEqual("a2%3Dr%2520b", parameterParts[0]); Assert.AreEqual("a3%3D2%2520q", parameterParts[1]); Assert.AreEqual("a3%3Da", parameterParts[2]); Assert.AreEqual("b5%3D%253D%25253D", parameterParts[3]); Assert.AreEqual("c%2540%3D", parameterParts[4]); Assert.AreEqual("c2%3D", parameterParts[5]); Assert.AreEqual("oauth_consumer_key%3D9djdj82h48djs9d2", parameterParts[6]); Assert.AreEqual("oauth_nonce%3D1357924680", parameterParts[7]); Assert.AreEqual("oauth_signature_method%3DHMAC-SHA1", parameterParts[8]); Assert.AreEqual("oauth_timestamp%3D2468013579", parameterParts[9]); Assert.AreEqual("oauth_token%3Dkkk9d7dh3k39sjv7", parameterParts[10]); Assert.AreEqual("oauth_version%3D1.0", parameterParts[11]); }