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

Language C# Lines 51
MD5 Hash 30f7592eec72f111361e07b3db1f44c1
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
48
49
50
51
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Moq;
using Ninject.Components;
using Ninject.Modules;
using Xunit;

namespace Ninject.Tests.Unit.ModuleLoaderTests
{
	public class ModuleLoaderContext
	{
		protected readonly ModuleLoader moduleLoader;
		protected readonly Mock<IKernel> kernelMock;
		protected readonly Mock<IComponentContainer> componentsMock;
		protected readonly Mock<IModuleLoaderPlugin> fooPluginMock;
		protected readonly Mock<IModuleLoaderPlugin> barPluginMock;

		public ModuleLoaderContext()
		{
			kernelMock = new Mock<IKernel>();
			componentsMock = new Mock<IComponentContainer>();
			fooPluginMock = new Mock<IModuleLoaderPlugin>();
			barPluginMock = new Mock<IModuleLoaderPlugin>();
			moduleLoader = new ModuleLoader(kernelMock.Object);

			var plugins = new[] { fooPluginMock.Object, barPluginMock.Object };

			kernelMock.SetupGet(x => x.Components).Returns(componentsMock.Object);
			componentsMock.Setup(x => x.GetAll<IModuleLoaderPlugin>()).Returns(plugins);
			fooPluginMock.SetupGet(x => x.SupportedExtensions).Returns(new[] { ".foo" });
			barPluginMock.SetupGet(x => x.SupportedExtensions).Returns(new[] { ".bar" });
		}
	}

	public class WhenLoadModulesIsCalled : ModuleLoaderContext
	{
		[Fact(Skip = "Moq throwing exception, need to investigate")]
		public void PassesMatchingFilesToAppropriatePlugin()
		{
			moduleLoader.LoadModules(new[] { "TestModules/*" });

			var fooFiles = new[] { Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"TestModules\test.foo") };
			var barFiles = new[] { Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"TestModules\test.bar") };

			fooPluginMock.Verify(x => x.LoadModules(It.Is<IEnumerable<string>>(e => e.SequenceEqual(fooFiles))));
			barPluginMock.Verify(x => x.LoadModules(It.Is<IEnumerable<string>>(e => e.SequenceEqual(barFiles))));
		}
	}
}
Back to Top