Ejemplo n.º 1
0
        public void RegisterInstance_ResolvingTypeAndInstanceObjectAsParameter_ShouldResolvePassedInstance()
        {
            var ioc = new ServiceContainer();

            var instance = new IocTest1();

            ioc.RegisterInstance <IIocTest1>(instance);
            var resolvedType = ioc.Resolve <IIocTest1>();

            resolvedType.Should().NotBeNull();
            resolvedType.Should().BeOfType <IocTest1>();

            resolvedType.Should().Be(instance);
        }
Ejemplo n.º 2
0
        public void RemoveService_ResolvingTypeAsParameter_ShouldThrowExceptionOnResolving()
        {
            var ioc = new ServiceContainer();

            var instance = new IocTest1();

            ioc.RegisterInstance <IIocTest1>(instance);
            var resolvedType = ioc.Resolve <IIocTest1>();

            ioc.RemoveService <IIocTest1>();
            Assert.Throws <ServiceNotRegisteredException>(() =>
            {
                ioc.Resolve <IIocTest1>();
            });
        }
Ejemplo n.º 3
0
        public void Resolve_ResolvingType_ShouldResolveTypeWithMultipleDependencies()
        {
            var ioc = new ServiceContainer();

            var instance = new IocTest1();

            ioc.RegisterInstance <IIocTest1, IocTest1>(instance);
            ioc.RegisterSingleton <IIocTest3, IocTest3>();
            ioc.RegisterTransient <IIocTest2, IocTest2>();

            var resolvedType = ioc.Resolve <IIocTest2>();

            resolvedType.Should().NotBeNull();
            resolvedType.Should().BeOfType <IocTest2>();

            resolvedType.Test1.Should().Be(ioc.Resolve <IIocTest1>());
            resolvedType.Test3.Should().Be(ioc.Resolve <IIocTest3>());
        }