Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1.         [Test]
  2.         public void Test_SpecialLinkAttributes_Are_Marked_On_Correct_Types()
  3.         {
  4.             //arrange
  5.             //Find the attribute that should be annoting these payloads
  6.             WireDataContractBaseLinkAttribute linkAttri = typeof(LoginClientPacketPayloadAttribute)
  7.                 .Assembly
  8.                 .GetTypes()
  9.                 .Where(t => t.BaseType == typeof(WireDataContractBaseLinkAttribute))
  10.                 .Select(t => Activator.CreateInstance(t, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] {5}, null) as WireDataContractBaseLinkAttribute)
  11.                 .FirstOrDefault(c => c.BaseType == typeof(TPayloadBaseType));
  12.  
  13.             //check that all payloads in the assembly with this attribute derive from the basepayload type
  14.             foreach(Type t in typeof(TTypeToReflectForAssembly).Assembly
  15.                 .GetTypes()
  16.                 .Where(t => t.GetCustomAttribute(linkAttri.GetType()) != null))
  17.             {
  18.                 Assert.True(typeof(TPayloadBaseType).IsAssignableFrom(t), $"Type: {t.Name} is marked with Attribute: {linkAttri.GetType().Name} but doesn't derive from Type: {linkAttri.BaseType.Name}. In derives from incorrect Type: {t.BaseType}");
  19.             }
  20.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement