예제 #1
0
        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");
        }
예제 #2
0
        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);
        }
예제 #3
0
        public void AuthorizationState_must_not_accept_empty_code()
        {
            var target = new APIAuthorizer("client", "key", new Uri("https://www.mystore.com/manager"));

            target.AuthorizationState("");
        }