PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Ninject.Test/Unit/AssemblyNameRetrieverTests.cs

http://github.com/ninject/ninject
C# | 49 lines | 42 code | 7 blank | 0 comment | 0 complexity | 2dfd3a35e4f3e291f04123710f562c7a MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. namespace Ninject.Tests.Unit
  2. {
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using FluentAssertions;
  8. using Ninject.Modules;
  9. using Xunit;
  10. public class AssemblyNameRetrieverContext
  11. {
  12. protected readonly AssemblyNameRetriever AssemblyNameRetriever;
  13. protected readonly string ModuleFilename = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), @"Ninject.Tests.TestModule.dll");
  14. protected readonly string AssemblyFilename = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), @"Ninject.Tests.TestAssembly.dll");
  15. public AssemblyNameRetrieverContext()
  16. {
  17. this.AssemblyNameRetriever = new AssemblyNameRetriever();
  18. }
  19. }
  20. public class WhenGetAssemblyNamesIsCalledWithFileName : AssemblyNameRetrieverContext
  21. {
  22. [Fact]
  23. public void AssemblyNamesOfMatchingAssembliesAreReturned()
  24. {
  25. var expected = Assembly.LoadFrom(this.ModuleFilename).GetName();
  26. var actualNames = this.AssemblyNameRetriever.GetAssemblyNames(
  27. new[] { this.ModuleFilename, this.AssemblyFilename },
  28. asm => asm.FullName.StartsWith("Ninject.Tests.TestModule"));
  29. var assemblyFullNames = actualNames.Select(a => a.FullName).ToList();
  30. assemblyFullNames.Should().BeEquivalentTo(new[] { expected.FullName });
  31. }
  32. }
  33. public class WhenGetAssemblyNamesIsCalledWithUnknownAssemblyName : AssemblyNameRetrieverContext
  34. {
  35. [Fact]
  36. public void WillBeIgnored()
  37. {
  38. var actualNames = this.AssemblyNameRetriever.GetAssemblyNames(new[] { "Blah" }, asm => true);
  39. actualNames.Should().BeEmpty();
  40. }
  41. }
  42. }