ninject /src/Ninject.Tests/Unit/DisposableStrategyTests.cs

Language C# Lines 45
MD5 Hash fd7346a58088664dbb615112b4105af5
Repository https://github.com/developingchris/ninject.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using Moq;
using Ninject.Activation;
using Ninject.Activation.Strategies;
using Ninject.Infrastructure.Disposal;
using Ninject.Tests.Fakes;
using Xunit;
using Xunit.Should;

namespace Ninject.Tests.Unit.DisposableStrategyTests
{
	public class DisposableStrategyContext
	{
		protected readonly DisposableStrategy strategy;
		protected readonly Mock<IContext> contextMock;

		public DisposableStrategyContext()
		{
			contextMock = new Mock<IContext>();
			strategy = new DisposableStrategy();
		}
	}

	public class WhenDeactivateIsCalled : DisposableStrategyContext
	{
		[Fact]
		public void StrategyDisposesInstanceIfItIsDisposable()
		{
			var instance = new NotifiesWhenDisposed();
			var reference = new InstanceReference { Instance = instance };

			strategy.Deactivate(contextMock.Object, reference);
			instance.IsDisposed.ShouldBeTrue();
		}

		[Fact]
		public void StrategyDoesNotAttemptToDisposeInstanceIfItIsNotDisposable()
		{
			var instance = new object();
			var reference = new InstanceReference { Instance = instance };

			strategy.Deactivate(contextMock.Object, reference);
		}
	}
}
Back to Top