PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Ninject.Test/Unit/MethodInjectionDirectiveBaseTests.cs

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