private static void Main(string[] args) { var assemblyLauncher = new AssemblyLauncher(); var result1 = assemblyLauncher.Execute <BizLogicObjcet, object>(new BizLogicObjcet(), "GetString"); Console.WriteLine(JsonSerializer.Serialize(result1)); var result2 = assemblyLauncher.Execute <BizLogicObjcet, object>( new BizLogicObjcet(), "GetStringWithParamter", JsonSerializer.Serialize(new { Name = "Hello World" }) ); Console.WriteLine(JsonSerializer.Serialize(result2)); try { var result3 = assemblyLauncher.Execute <BizLogicObjcet, object>( new BizLogicObjcet(), "GetStringWith2Paramter", string.Concat( JsonSerializer.Serialize(new { Name = "Hello World1" }), JsonSerializer.Serialize(new { Name = "Hello World2" })) ); Console.WriteLine(JsonSerializer.Serialize(result3)); } catch (Exception e) { Console.WriteLine(e.Message); } }
public void TestExecute() { var stubMethod = AssemblyLauncher.Execute <StubBizLogic, string>(StubBizLogic, "StubMethod"); Assert.AreEqual("Result", stubMethod.Message); var stubMethodWithParameter = AssemblyLauncher.Execute <StubBizLogic, string>(StubBizLogic, "StubMethodWithParameter", "'parameter'"); Assert.AreEqual("Result with parameter", stubMethodWithParameter.Message); }
public void TestJsonException() { try { AssemblyLauncher.Execute <StubBizLogic, string>(StubBizLogic, "StubMethodWithParameter", "{parameter: wrong}"); Assert.Fail("應該拋出一個例外"); } catch (Exception e) { Assert.AreEqual("JSON 參數反序列化錯誤,UnitTestProject.StubBizLogic 的 StubMethodWithParameter 組件方法所需參數型別應為: System.String", e.Message); } }
public void TestTooManyParametersException() { try { AssemblyLauncher.Execute <StubBizLogic, string>(StubBizLogic, "StubMethodWithTooManyParameter", "'parameter'"); Assert.Fail("應該拋出一個例外"); } catch (Exception e) { Assert.AreEqual("依照設計規範 UnitTestProject.StubBizLogic 的 StubMethodWithTooManyParameter 組件方法只能傳入一個參數", e.Message); } }
public void TestNotReturnTypeofIExecuteResultException() { try { AssemblyLauncher.Execute <StubBizLogic, string>(StubBizLogic, "StubMethod2"); Assert.Fail("應該拋出一個例外"); } catch (Exception e) { Assert.AreEqual("依照設計規範 UnitTestProject.StubBizLogic 的 StubMethod2 組件方法必須回傳繼承自 IExecuteResult<T> 介面的物件,可將該組件方法的回傳型別改為 DefaultExecuteResult", e.Message); } try { AssemblyLauncher.Execute <StubBizLogic, string>(StubBizLogic, "StubMethodWithParameter2", "'parameter'"); Assert.Fail("應該拋出一個例外"); } catch (Exception e) { Assert.AreEqual("依照設計規範 UnitTestProject.StubBizLogic 的 StubMethodWithParameter2 組件方法必須回傳繼承自 IExecuteResult<T> 介面的物件,可將該組件方法的回傳型別改為 DefaultExecuteResult", e.Message); } }
public IActionResult Get(string method) { var result = AssemblyLauncher.Execute <BizLogicObjcet, object>(new BizLogicObjcet(), method); return(new JsonResult(result)); }
public void TestReturnType() { var stubMethod = AssemblyLauncher.Execute <StubBizLogic, string>(StubBizLogic, "StubMethod"); Assert.IsInstanceOfType(stubMethod, typeof(IExecuteResult <string>)); }