public void GetConstructor_TypeWithMultiplePublicConstructors_ThrowsExpectedException() { // Arrange var behavior = GetContainerOptions().ConstructorResolutionBehavior; try { // Act behavior.GetConstructor(typeof(TypeWithMultiplePublicConstructors)); // Assert Assert.Fail("Exception expected."); } catch (ActivationException ex) { AssertThat.StringContains("For the container to be able to create " + "DefaultConstructorResolutionBehaviorTests.TypeWithMultiplePublicConstructors it " + "should have only one public constructor: it has 2.", ex.Message); } }
public void RegisterSingleOpenGeneric_ImplementationWithMultipleConstructors_ThrowsExpectedException() { // Arrange var container = ContainerFactory.New(); try { // Act container.RegisterSingleOpenGeneric(typeof(IService <,>), typeof(ServiceImplWithMultipleCtors <,>)); // Assert Assert.Fail("Exception expected."); } catch (ArgumentException ex) { AssertThat.StringContains(@" For the container to be able to create ServiceImplWithMultipleCtors<TA, TB>, it should contain exactly one public constructor, but it has 2.".TrimInside(), ex.Message); } }
public void GetConstructor_TypeWithSingleInternalConstructor_ThrowsExpectedException() { // Arrange var behavior = new ContainerOptions().ConstructorResolutionBehavior; try { // Act behavior.GetConstructor(typeof(TypeWithSingleInternalConstructor), typeof(TypeWithSingleInternalConstructor)); // Assert Assert.Fail("Exception expected."); } catch (ActivationException ex) { AssertThat.StringContains("For the container to be able to create " + "DefaultConstructorResolutionBehaviorTests.TypeWithSingleInternalConstructor, it should " + "contain exactly one public constructor, but it has 0.", ex.Message); } }
public void RegisterManyForOpenGeneric_WithNonInheritableType_ThrowsException() { // Arrange var container = ContainerFactory.New(); var serviceType = typeof(IService <,>); var validType = typeof(ServiceImpl <object, string>); var invalidType = typeof(List <int>); try { // Act container.RegisterManyForOpenGeneric(serviceType, validType, invalidType); // Assert Assert.Fail("Exception expected."); } catch (Exception ex) { AssertThat.StringContains("List<Int32>", ex.Message); AssertThat.StringContains("IService<TA, TB>", ex.Message); } }