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

Language C# Lines 47
MD5 Hash a04f39077662645b325fdd03186b09e8
Repository https://github.com/developingchris/ninject.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Reflection;
using Ninject.Planning.Directives;
using Ninject.Planning.Targets;
using Ninject.Tests.Fakes;
using Xunit;
using Xunit.Should;
using Ninject.Injection;

namespace Ninject.Tests.Unit.MethodInjectionDirectiveBaseTests
{
	public class MethodInjectionDirectiveBaseContext
	{
		protected FakeMethodInjectionDirective directive;
	}

	public class WhenDirectiveIsCreated : MethodInjectionDirectiveBaseContext
	{
		[Fact]
		public void CreatesTargetsForMethodParameters()
		{
			var method = typeof(Dummy).GetMethod("MethodA");
			MethodInjector injector = delegate { };

			directive = new FakeMethodInjectionDirective(method, injector);
			ITarget[] targets = directive.Targets;

			targets.Length.ShouldBe(3);
			targets[0].Name.ShouldBe("foo");
			targets[0].Type.ShouldBe(typeof(int));
			targets[1].Name.ShouldBe("bar");
			targets[1].Type.ShouldBe(typeof(string));
			targets[2].Name.ShouldBe("baz");
			targets[2].Type.ShouldBe(typeof(IWeapon));
		}
	}

	public class FakeMethodInjectionDirective : MethodInjectionDirectiveBase<MethodInfo, MethodInjector>
	{
		public FakeMethodInjectionDirective(MethodInfo method, MethodInjector injector) : base(method, injector) { }
	}

	public class Dummy
	{
		public void MethodA(int foo, string bar, IWeapon baz) { }
	}
}
Back to Top