public void TestMergeWithAuthenticationContext()
		{
			var sut = new EmptyAuthenticationContext();
			sut.MergeWith(_authenticationContext);

			Assert.Equal(_authenticationContext.ConsumerKey, sut.ConsumerKey);
			Assert.Equal(_authenticationContext.ConsumerKeySecret, sut.ConsumerKeySecret);
			Assert.Equal(_authenticationContext.AccessToken, sut.AccessToken);
			Assert.Equal(_authenticationContext.AccessTokenSecret, sut.AccessTokenSecret);
		}
		public void TestMergeWithDictionary()
		{
			var sut = new EmptyAuthenticationContext();
			IDictionary<string, string> dictoinary = new Dictionary<string, string>
			{
				{ "oauth_token", "oauth_token_value" },
				{ "oauth_token_secret", "oauth_token_secret_value" }
			};
			sut.MergeWith(dictoinary);

			Assert.Equal("oauth_token_value", sut.AccessToken);
			Assert.Equal("oauth_token_secret_value", sut.AccessTokenSecret);
		}
Пример #3
0
		private static IAuthenticationContext GetRequestTokens(IAuthenticationContext authenticationContext)
		{
			HttpWebRequest request = GetRequestTokenRequest(authenticationContext);
			using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
			using (Stream dataStream = response.GetResponseStream())
			using (StreamReader reader = new StreamReader(dataStream))
			{
				//Read the content.
				string responseFromServer = reader.ReadToEnd();
				string[] tokens = responseFromServer.Split(new[] { "&" }, StringSplitOptions.RemoveEmptyEntries);
				Dictionary<string, string> dictionary = tokens.ToDictionary(s => s.Split('=')[0], s => s.Split('=')[1]);

				var emptyContext = new EmptyAuthenticationContext();
				emptyContext.MergeWith(dictionary);

				return emptyContext;
			}
		}