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

/src/Ninject.Tests/Integration/ExternalInjectionTests.cs

https://github.com/developingchris/ninject
C# | 48 lines | 39 code | 9 blank | 0 comment | 0 complexity | d562ab07cc1d1f53cd4df389a4d1246f MD5 | raw file
  1. using System;
  2. using Ninject.Tests.Fakes;
  3. using Xunit;
  4. using Xunit.Should;
  5. namespace Ninject.Tests.Integration.ExternalInjectionTests
  6. {
  7. public class ExternalInjectionContext
  8. {
  9. protected readonly StandardKernel kernel;
  10. public ExternalInjectionContext()
  11. {
  12. kernel = new StandardKernel();
  13. }
  14. }
  15. public class WhenInjectIsCalled : ExternalInjectionContext
  16. {
  17. [Fact]
  18. public void InstanceOfKernelIsInjected()
  19. {
  20. kernel.Bind<IWeapon>().To<Sword>();
  21. var warrior = new ExternalWarrior();
  22. kernel.Inject(warrior);
  23. warrior.Weapon.ShouldNotBeNull();
  24. warrior.Weapon.ShouldBeInstanceOf<Sword>();
  25. }
  26. [Fact]
  27. public void InstanceIsNotTrackedForDeactivation()
  28. {
  29. var instance = new NotifiesWhenDisposed();
  30. kernel.Inject(instance);
  31. kernel.Dispose();
  32. instance.IsDisposed.ShouldBeFalse();
  33. }
  34. }
  35. public class ExternalWarrior
  36. {
  37. [Inject] public IWeapon Weapon { get; set; }
  38. }
  39. }