/src/UnitTests/AOP/ParameterDefinitionExtensionTests.cs

http://github.com/philiplaureano/LinFu · C# · 35 lines · 28 code · 5 blank · 2 comment · 0 complexity · 8ae2a9fe7ed413ef14c238a9ea0307d0 MD5 · raw file

  1. using LinFu.Reflection.Emit;
  2. using Mono.Cecil;
  3. using Xunit;
  4. using SampleLibrary.AOP;
  5. namespace LinFu.UnitTests.AOP
  6. {
  7. public class ParameterDefinitionExtensionTests : BaseTestFixture
  8. {
  9. [Fact]
  10. public void ShouldBeAbleToDetermineIfMethodIsByRef()
  11. {
  12. var location = typeof(SampleClassWithByRefMethod).Assembly.Location;
  13. var assembly = AssemblyDefinition.ReadAssembly(location);
  14. var module = assembly.MainModule;
  15. var targetType = module.GetType("SampleClassWithByRefMethod");
  16. var byRefMethod = targetType.GetMethod("ByRefMethod");
  17. var regularMethod = targetType.GetMethod("NonByRefMethod");
  18. Assert.NotNull(assembly);
  19. Assert.NotNull(targetType);
  20. Assert.NotNull(byRefMethod);
  21. Assert.NotNull(regularMethod);
  22. // Test the byref parameter
  23. var parameter = byRefMethod.Parameters[0];
  24. Assert.True(parameter.IsByRef());
  25. // Test the non-byref parameter
  26. parameter = regularMethod.Parameters[0];
  27. Assert.False(parameter.IsByRef());
  28. }
  29. }
  30. }