InterceptorTest.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using Xunit;
  5. namespace VCommon.Ioc.Tests
  6. {
  7. public class InterceptorTest
  8. {
  9. private class Interceptor : IInterceptor, ITransientIocClass
  10. {
  11. public void BeforeInvoke(Type svcClass, MethodBase svcMethod, IReadOnlyDictionary<string, object> paramDic)
  12. {
  13. }
  14. public void AfterInvoke(Type svcClass, MethodBase svcMethod, IReadOnlyDictionary<string, object> paramDic, object resultReturnValue, Exception resultException)
  15. {
  16. }
  17. }
  18. public interface ITestInterface
  19. {
  20. int TestMethod(int value);
  21. }
  22. private class TestClass : ITestInterface, ITransientIocClass<IInterceptor>
  23. {
  24. public int TestMethod(int value)
  25. {
  26. return value + 1;
  27. }
  28. }
  29. [Fact]
  30. public void Test()
  31. {
  32. var container = new IocManager();
  33. var child = container.CreateChildren();
  34. child.RegisterInstanceToContainer(child);
  35. var svc = container.Resolve<ITestInterface>();
  36. var ret = svc.TestMethod(1);
  37. }
  38. }
  39. }