You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.3 KiB
83 lines
2.3 KiB
// 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<Mock<IRegistrationBase>>();
|
|
}
|
|
}
|
|
|
|
[UsedImplicitly]
|
|
public class AssemblyWrapper : Assembly
|
|
{
|
|
|
|
}
|
|
|
|
#endregion TestClasses
|
|
|
|
[Test]
|
|
public void TestInstall()
|
|
{
|
|
List<Type> types = new List<Type>
|
|
{
|
|
typeof(object),
|
|
typeof(TestInstaller)
|
|
};
|
|
|
|
Mock<AssemblyWrapper> assemblyMock = new Mock<AssemblyWrapper>();
|
|
assemblyMock.Setup(a => a.GetTypes()).Returns(types.ToArray);
|
|
|
|
Mock<IIocContainer> iocContainerMock = new Mock<IIocContainer>();
|
|
|
|
AssemblyInstaller assemblyInstaller = new AssemblyInstaller(assemblyMock.Object);
|
|
assemblyInstaller.Install(iocContainerMock.Object);
|
|
|
|
iocContainerMock.Verify(ioc => ioc.Register<It.IsSubtype<Mock<IRegistrationBase>>>(It.IsAny<Lifestyle>()), Times.Once);
|
|
}
|
|
|
|
[Test]
|
|
public void TestFromAssemblyThis()
|
|
{
|
|
IIocContainer iocContainer = new IocContainer();
|
|
iocContainer.Install(FromAssembly.This());
|
|
}
|
|
|
|
[Test]
|
|
public void TestFromAssemblyInstance()
|
|
{
|
|
List<Type> types = new List<Type>
|
|
{
|
|
typeof(object),
|
|
typeof(TestInstaller)
|
|
};
|
|
|
|
Mock<AssemblyWrapper> assemblyMock = new Mock<AssemblyWrapper>();
|
|
assemblyMock.Setup(a => a.GetTypes()).Returns(types.ToArray);
|
|
|
|
IIocContainer iocContainer = new IocContainer();
|
|
iocContainer.Install(FromAssembly.Instance(assemblyMock.Object));
|
|
}
|
|
}
|
|
} |