PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Ninject.Test/Integration/ExternalInjectionTests.cs

https://github.com/bartelink/ninject
C# | 67 lines | 57 code | 10 blank | 0 comment | 0 complexity | 4bc156d9338e4f384bf22fcc89e15a19 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0
  1. namespace Ninject.Tests.Integration.ExternalInjectionTests
  2. {
  3. using Ninject.Tests.Fakes;
  4. #if SILVERLIGHT
  5. #if SILVERLIGHT_MSTEST
  6. using MsTest.Should;
  7. using Microsoft.VisualStudio.TestTools.UnitTesting;
  8. using Fact = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
  9. #else
  10. using UnitDriven;
  11. using UnitDriven.Should;
  12. using Fact = UnitDriven.TestMethodAttribute;
  13. #endif
  14. #else
  15. using Ninject.Tests.MSTestAttributes;
  16. using Xunit;
  17. using Xunit.Should;
  18. #endif
  19. public class ExternalInjectionContext
  20. {
  21. protected StandardKernel kernel;
  22. public ExternalInjectionContext()
  23. {
  24. this.SetUp();
  25. }
  26. [TestInitialize]
  27. public void SetUp()
  28. {
  29. this.kernel = new StandardKernel();
  30. }
  31. }
  32. [TestClass]
  33. public class WhenInjectIsCalled : ExternalInjectionContext
  34. {
  35. [Fact]
  36. public void InstanceOfKernelIsInjected()
  37. {
  38. kernel.Bind<IWeapon>().To<Sword>();
  39. var warrior = new ExternalWarrior();
  40. kernel.Inject(warrior);
  41. warrior.Weapon.ShouldNotBeNull();
  42. warrior.Weapon.ShouldBeInstanceOf<Sword>();
  43. }
  44. [Fact]
  45. public void InstanceIsNotTrackedForDeactivation()
  46. {
  47. var instance = new NotifiesWhenDisposed();
  48. kernel.Inject(instance);
  49. kernel.Dispose();
  50. instance.IsDisposed.ShouldBeFalse();
  51. }
  52. }
  53. public class ExternalWarrior
  54. {
  55. [Inject] public IWeapon Weapon { get; set; }
  56. }
  57. }