A lightweight IOC Container that is powerful enough to do all the things you need it to do.
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.

75 lines
2.0 KiB

// Author: Gockner, Simon
// Created: 2019-06-12
// Copyright(c) 2019 SimonG. All Rights Reserved.
using System.Reflection;
using JetBrains.Annotations;
using LightweightIocContainer;
using LightweightIocContainer.Installers;
using LightweightIocContainer.Interfaces;
using LightweightIocContainer.Interfaces.Installers;
using LightweightIocContainer.Interfaces.Registrations;
using NSubstitute;
using NUnit.Framework;
namespace Test.LightweightIocContainer;
[TestFixture]
public class AssemblyInstallerTest
{
[UsedImplicitly]
public class TestInstaller : IIocInstaller
{
public void Install(IRegistrationCollector registration) => registration.Add<IRegistration>();
}
[UsedImplicitly]
public class AssemblyWrapper : Assembly
{
}
[Test]
public void TestInstall()
{
List<Type> types =
[
typeof(object),
typeof(TestInstaller)
];
AssemblyWrapper assemblyMock = Substitute.For<AssemblyWrapper>();
assemblyMock.GetTypes().Returns(types.ToArray());
IRegistrationCollector registrationCollectorMock = Substitute.For<IRegistrationCollector>();
AssemblyInstaller assemblyInstaller = new(assemblyMock);
assemblyInstaller.Install(registrationCollectorMock);
registrationCollectorMock.Received(1).Add<IRegistration>(Arg.Any<Lifestyle>());
}
[Test]
public void TestFromAssemblyThis()
{
IIocContainer iocContainer = new IocContainer();
iocContainer.Install(FromAssembly.This());
}
[Test]
public void TestFromAssemblyInstance()
{
List<Type> types =
[
typeof(object),
typeof(TestInstaller)
];
AssemblyWrapper assemblyMock = Substitute.For<AssemblyWrapper>();
assemblyMock.GetTypes().Returns(types.ToArray());
IIocContainer iocContainer = new IocContainer();
iocContainer.Install(FromAssembly.Instance(assemblyMock));
}
}