public void RemoveInstance_Should_Throw_Exception_When_Type_Is_Not_Registered() { // Arrange var container = ContainerFactory.Create(); // Act // Assert ExceptionAssert.Thrown <ContainerException>( container.RemoveInstance <IContainerTestInterface>, "Container does not contain 'Agero.Core.DIContainer.Tests.Types.IContainerTestInterface' type as a key."); }
public void CreateInstance_Should_Throw_Exception_When_Type_Has_Ambiguous_Constructors() { // Arrange var container = ContainerFactory.Create(); // Act // Assert ExceptionAssert.Thrown <ContainerException>( () => container.CreateInstance <ContainerTestClassWithAmbiguousConstructors>(), "Ambiguous usage of 'Inject' attribute on constructors of type 'Agero.Core.DIContainer.Tests.Types.ContainerTestClassWithAmbiguousConstructors'." + " Only one constructor can be marked with 'Inject' attribute."); }
public void RemoveInstance_Should_Throw_Exception_When_FactoryMethod_Is_Registered_Per_Container_And_Instance_Is_Not_Created() { // Arrange var container = ContainerFactory.Create(); container.RegisterFactoryMethod <IContainerTestInterface>(c => new ContainerTestClass(), Lifetime.PerContainer); // Act // Assert ExceptionAssert.Thrown <ContainerException>( container.RemoveInstance <IContainerTestInterface>, "Container does not contain an instance of 'Agero.Core.DIContainer.Tests.Types.IContainerTestInterface' type."); }
public void RegisterInstance_Should_Throw_Exception_When_Instance_Is_Already_Registered() { // Arrange var container = ContainerFactory.Create(); container.RegisterInstance <IContainerTestInterface>(new ContainerTestClass()); // Act // Assert ExceptionAssert.Thrown <ContainerException>( () => container.RegisterInstance <IContainerTestInterface>(new ContainerTestClass()), "Container already contains 'Agero.Core.DIContainer.Tests.Types.IContainerTestInterface' type as a key."); }
public void CreateInstance_Should_Throw_Exception_When_UnknownInstances_Has_More_Than_One_Entry_Of_The_Same_Type() { // Arrange var container = ContainerFactory.Create(); var unknownInstance1 = new ContainerUnknownInstanceTestClass(); var unknownInstance2 = new ContainerUnknownInstanceTestClass(); // Act // Assert ExceptionAssert.Thrown <ArgumentException>( () => container.CreateInstance <ContainerTestClassWithUnknownInstance>(unknownInstance1, unknownInstance2), $"unknownInstances has more than one entry of the same type.{Environment.NewLine}Parameter name: unknownInstances"); }
public void RemoveInstance_Should_Throw_Exception_When_Implementation_Is_Registered_Per_Call() { // Arrange var container = ContainerFactory.Create(); container.RegisterImplementation <IContainerTestInterface, ContainerTestClass>(); container.Get <IContainerTestInterface>(); // Act // Assert ExceptionAssert.Thrown <ContainerException>( container.RemoveInstance <IContainerTestInterface>, "Container does not contain an instance of 'Agero.Core.DIContainer.Tests.Types.IContainerTestInterface' type."); }
public void CreateInstance_Should_Throw_Exception_When_Property_Injected_Instance_Is_Not_Registered() { // Arrange var container = ContainerFactory.Create(); container.RegisterImplementation <IContainerTestInterface, ContainerTestClass>(); // Act // Assert ExceptionAssert.Thrown <ContainerException>( () => container.CreateInstance <ContainerTestClassWithInjectedInstances>(), "The property types (Agero.Core.DIContainer.Tests.Types.IContainerTestInterface2) of type" + " 'Agero.Core.DIContainer.Tests.Types.ContainerTestClassWithInjectedInstances' are not registered" + " in the container or not passed as unknown instances."); }
public void CreateInstance_Should_Throw_Exception_When_Constructor_Injected_Instance_Is_Not_Registered() { // Arrange var container = ContainerFactory.Create(); container.RegisterImplementation <IContainerTestInterface2, ContainerTestClass2>(); // Act // Assert ExceptionAssert.Thrown <ContainerException>( () => container.CreateInstance <ContainerTestClassWithInjectedInstances>(), "The types (Agero.Core.DIContainer.Tests.Types.IContainerTestInterface) which" + " are the parameters of constructor of type 'Agero.Core.DIContainer.Tests.Types.ContainerTestClassWithInjectedInstances'" + " are not registered in the container or not passed as unknown instances."); }