PageRenderTime 46ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Ninject.Tests/Unit/MethodInjectionDirectiveBaseTests.cs

https://github.com/developingchris/ninject
C# | 47 lines | 41 code | 6 blank | 0 comment | 0 complexity | d3f81b668eea3c0040da8530981ec2e7 MD5 | raw file
  1. using System;
  2. using System.Reflection;
  3. using Ninject.Planning.Directives;
  4. using Ninject.Planning.Targets;
  5. using Ninject.Tests.Fakes;
  6. using Xunit;
  7. using Xunit.Should;
  8. using Ninject.Injection;
  9. namespace Ninject.Tests.Unit.MethodInjectionDirectiveBaseTests
  10. {
  11. public class MethodInjectionDirectiveBaseContext
  12. {
  13. protected FakeMethodInjectionDirective directive;
  14. }
  15. public class WhenDirectiveIsCreated : MethodInjectionDirectiveBaseContext
  16. {
  17. [Fact]
  18. public void CreatesTargetsForMethodParameters()
  19. {
  20. var method = typeof(Dummy).GetMethod("MethodA");
  21. MethodInjector injector = delegate { };
  22. directive = new FakeMethodInjectionDirective(method, injector);
  23. ITarget[] targets = directive.Targets;
  24. targets.Length.ShouldBe(3);
  25. targets[0].Name.ShouldBe("foo");
  26. targets[0].Type.ShouldBe(typeof(int));
  27. targets[1].Name.ShouldBe("bar");
  28. targets[1].Type.ShouldBe(typeof(string));
  29. targets[2].Name.ShouldBe("baz");
  30. targets[2].Type.ShouldBe(typeof(IWeapon));
  31. }
  32. }
  33. public class FakeMethodInjectionDirective : MethodInjectionDirectiveBase<MethodInfo, MethodInjector>
  34. {
  35. public FakeMethodInjectionDirective(MethodInfo method, MethodInjector injector) : base(method, injector) { }
  36. }
  37. public class Dummy
  38. {
  39. public void MethodA(int foo, string bar, IWeapon baz) { }
  40. }
  41. }