예제 #1
0
        public void CanRecognize200JsonException()
        {

            var errorDto = new ApiErrorResponseDTO()
            {
                ErrorCode = (int)ErrorCode.InvalidCredentials,
                ErrorMessage = "InvalidCredentials"

            };

            var ctx = BuildAuthenticatedClientAndSetupResponse(JsonConvert.SerializeObject(errorDto));

            ctx.LogIn(TestConfig.ApiUsername, TestConfig.ApiPassword);

        }
예제 #2
0
        public void ApiAuthenticationFailure()
        {

            var errorDto = new ApiErrorResponseDTO()
            {
                ErrorCode = (int)ErrorCode.InvalidCredentials,
                ErrorMessage = "InvalidCredentials"

            };

            var ctx = BuildAuthenticatedClientAndSetupResponse(JsonConvert.SerializeObject(errorDto));

            try
            {
                ctx.LogIn("foo", "bar");
                Assert.Fail("Expected exception");
            }
            catch (ApiException ex)
            {
                Assert.AreEqual("InvalidCredentials", ex.Message, "FIXME: the API is just setting 401. it needs to send ErrorResponseDTO json as well.");
                Assert.AreEqual("{\"ErrorMessage\":\"InvalidCredentials\",\"ErrorCode\":4010}", ex.ResponseText);
            }
        }
예제 #3
0
        public void CanRecognize200JsonException()
        {
            var server = new CassiniDevServer();
            server.StartServer(Environment.CurrentDirectory);

            var ctx = new Client(new Uri(server.NormalizeUrl("/")), new Uri(server.NormalizeUrl("/")), "foo")
            {
                UserName = "******",
                Session = "123"
            };


            var errorDto = new ApiErrorResponseDTO
                               {
                                   ErrorCode = (int)ErrorCode.InvalidCredentials,
                                   ErrorMessage = "InvalidCredentials"
                               };


            string jsonConvertSerializeObject = JsonConvert.SerializeObject(errorDto);

            server.Server.ProcessRequest += (i, e) =>
            {
                e.Continue = false;

                e.Response = jsonConvertSerializeObject;

            };

            ApiLogOnResponseDTO response = null;
            try
            {

                response = ctx.LogIn(Settings.RpcUserName, Settings.RpcPassword);
            }
            finally
            {
                server.Dispose();
            }

            Assert.IsNotNull(response);
        }
예제 #4
0
        public void ApiAuthenticationFailure()
        {
            Console.WriteLine("ApiAuthenticationFailure");

            var server = new CassiniDevServer();
            server.StartServer(Environment.CurrentDirectory);

            var errorDto = new ApiErrorResponseDTO
                               {
                                   ErrorCode = (int)ErrorCode.InvalidCredentials,
                                   ErrorMessage = "InvalidCredentials"
                               };



            var ctx = new Client(new Uri(server.NormalizeUrl("/")), new Uri(server.NormalizeUrl("/")), "foo")
                          {
                              UserName = "******",
                              Session = "123"
                          }; // authenticated

            server.Server.ProcessRequest += (i, e) =>
            {
                e.Continue = false;
                e.Response = JsonConvert.SerializeObject(errorDto);

            };


            Exception ex = null;
            try
            {
                ctx.LogIn("foo", "bar");
                Assert.Fail("Expected exception");
            }
            catch (Exception ex2)
            {
                ex = ex2;
            }
            finally
            {
                server.Dispose();
            }



            if (!(ex is ReliableHttpException))
            {
                Assert.Fail("Expected ReliableHttpException, got " + ex.GetType().FullName);
            }

            Assert.AreEqual("InvalidCredentials", ex.Message, "FIXME: the API is just setting 401. it needs to send ErrorResponseDTO json as well.");
            Assert.AreEqual("{\"HttpStatus\":0,\"ErrorMessage\":\"InvalidCredentials\",\"ErrorCode\":4010}", ((ReliableHttpException)ex).ResponseText);

        }