public void AuthorizationState_must_define_post_method_and_content_type() { var mock = new Mock<HttpHelper>("https://www.mystore.com/manager") .SetupProperty(m => m.HttpWebRequest.Method); mock.Setup(m => m.HttpWebRequest.GetRequestStream()).Returns(new MemoryStream()); mock.Setup(m => m.HttpWebRequest.GetResponse().GetResponseStream()).Returns(new MemoryStream()); var target = new APIAuthorizer("client", "key", new Uri("https://www.mystore.com/manager")); target.AuthorizationState("code", mock.Object); mock.VerifySet(h => h.HttpWebRequest.Method = "POST"); mock.VerifySet(h => h.HttpWebRequest.ContentType = "application/x-www-form-urlencoded"); }
public void AuthorizationState_must_define_parameters_on_request_body() { string writedString = string.Empty; var mockMS = new Mock<MemoryStream>(); mockMS.Setup(m => m.CanWrite).Returns(true); mockMS.Setup(m => m.Write(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>())).Callback( (byte[] b, int i1, int i2) => { writedString = new System.Text.ASCIIEncoding().GetString(b, i1, i2); }); var mock = new Mock<HttpHelper>("https://www.mystore.com/manager") .SetupProperty(m => m.HttpWebRequest.Method); mock.Setup(m => m.HttpWebRequest.GetRequestStream()).Returns(mockMS.Object); mock.Setup(m => m.HttpWebRequest.GetResponse().GetResponseStream()).Returns(new MemoryStream()); var target = new APIAuthorizer("client", "key", new Uri("https://www.mystore.com/manager")); target.AuthorizationState("code", mock.Object); Assert.AreEqual("client_id=client&client_secret=key&code=code", writedString); }
public void AuthorizationState_must_not_accept_empty_code() { var target = new APIAuthorizer("client", "key", new Uri("https://www.mystore.com/manager")); target.AuthorizationState(""); }