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.
 
 
 

61 regels
2.7 KiB

  1. using Xunit;
  2. using ExternalModuleSubscriberClass = DotNetCore.CAP.MultiModuleSubscriberTests.SubscriberClass;
  3. namespace DotNetCore.CAP.Test.SubscriberCollisionTests
  4. {
  5. public class OldMethodTests
  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. var reflectedType = methodInfo.ReflectedType.Name;
  13. var key = $"{methodInfo.Module.Name}_{reflectedType}_{methodInfo.MetadataToken}";
  14. var externalReflectedType = methodInfo.ReflectedType.Name;
  15. var externalKey = $"{externalMethodInfo.Module.Name}_{externalReflectedType}_{externalMethodInfo.MetadataToken}";
  16. Assert.NotEqual(key, externalKey);
  17. }
  18. [Fact]
  19. public void NoCollision_Subclasses_SameAssembly()
  20. {
  21. var methodInfo1 = typeof(Subclass1OfSubscriberClass).GetMethod(nameof(SubscriberClass.TestSubscriber));
  22. var methodInfo2 = typeof(Subclass2OfSubscriberClass).GetMethod(nameof(SubscriberClass.TestSubscriber));
  23. var reflectedType = methodInfo1.ReflectedType.Name;
  24. var key = $"{methodInfo1.Module.Name}_{reflectedType}_{methodInfo1.MetadataToken}";
  25. var externalReflectedType = methodInfo2.ReflectedType.Name;
  26. var externalKey = $"{methodInfo2.Module.Name}_{externalReflectedType}_{methodInfo2.MetadataToken}";
  27. Assert.NotEqual(key, externalKey);
  28. }
  29. [Fact]
  30. public void Collision_SubclassOfGenericOpenType_SameAssembly_Handle()
  31. {
  32. var method1 = typeof(BaseClass<>)
  33. .MakeGenericType(typeof(MessageType1))
  34. .GetMethod(nameof(BaseClass<object>.Handle));
  35. var method2 = typeof(BaseClass<>)
  36. .MakeGenericType(typeof(MessageType2))
  37. .GetMethod(nameof(BaseClass<object>.Handle));
  38. Assert.Equal(method1.MetadataToken, method2.MetadataToken);
  39. }
  40. private class Subclass1OfSubscriberClass : SubscriberClass {}
  41. private class Subclass2OfSubscriberClass : SubscriberClass {}
  42. private class MessageType1 { }
  43. private class MessageType2 { }
  44. private abstract class BaseClass<T>
  45. {
  46. public void Handle()
  47. {
  48. }
  49. }
  50. }
  51. }