/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
- using System;
- using Ninject.Tests.Fakes;
- using Xunit;
- using Xunit.Should;
- namespace Ninject.Tests.Integration.ExternalInjectionTests
- {
- public class ExternalInjectionContext
- {
- protected readonly StandardKernel kernel;
- public ExternalInjectionContext()
- {
- kernel = new StandardKernel();
- }
- }
- 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; }
- }
- }