コード例 #1
0
        public void CommandBuilder_GenerateRequest_CallsAuthenticationForSignature()
        {
            var commandBuilder = new ComputeCommandBuilder();
            var mockAuthenticator = Substitute.For<IComputeCommandAuthenticator>();

            commandBuilder.GenerateRequest(new StubRequest(), mockAuthenticator, "http://tempuri.com", "", "");

            mockAuthenticator.Received().AuthenticateRequest(Arg.Any<string>(), Arg.Any<string>());
        }
コード例 #2
0
        public void CommandBuilder_GenerateRequest_CallsAuthenticationForSignature()
        {
            var commandBuilder    = new ComputeCommandBuilder();
            var mockAuthenticator = Substitute.For <IComputeCommandAuthenticator>();

            commandBuilder.GenerateRequest(new StubRequest(), mockAuthenticator, "http://tempuri.com", "", "");

            mockAuthenticator.Received().AuthenticateRequest(Arg.Any <string>(), Arg.Any <string>());
        }
コード例 #3
0
        public void CommandBuilder_GenerateRequest_ShouldReturnGetRequest()
        {
            var commandBuilder = new ComputeCommandBuilder();

            var request = commandBuilder.GenerateRequest(new StubRequest(),
                                                         Substitute.For <IComputeCommandAuthenticator>(),
                                                         "http://tempuri.org",
                                                         "key",
                                                         "AAAAAAAAAAAAAAAA");

            Assert.IsNotNull(request);
            Assert.AreEqual("GET", request.Method);
        }
コード例 #4
0
        public void CommandBuilder_GenerateRequest_ShouldNotIncludeAnEmptyParameter()
        {
            var commandBuilder = new ComputeCommandBuilder();

            var request = commandBuilder.GenerateRequest(new StubRequest
            {
                ParameterOne = "1",
            },
                                                         new ComputeCommandAuthenticator(),
                                                         "http://tempuri.org",
                                                         "key",
                                                         "AAAAAAAAAAAAAAAA");

            Assert.IsNotNull(request);
            Assert.IsFalse(request.RequestUri.Query.Contains("parameterTwo=2"));
        }
コード例 #5
0
        public void CommandBuilder_GenerateRequest_QueryStartsWithApiKeyAndCommand()
        {
            var commandBuilder = new ComputeCommandBuilder();
            var authenticator  = Substitute.For <IComputeCommandAuthenticator>();

            var request = commandBuilder.GenerateRequest(new StubRequest
            {
                ParameterOne = "1",
            },
                                                         authenticator,
                                                         "http://tempuri.org",
                                                         "key",
                                                         "AAAAAAAAAA");

            Assert.IsNotNull(request);
            Assert.IsTrue(request.RequestUri.Query.StartsWith("?apiKey=key&command=stubRequest"));
        }
コード例 #6
0
        public void CommandBuilder_GenerateRequest_ParameterNamesAreCamelCased()
        {
            var commandBuilder = new ComputeCommandBuilder();
            var authenticator  = Substitute.For <IComputeCommandAuthenticator>();

            var request = commandBuilder.GenerateRequest(new StubRequest
            {
                ParameterOne = "1",
            },
                                                         authenticator,
                                                         "http://tempuri.org",
                                                         "key",
                                                         "AAAAAAAAAA");

            Assert.IsNotNull(request);
            Assert.IsTrue(request.RequestUri.Query.Contains("parameterOne"));
        }
コード例 #7
0
        public void CommandBuilder_GenerateRequest_QueryStartsWithApiKeyAndCommand()
        {
            var commandBuilder = new ComputeCommandBuilder();
            var authenticator = Substitute.For<IComputeCommandAuthenticator>();

            var request = commandBuilder.GenerateRequest(new StubRequest
            {
                ParameterOne = "1",
            },
                                                                   authenticator,
                                                                   "http://tempuri.org",
                                                                   "key",
                                                                   "AAAAAAAAAA");

            Assert.IsNotNull(request);
            Assert.IsTrue(request.RequestUri.Query.StartsWith("?apiKey=key&command=stubRequest"));
        }
コード例 #8
0
        public void CommandBuilder_GenerateRequest_ParameterNamesAreCamelCased()
        {
            var commandBuilder = new ComputeCommandBuilder();
            var authenticator = Substitute.For<IComputeCommandAuthenticator>();

            var request = commandBuilder.GenerateRequest(new StubRequest
            {
                ParameterOne = "1",
            },
                                                                   authenticator,
                                                                   "http://tempuri.org",
                                                                   "key",
                                                                   "AAAAAAAAAA");

            Assert.IsNotNull(request);
            Assert.IsTrue(request.RequestUri.Query.Contains("parameterOne"));
        }
コード例 #9
0
        public void CommandBuilder_GenerateRequest_ShouldReturnQueryContainingAllProvidedRequestParams()
        {
            var commandBuilder = new ComputeCommandBuilder();

            var request = commandBuilder.GenerateRequest(new StubRequest
            {
                ParameterOne = "1",
                ParameterTwo = "2",
            },
                                                         Substitute.For <IComputeCommandAuthenticator>(),
                                                         "http://tempuri.org",
                                                         "key",
                                                         "AAAAAAAAAAAAAAAA");

            Assert.IsNotNull(request);
            Assert.IsTrue(request.RequestUri.Query.Contains("parameterOne=1"));
            Assert.IsTrue(request.RequestUri.Query.Contains("parameterTwo=2"));
        }
コード例 #10
0
        public void CommandBuilder_GenerateRequest_AppendsSignatureToRequest()
        {
            const string secret = "AAAAAAAAAAAAAAAA";

            var commandBuilder = new ComputeCommandBuilder();
            var authenticator =Substitute.For<IComputeCommandAuthenticator>();
            authenticator.AuthenticateRequest(Arg.Any<string>(), secret).Returns("signature");

            var request = commandBuilder.GenerateRequest(new StubRequest
                                                                    {
                                                                        ParameterOne = "1",
                                                                    },
                                                                    authenticator,
                                                                    "http://tempuri.org",
                                                                    "key",
                                                                    secret);

            Assert.IsNotNull(request);
            Assert.IsTrue(request.RequestUri.Query.EndsWith("&signature=signature"), string.Format("Query ends with {0}", request.RequestUri.Query));
        }
コード例 #11
0
        public void CommandBuilder_GenerateRequest_AppendsSignatureToRequest()
        {
            const string secret = "AAAAAAAAAAAAAAAA";

            var commandBuilder = new ComputeCommandBuilder();
            var authenticator  = Substitute.For <IComputeCommandAuthenticator>();

            authenticator.AuthenticateRequest(Arg.Any <string>(), secret).Returns("signature");


            var request = commandBuilder.GenerateRequest(new StubRequest
            {
                ParameterOne = "1",
            },
                                                         authenticator,
                                                         "http://tempuri.org",
                                                         "key",
                                                         secret);

            Assert.IsNotNull(request);
            Assert.IsTrue(request.RequestUri.Query.EndsWith("&signature=signature"), string.Format("Query ends with {0}", request.RequestUri.Query));
        }
コード例 #12
0
        public void CommandBuilder_GenerateRequest_ShouldNotIncludeAnEmptyParameter()
        {
            var commandBuilder = new ComputeCommandBuilder();

            var request = commandBuilder.GenerateRequest(new StubRequest
            {
                ParameterOne = "1",
            },
                                                                    new ComputeCommandAuthenticator(),
                                                                    "http://tempuri.org",
                                                                    "key",
                                                                    "AAAAAAAAAAAAAAAA");

            Assert.IsNotNull(request);
            Assert.IsFalse(request.RequestUri.Query.Contains("parameterTwo=2"));
        }
コード例 #13
0
        public void CommandBuilder_GenerateRequest_ShouldReturnQueryContainingAllProvidedRequestParams()
        {
            var commandBuilder = new ComputeCommandBuilder();

            var request = commandBuilder.GenerateRequest(new StubRequest
                                                             {
                                                                 ParameterOne = "1",
                                                                 ParameterTwo = "2",
                                                             },
                                                                    Substitute.For<IComputeCommandAuthenticator>(),
                                                                    "http://tempuri.org",
                                                                    "key",
                                                                    "AAAAAAAAAAAAAAAA");

            Assert.IsNotNull(request);
            Assert.IsTrue(request.RequestUri.Query.Contains("parameterOne=1"));
            Assert.IsTrue(request.RequestUri.Query.Contains("parameterTwo=2"));
        }
コード例 #14
0
        public void CommandBuilder_GenerateRequest_ShouldReturnGetRequest()
        {
            var commandBuilder = new ComputeCommandBuilder();

            var request = commandBuilder.GenerateRequest(new StubRequest(),
                                                                    Substitute.For<IComputeCommandAuthenticator>(),
                                                                    "http://tempuri.org",
                                                                    "key",
                                                                    "AAAAAAAAAAAAAAAA");

            Assert.IsNotNull(request);
            Assert.AreEqual("GET", request.Method);
        }