PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Ninject.Tests/Integration/ManualReleaseTests.cs

https://github.com/daniyord/ninject
C# | 47 lines | 38 code | 9 blank | 0 comment | 0 complexity | 880f0d5a46bb98f5f7babbc43c7b93a2 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. using System;
  2. using Ninject.Tests.Fakes;
  3. using Xunit;
  4. using Xunit.Should;
  5. namespace Ninject.Tests.Integration.ManualReleaseTests
  6. {
  7. public class ManualReleaseContext
  8. {
  9. protected readonly StandardKernel kernel;
  10. public ManualReleaseContext()
  11. {
  12. kernel = new StandardKernel();
  13. }
  14. }
  15. public class WhenReleaseIsCalled : ManualReleaseContext
  16. {
  17. [Fact]
  18. public void InstanceIsDeactivated()
  19. {
  20. kernel.Bind<NotifiesWhenDisposed>().ToSelf().InSingletonScope();
  21. var instance = kernel.Get<NotifiesWhenDisposed>();
  22. kernel.Release(instance);
  23. instance.IsDisposed.ShouldBeTrue();
  24. }
  25. [Fact]
  26. public void InstanceIsRemovedFromCache()
  27. {
  28. kernel.Bind<NotifiesWhenDisposed>().ToSelf().InSingletonScope();
  29. var instance1 = kernel.Get<NotifiesWhenDisposed>();
  30. var instance2 = kernel.Get<NotifiesWhenDisposed>();
  31. instance1.ShouldBeSameAs(instance2);
  32. kernel.Release(instance1);
  33. var instance3 = kernel.Get<NotifiesWhenDisposed>();
  34. instance3.ShouldNotBeSameAs(instance1);
  35. instance3.ShouldNotBeSameAs(instance2);
  36. }
  37. }
  38. }