You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

64 lines
2.6 KiB

  1. using Xunit;
  2. using ExternalModuleSubscriberClass = DotNetCore.CAP.MultiModuleSubscriberTests.SubscriberClass;
  3. namespace DotNetCore.CAP.Test.SubscriberCollisionTests
  4. {
  5. public class NewMethodTests
  6. {
  7. [Fact]
  8. public void NoCollision_SameClassAndMethod_DifferentAssemblies()
  9. {
  10. var methodInfo = typeof(SubscriberClass).GetMethod(nameof(SubscriberClass.TestSubscriber));
  11. var externalMethodInfo = typeof(ExternalModuleSubscriberClass).GetMethod(nameof(ExternalModuleSubscriberClass.TestSubscriber));
  12. Assert.NotEqual(methodInfo.MethodHandle, externalMethodInfo.MethodHandle);
  13. }
  14. [Fact]
  15. public void Collision_Subclass_SameAssembly_MethodHandleOnly()
  16. {
  17. var methodInfo1 = typeof(Subclass1OfSubscriberClass).GetMethod(nameof(SubscriberClass.TestSubscriber));
  18. var methodInfo2 = typeof(Subclass2OfSubscriberClass).GetMethod(nameof(SubscriberClass.TestSubscriber));
  19. Assert.Equal(methodInfo1.MethodHandle.Value,
  20. methodInfo2.MethodHandle.Value);
  21. }
  22. [Fact]
  23. public void NoCollision_Subclass_SameAssembly_TypeAndMethodHandle()
  24. {
  25. var methodInfo1 = typeof(Subclass1OfSubscriberClass).GetMethod(nameof(SubscriberClass.TestSubscriber));
  26. var methodInfo2 = typeof(Subclass2OfSubscriberClass).GetMethod(nameof(SubscriberClass.TestSubscriber));
  27. Assert.NotEqual($"{methodInfo1.MethodHandle.Value}_{methodInfo1.ReflectedType.TypeHandle.Value}",
  28. $"{methodInfo2.MethodHandle.Value}_{methodInfo2.ReflectedType.TypeHandle.Value}");
  29. }
  30. [Fact]
  31. public void NoCollision_SubclassOfGenericOpenType_SameAssembly_Handle()
  32. {
  33. var methodInfo1 = typeof(BaseClass<>)
  34. .MakeGenericType(typeof(MessageType1))
  35. .GetMethod(nameof(BaseClass<object>.Handle));
  36. var methodInfo2 = typeof(BaseClass<>)
  37. .MakeGenericType(typeof(MessageType2))
  38. .GetMethod(nameof(BaseClass<object>.Handle));
  39. Assert.NotEqual($"{methodInfo1.MethodHandle.Value}_{methodInfo1.ReflectedType.TypeHandle.Value}",
  40. $"{methodInfo2.MethodHandle.Value}_{methodInfo2.ReflectedType.TypeHandle.Value}");
  41. }
  42. private class Subclass1OfSubscriberClass : SubscriberClass { }
  43. private class Subclass2OfSubscriberClass : SubscriberClass { }
  44. private class MessageType1 { }
  45. private class MessageType2 { }
  46. private abstract class BaseClass<T>
  47. {
  48. public void Handle()
  49. {
  50. }
  51. }
  52. }
  53. }