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

Language C# Lines 65
MD5 Hash b26c2a3efeae1b75c3040c1b18a96d12
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
using System;
using System.Collections.Generic;
using System.Linq;
using Moq;
using Ninject.Activation;
using Ninject.Activation.Strategies;
using Xunit;
using Xunit.Should;

namespace Ninject.Tests.Unit.PipelineTests
{
	public class PipelineContext
	{
		protected readonly List<Mock<IActivationStrategy>> strategyMocks = new List<Mock<IActivationStrategy>>();
		protected readonly Pipeline pipeline;

		public PipelineContext()
		{
			strategyMocks.Add(new Mock<IActivationStrategy>());
			strategyMocks.Add(new Mock<IActivationStrategy>());
			strategyMocks.Add(new Mock<IActivationStrategy>());
			pipeline = new Pipeline(strategyMocks.Select(mock => mock.Object));
		}
	}

	public class WhenPipelineIsCreated : PipelineContext
	{
		[Fact]
		public void HasListOfStrategies()
		{
			pipeline.Strategies.ShouldNotBeNull();

			for (int idx = 0; idx < strategyMocks.Count; idx++)
				pipeline.Strategies[idx].ShouldBeSameAs(strategyMocks[idx].Object);
		}
	}

	public class WhenActivateIsCalled : PipelineContext
	{
		[Fact]
		public void CallsActivateOnStrategies()
		{
			var contextMock = new Mock<IContext>();
			var reference = new InstanceReference();

			pipeline.Activate(contextMock.Object, reference);

			strategyMocks.Map(mock => mock.Verify(x => x.Activate(contextMock.Object, reference)));
		}
	}

	public class WhenDeactivateIsCalled : PipelineContext
	{
		[Fact]
		public void CallsDeactivateOnStrategies()
		{
			var contextMock = new Mock<IContext>();
			var reference = new InstanceReference();

			pipeline.Deactivate(contextMock.Object, reference);

			strategyMocks.Map(mock => mock.Verify(x => x.Deactivate(contextMock.Object, reference)));
		}
	}
}
Back to Top