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

Language C# Lines 53
MD5 Hash 4cd7381c856c224ef7a6eaee73555de6
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
46
47
48
49
50
51
52
53
using System;
using Moq;
using Ninject.Activation;
using Ninject.Activation.Strategies;
using Xunit;
using Xunit.Should;

namespace Ninject.Tests.Unit.InitializableStrategyTests
{
	public class InitializableStrategyContext
	{
		protected readonly InitializableStrategy strategy;
		protected readonly Mock<IContext> contextMock;

		public InitializableStrategyContext()
		{
			contextMock = new Mock<IContext>();
			strategy = new InitializableStrategy();
		}
	}

	public class WhenActivateIsCalled : InitializableStrategyContext
	{
		[Fact]
		public void StrategyInitializesInstanceIfItIsInitializable()
		{
			var instance = new InitializableObject();
			var reference = new InstanceReference { Instance = instance };

			strategy.Activate(contextMock.Object, reference);
			instance.WasInitialized.ShouldBeTrue();
		}

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

			strategy.Activate(contextMock.Object, reference);
		}
	}

	public class InitializableObject : IInitializable
	{
		public bool WasInitialized { get; set; }

		public void Initialize()
		{
			WasInitialized = true;
		}
	}
}
Back to Top