public void Container_Register_AddsMappingToList() { var container = new Yadndil.Container(); container.Register <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor, TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>(); Assert.AreEqual(1, container._mapping.Count); }
public void Container_Get_CanCallInterfaceMethod() { var container = new Yadndil.Container(); container.Register <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor, TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>(); var result = container.Get <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor>(); Assert.AreEqual("Hi!", result.PrintSomething()); }
public void Container_Get_ReturnsImplementationWhenConstructorIsEmpty() { var container = new Yadndil.Container(); container.Register <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor, TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>(); var result = container.Get <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor>(); Assert.IsInstanceOf <TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>(result); }
public void Container_Get_ExceptionWhenNotMapped() { var container = new Yadndil.Container(); Assert.Throws <Exception>(() => { container.Get <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor>(); }); }
public void Container_Get_ExceptionWhenFirstParameterIsNotInterface() { var container = new Yadndil.Container(); Assert.Throws <ArgumentException>(() => { container.Get <TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>(); }); }
public void Container_Register_ThrowsWhenInterfaceHasAlreadyBeenAdded() { var container = new Yadndil.Container(); Assert.Throws <Exception>(() => { container.Register <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor, TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>(); container.Register <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor, TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>(); }); }
public void Container_FinishRegistering_CircularReferenceCausesStackOverflow() { var container = new Yadndil.Container(); Assert.Throws <Exception>(() => { container.Register <TypesForTests.ContainerTestTypes.IInterafce1ForStackOverflow, TypesForTests.ContainerTestTypes.Class1ForStackOverflow>(); container.Register <TypesForTests.ContainerTestTypes.IInterafce2ForStackOverflow, TypesForTests.ContainerTestTypes.Class2ForStackOverflow>(); container.Get <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithNonEmptyConstructor>(); }); }