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

/src/Ninject.Test/Unit/CompiledModuleLoaderPluginTests.cs

http://github.com/ninject/ninject
C# | 51 lines | 45 code | 6 blank | 0 comment | 1 complexity | ef94ea811b7b12c851617da54b028866 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. namespace Ninject.Tests.Unit.CompiledModuleLoaderPluginTests
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Reflection;
  8. using FluentAssertions;
  9. using Moq;
  10. using Ninject.Modules;
  11. using Xunit;
  12. public class CompiledModuleLoaderPluginContext
  13. {
  14. protected readonly CompiledModuleLoaderPlugin loaderPlugin;
  15. protected readonly Mock<IKernel> kernelMock;
  16. protected readonly string moduleFilename = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), @"Ninject.Tests.TestModule.dll");
  17. protected readonly string assemblyFilename = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), @"Ninject.Tests.TestAssembly.dll");
  18. public CompiledModuleLoaderPluginContext()
  19. {
  20. this.kernelMock = new Mock<IKernel>();
  21. this.loaderPlugin = new CompiledModuleLoaderPlugin(this.kernelMock.Object, new AssemblyNameRetriever());
  22. }
  23. }
  24. public class WhenLoadModulesIsCalled : CompiledModuleLoaderPluginContext
  25. {
  26. [Fact]
  27. public void CallsLoadMethodOnKernelWithAssemblies()
  28. {
  29. var expected = Assembly.LoadFrom(this.moduleFilename).GetName().Name;
  30. IEnumerable<Assembly> actual = null;
  31. this.kernelMock.Setup(x => x.Load(It.IsAny<IEnumerable<Assembly>>()))
  32. .Callback<IEnumerable<Assembly>>(m => actual = m);
  33. this.loaderPlugin.LoadModules(new[] { this.moduleFilename });
  34. actual.Should().NotBeNull();
  35. actual.Count().Should().Be(1);
  36. actual.Where(a => a.GetName().Name == expected).Should().NotBeEmpty();
  37. }
  38. [Fact]
  39. public void DoesNotLoadAssembliesWithoutModules()
  40. {
  41. this.loaderPlugin.LoadModules(new[] { this.assemblyFilename });
  42. this.kernelMock.Verify(k => k.Load(It.Is<IEnumerable<Assembly>>(p => p.Any())), Times.Never());
  43. }
  44. }
  45. }