PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

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

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