PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/developingchris/ninject
C# | 51 lines | 44 code | 7 blank | 0 comment | 0 complexity | 843c2ab6f584b0b11f58831a52a1cb11 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using Moq;
  6. using Ninject.Components;
  7. using Ninject.Modules;
  8. using Xunit;
  9. namespace Ninject.Tests.Unit.ModuleLoaderTests
  10. {
  11. public class ModuleLoaderContext
  12. {
  13. protected readonly ModuleLoader moduleLoader;
  14. protected readonly Mock<IKernel> kernelMock;
  15. protected readonly Mock<IComponentContainer> componentsMock;
  16. protected readonly Mock<IModuleLoaderPlugin> fooPluginMock;
  17. protected readonly Mock<IModuleLoaderPlugin> barPluginMock;
  18. public ModuleLoaderContext()
  19. {
  20. kernelMock = new Mock<IKernel>();
  21. componentsMock = new Mock<IComponentContainer>();
  22. fooPluginMock = new Mock<IModuleLoaderPlugin>();
  23. barPluginMock = new Mock<IModuleLoaderPlugin>();
  24. moduleLoader = new ModuleLoader(kernelMock.Object);
  25. var plugins = new[] { fooPluginMock.Object, barPluginMock.Object };
  26. kernelMock.SetupGet(x => x.Components).Returns(componentsMock.Object);
  27. componentsMock.Setup(x => x.GetAll<IModuleLoaderPlugin>()).Returns(plugins);
  28. fooPluginMock.SetupGet(x => x.SupportedExtensions).Returns(new[] { ".foo" });
  29. barPluginMock.SetupGet(x => x.SupportedExtensions).Returns(new[] { ".bar" });
  30. }
  31. }
  32. public class WhenLoadModulesIsCalled : ModuleLoaderContext
  33. {
  34. [Fact(Skip = "Moq throwing exception, need to investigate")]
  35. public void PassesMatchingFilesToAppropriatePlugin()
  36. {
  37. moduleLoader.LoadModules(new[] { "TestModules/*" });
  38. var fooFiles = new[] { Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"TestModules\test.foo") };
  39. var barFiles = new[] { Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"TestModules\test.bar") };
  40. fooPluginMock.Verify(x => x.LoadModules(It.Is<IEnumerable<string>>(e => e.SequenceEqual(fooFiles))));
  41. barPluginMock.Verify(x => x.LoadModules(It.Is<IEnumerable<string>>(e => e.SequenceEqual(barFiles))));
  42. }
  43. }
  44. }