/src/Ninject.Test/Integration/ExternalInjectionTests.cs
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
- namespace Ninject.Tests.Integration.ExternalInjectionTests
- {
- using Ninject.Tests.Fakes;
- #if SILVERLIGHT
- #if SILVERLIGHT_MSTEST
- using MsTest.Should;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using Fact = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
- #else
- using UnitDriven;
- using UnitDriven.Should;
- using Fact = UnitDriven.TestMethodAttribute;
- #endif
- #else
- using Ninject.Tests.MSTestAttributes;
- using Xunit;
- using Xunit.Should;
- #endif
- public class ExternalInjectionContext
- {
- protected StandardKernel kernel;
- public ExternalInjectionContext()
- {
- this.SetUp();
- }
- [TestInitialize]
- public void SetUp()
- {
- this.kernel = new StandardKernel();
- }
- }
- [TestClass]
- public class WhenInjectIsCalled : ExternalInjectionContext
- {
- [Fact]
- public void InstanceOfKernelIsInjected()
- {
- kernel.Bind<IWeapon>().To<Sword>();
- var warrior = new ExternalWarrior();
- kernel.Inject(warrior);
- warrior.Weapon.ShouldNotBeNull();
- warrior.Weapon.ShouldBeInstanceOf<Sword>();
- }
- [Fact]
- public void InstanceIsNotTrackedForDeactivation()
- {
- var instance = new NotifiesWhenDisposed();
- kernel.Inject(instance);
- kernel.Dispose();
- instance.IsDisposed.ShouldBeFalse();
- }
- }
- public class ExternalWarrior
- {
- [Inject] public IWeapon Weapon { get; set; }
- }
- }