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

Language C# Lines 66
MD5 Hash 31f9bc88e1faa66d1928fdbfd5a412ab
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
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using Moq;
using Ninject.Activation;
using Ninject.Activation.Strategies;
using Ninject.Planning.Bindings;
using Xunit;
using Xunit.Should;

namespace Ninject.Tests.Unit.BindingActionStrategyTests
{
	public class BindingActionStrategyContext
	{
		protected readonly BindingActionStrategy strategy;
		protected readonly Mock<IContext> contextMock;
		protected readonly Mock<IBinding> bindingMock;

		public BindingActionStrategyContext()
		{
			contextMock = new Mock<IContext>();
			bindingMock = new Mock<IBinding>();
			strategy = new BindingActionStrategy();
		}
	}

	public class WhenActivateIsCalled : BindingActionStrategyContext
	{
		[Fact]
		public void StrategyInvokesActivationActionsDefinedInBinding()
		{
			bool action1WasCalled = false;
			bool action2WasCalled = false;

			Action<object> action1 = c => action1WasCalled = true;
			Action<object> action2 = c => action2WasCalled = true;
			var actions = new[] { action1, action2 };

			contextMock.SetupGet(x => x.Binding).Returns(bindingMock.Object);
			bindingMock.SetupGet(x => x.ActivationActions).Returns(actions);
			strategy.Activate(contextMock.Object, new InstanceReference());

			action1WasCalled.ShouldBeTrue();
			action2WasCalled.ShouldBeTrue();
		}
	}

	public class WhenDeactivateIsCalled : BindingActionStrategyContext
	{
		[Fact]
		public void StrategyInvokesDeactivationActionsDefinedInBinding()
		{
			bool action1WasCalled = false;
			bool action2WasCalled = false;

			Action<object> action1 = c => action1WasCalled = true;
			Action<object> action2 = c => action2WasCalled = true;
			var actions = new[] { action1, action2 };

			contextMock.SetupGet(x => x.Binding).Returns(bindingMock.Object);
			bindingMock.SetupGet(x => x.DeactivationActions).Returns(actions);
			strategy.Deactivate(contextMock.Object, new InstanceReference());

			action1WasCalled.ShouldBeTrue();
			action2WasCalled.ShouldBeTrue();
		}
	}
}
Back to Top