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); }
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>(); }); }
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>()); }