// Author: Gockner, Simon // Created: 2019-06-12 // Copyright(c) 2019 SimonG. All Rights Reserved. using System; using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; using LightweightIocContainer; using LightweightIocContainer.Installers; using LightweightIocContainer.Interfaces; using LightweightIocContainer.Interfaces.Installers; using LightweightIocContainer.Interfaces.Registrations; using Moq; using NUnit.Framework; namespace Test.LightweightIocContainer { [TestFixture] public class AssemblyInstallerTest { #region TestClasses private class TestInstaller : IIocInstaller { public void Install(IIocContainer container) { container.Register>(); } } [UsedImplicitly] public class AssemblyWrapper : Assembly { } #endregion TestClasses [Test] public void TestInstall() { List types = new List { typeof(object), typeof(TestInstaller) }; Mock assemblyMock = new Mock(); assemblyMock.Setup(a => a.GetTypes()).Returns(types.ToArray); Mock iocContainerMock = new Mock(); AssemblyInstaller assemblyInstaller = new AssemblyInstaller(assemblyMock.Object); assemblyInstaller.Install(iocContainerMock.Object); iocContainerMock.Verify(ioc => ioc.Register>>(It.IsAny()), Times.Once); } [Test] public void TestFromAssemblyThis() { IIocContainer iocContainer = new IocContainer(); iocContainer.Install(FromAssembly.This()); } [Test] public void TestFromAssemblyInstance() { List types = new List { typeof(object), typeof(TestInstaller) }; Mock assemblyMock = new Mock(); assemblyMock.Setup(a => a.GetTypes()).Returns(types.ToArray); IIocContainer iocContainer = new IocContainer(); iocContainer.Install(FromAssembly.Instance(assemblyMock.Object)); } } }