PageRenderTime 18ms CodeModel.GetById 2ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

/Source/Bifrost.Specs/Execution/for_TypeImporter/TypeImporterSpecs.cs

#
C# | 64 lines | 59 code | 5 blank | 0 comment | 0 complexity | 86fb717c769a327b8198a2c2ad6c4888 MD5 | raw file
 1using System;
 2using Bifrost.Execution;
 3using Moq;
 4using NUnit.Framework;
 5
 6namespace Bifrost.Specs.Execution.for_TypeImporter
 7{
 8	[TestFixture]
 9	public class TypeImporterSpecs
10	{
11		[Test]
12		public void ImportingMultipleShouldReturnAllInstances()
13		{
14		    var containerMock = new Mock<IContainer>();
15			var typeDiscovererMock = new Mock<ITypeDiscoverer>();
16			typeDiscovererMock.Setup(t => t.FindMultiple<IMultipleInterface>()).Returns(new[]
17			                                                                            	{
18																								typeof(FirstMultipleClass),
19																								typeof(SecondMultipleClass)
20			                                                                            	});
21			var typeImporter = new TypeImporter(containerMock.Object, typeDiscovererMock.Object);
22			var instances = typeImporter.ImportMany<IMultipleInterface>();
23			Assert.That(instances.Length, Is.EqualTo(2));
24			Assert.That(instances[0], Is.InstanceOf<FirstMultipleClass>());
25			Assert.That(instances[1], Is.InstanceOf<SecondMultipleClass>());
26		}
27
28		[Test]
29		public void ImportingMultipleAndThereIsOnlyOneShouldReturnThatInstance()
30		{
31            var containerMock = new Mock<IContainer>();
32			var typeDiscovererMock = new Mock<ITypeDiscoverer>();
33			typeDiscovererMock.Setup(t => t.FindMultiple<ISingleInterface>()).Returns(new[]
34			                                                                            	{
35																								typeof(SingleClass),
36			                                                                            	});
37			var typeImporter = new TypeImporter(containerMock.Object, typeDiscovererMock.Object);
38			var instances = typeImporter.ImportMany<ISingleInterface>();
39			Assert.That(instances.Length, Is.EqualTo(1));
40			Assert.That(instances[0], Is.InstanceOf<SingleClass>());
41		}
42
43		[Test, ExpectedException(typeof(ArgumentException))]
44		public void ImportingMultipleAndDiscovererReturnsNullShouldCauseAnArgumentException()
45		{
46            var containerMock = new Mock<IContainer>();
47			var typeDiscovererMock = new Mock<ITypeDiscoverer>();
48			typeDiscovererMock.Setup(t => t.FindMultiple<IMultipleInterface>()).Returns((Type[])null);
49			var typeImporter = new TypeImporter(containerMock.Object, typeDiscovererMock.Object);
50			typeImporter.ImportMany<IMultipleInterface>();
51		}
52
53		[Test, ExpectedException(typeof(ArgumentException))]
54		public void ImportingMultipleAndDiscovererThrowExceptionShouldCauseAnArgumentException()
55		{
56            var containerMock = new Mock<IContainer>();
57			var typeDiscovererMock = new Mock<ITypeDiscoverer>();
58			typeDiscovererMock.Setup(t => t.FindMultiple<IMultipleInterface>()).Throws(new ArgumentException());
59
60			var typeImporter = new TypeImporter(containerMock.Object, typeDiscovererMock.Object);
61			typeImporter.ImportMany<IMultipleInterface>();
62		}
63	}
64}