PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Ninject.Test/Integration/WhenReleasingAnObject.cs

https://github.com/wjkhappy14/ninject
C# | 64 lines | 47 code | 17 blank | 0 comment | 0 complexity | 30f76655f6e0fe421e9d3d37f65cd743 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. namespace Ninject.Tests.Integration
  2. {
  3. using System;
  4. using FluentAssertions;
  5. using Xunit;
  6. public class WhenReleasingAnObject
  7. {
  8. private Foo foo;
  9. private StandardKernel kernel;
  10. public WhenReleasingAnObject()
  11. {
  12. this.kernel = new StandardKernel();
  13. this.kernel.Bind<Foo>().ToSelf().InSingletonScope();
  14. this.kernel.Bind<Bar>().ToSelf().InScope(ctx => this.foo);
  15. this.foo = this.kernel.Get<Foo>();
  16. }
  17. [Fact]
  18. public void ItIsDisposed()
  19. {
  20. this.kernel.Release(this.foo);
  21. this.foo.Disposed.Should().BeTrue();
  22. }
  23. [Fact]
  24. public void ObjectsThatHaveItAsScopeAreDisposed()
  25. {
  26. var bar = kernel.Get<Bar>();
  27. this.kernel.Release(this.foo);
  28. bar.Disposed.Should().BeTrue();
  29. }
  30. public class Foo : IDisposable
  31. {
  32. public void Dispose()
  33. {
  34. this.Disposed = true;
  35. }
  36. public bool Disposed { get; set; }
  37. }
  38. public class Bar : IDisposable
  39. {
  40. public void Dispose()
  41. {
  42. this.Disposed = true;
  43. }
  44. public bool Disposed { get; set; }
  45. }
  46. }
  47. }