コード例 #1
0
        public void ExceptionFilterTest_BusinessError_Encrypted()
        {
            using (var server = new EncryptedHttpRouteWrapper())
            using (HttpClient client = new EncryptedHttpClientWrapper())
            {
                var exceptionFilter = new ExceptionFilter();
                exceptionFilter.Exception += (sender, e) =>
                {
                    e.Handled = true;
                    e.ReturnCode = "7533967";
                    e.Message = "中毒太深";
                };
                server.Configuration.Filters.Add(exceptionFilter);

                try
                {
                    client.PostJson<object, object>(
                        "/api2/ApiServerTest/BusinessErrorTest",
                        null,
                        null
                    );

                    Assert.Fail("Did not throw expected exception InvocationNotAcceptableException.");
                }
                catch (InvocationNotAcceptableException ex)
                {
                    Assert.AreEqual("中毒太深", ex.Message);
                    Assert.AreEqual("7533967", ex.ErrorCode);
                }
            }
        }
コード例 #2
0
 public void EncryptedHttpRouteTest_RequestAndResponse()
 {
     using (var server = new EncryptedHttpRouteWrapper())
     using (HttpClient client = new EncryptedHttpClientWrapper())
     {
         client.PostJson<SmokeTestRequest, SmokeTestResponse>(
             "/api2/ApiServerTest/RequestAndResponse",
             () =>
             {
                 return new SmokeTestRequest
                 {
                     BoolValue = true,
                     ByteValue = byte.MaxValue,
                     IntValue = int.MaxValue,
                     StringValue = "string123中文abc",
                 };
             },
             response =>
             {
                 Assert.IsNotNull(response);
                 Assert.IsInstanceOfType(response, typeof(SmokeTestResponse));
                 Assert.AreEqual(true, response.BoolValue);
                 Assert.AreEqual(byte.MaxValue, response.ByteValue);
                 Assert.AreEqual(int.MaxValue, response.IntValue);
                 Assert.AreEqual("string123中文abc", response.StringValue);
             });
     }
 }
コード例 #3
0
 public void EncryptedHttpServerTest_ActionOnly()
 {
     using (HttpClient client = new EncryptedHttpClientWrapper("http://apifoundation.self.monday:9999"))
     {
         client.PostJson<object, object>("/api2/ApiServerTest/ActionOnly", null, null);
     }
 }
コード例 #4
0
 public void EncryptedHttpRouteTest_ActionOnly()
 {
     using (var server = new EncryptedHttpRouteWrapper())
     using (HttpClient client = new EncryptedHttpClientWrapper())
     {
         client.PostJson<object, object>("/api2/ApiServerTest/ActionOnly", null, null);
     }
 }
コード例 #5
0
 public void EncryptedHttpServerTest_NullResponse()
 {
     using (HttpClient client = new EncryptedHttpClientWrapper("http://apifoundation.self.monday:9999"))
     {
         client.PostJson<object, SmokeTestResponse>(
             "/api2/ApiServerTest/NullResponse",
             null,
             response => Assert.IsNull(response));
     }
 }
コード例 #6
0
 public void EncryptedHttpServerTest_NullRequest()
 {
     using (HttpClient client = new EncryptedHttpClientWrapper("http://apifoundation.self.monday:9999"))
     {
         client.PostJson<SmokeTestRequest, object>(
             "/api2/ApiServerTest/NullRequest",
             () => null,
             null);
     }
 }
コード例 #7
0
 public void EncryptedHttpRouteTest_NullResponse()
 {
     using (var server = new EncryptedHttpRouteWrapper())
     using (HttpClient client = new EncryptedHttpClientWrapper())
     {
         client.PostJson<object, SmokeTestResponse>(
             "/api2/ApiServerTest/NullResponse",
             null,
             response => Assert.IsNull(response));
     }
 }
コード例 #8
0
 public void EncryptedHttpRouteTest_NullRequest()
 {
     using (var server = new EncryptedHttpRouteWrapper())
     using (HttpClient client = new EncryptedHttpClientWrapper())
     {
         client.PostJson<SmokeTestRequest, object>(
             "/api2/ApiServerTest/NullRequest",
             () => null,
             null);
     }
 }
コード例 #9
0
 public void EncryptedHttpServerTest_RequestOnly()
 {
     using (HttpClient client = new EncryptedHttpClientWrapper("http://apifoundation.self.monday:9999"))
     {
         client.PostJson<SmokeTestRequest, object>(
             "/api2/ApiServerTest/RequestOnly",
             () =>
             {
                 return new SmokeTestRequest
                 {
                     BoolValue = true,
                     ByteValue = byte.MaxValue,
                     IntValue = int.MaxValue,
                     StringValue = "string123中文abc",
                 };
             },
             response =>
             {
                 Assert.IsNull(response);
             });
     }
 }
コード例 #10
0
 public void EncryptedHttpRouteTest_ResponseOnly()
 {
     using (var server = new EncryptedHttpRouteWrapper())
     using (HttpClient client = new EncryptedHttpClientWrapper())
     {
         client.PostJson<object, SmokeTestResponse>(
             "/api2/ApiServerTest/ResponseOnly",
             null,
             response =>
             {
                 Assert.IsNotNull(response);
                 Assert.IsInstanceOfType(response, typeof(SmokeTestResponse));
                 Assert.AreEqual(true, response.BoolValue);
                 Assert.AreEqual(byte.MaxValue, response.ByteValue);
                 Assert.AreEqual(int.MaxValue, response.IntValue);
                 Assert.AreEqual("string123中文abc", response.StringValue);
             });
     }
 }
コード例 #11
0
        public void ExceptionFilterTest_ProgramError_IIS_Encrypted()
        {
            using (HttpClient client = new EncryptedHttpClientWrapper("http://apifoundation.self.monday:9999"))
            {
                try
                {
                    client.PostJson<object, object>(
                        "/api2/ApiServerTest/ProgramErrorTest",
                        null,
                        null
                    );

                    Assert.Fail("Did not throw expected exception HttpServiceException.");
                }

                catch (HttpServiceException ex)
                {
                    Assert.AreEqual("模擬非商業邏輯錯誤。", ex.ExceptionMessage);
                    Assert.AreEqual(typeof(InvalidOperationException).FullName, ex.ExceptionType);
                }
            }
        }
コード例 #12
0
        public void ExceptionFilterTest_ProgramError_Encrypted()
        {
            using (var server = new EncryptedHttpRouteWrapper())
            using (HttpClient client = new EncryptedHttpClientWrapper())
            {
                server.Configuration.Filters.Add(new ExceptionFilter());

                try
                {
                    client.PostJson<object, object>(
                        "/api2/ApiServerTest/ProgramErrorTest",
                        null,
                        null
                    );

                    Assert.Fail("Did not throw expected exception HttpServiceException.");
                }
                catch (HttpServiceException ex)
                {
                    Assert.AreEqual("模擬非商業邏輯錯誤。", ex.ExceptionMessage);
                    Assert.AreEqual(typeof(InvalidOperationException).FullName, ex.ExceptionType);
                }
            }
        }
コード例 #13
0
        public void ExceptionFilterTest_BusinessError_IIS_Encrypted()
        {
            using (HttpClient client = new EncryptedHttpClientWrapper("http://apifoundation.self.monday:9999"))
            {
                try
                {
                    client.PostJson<object, object>(
                        "/api2/ApiServerTest/BusinessErrorTest",
                        null,
                        null
                    );

                    Assert.Fail("Did not throw expected exception InvocationNotAcceptableException.");
                }
                catch (InvocationNotAcceptableException ex)
                {
                    Assert.AreEqual("中毒太深", ex.Message);
                    Assert.AreEqual("7533967", ex.ErrorCode);
                }
            }
        }