public void ExceptionThrownWhileResolvingAPropertyValueIsBubbledUpAndTheCurrentOperationIsNotCleared() { var exception = new ArgumentException(); var resolverPolicy = new ExceptionThrowingTestResolverPolicy(exception); MockBuilderContext context = GetContext(); var key = new NamedTypeBuildKey <OnePropertyClass>(); context.BuildKey = key; context.Existing = new OnePropertyClass(); context.Policies.Set <IPropertySelectorPolicy>( new TestSinglePropertySelectorPolicy <OnePropertyClass>(resolverPolicy), key); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, key); try { plan.BuildUp(context); Assert.Fail("failure expected"); } catch (Exception e) { Assert.AreSame(exception, e); var operation = (ResolvingPropertyValueOperation)context.CurrentOperation; Assert.IsNotNull(operation); Assert.AreSame(typeof(OnePropertyClass), operation.TypeBeingConstructed); Assert.AreEqual("Key", operation.PropertyName); } }
public void ExceptionThrownWhileResolvingAParameterIsBubbledUpAndTheCurrentOperationIsNotCleared() { var exception = new ArgumentException(); var resolverPolicy = new ExceptionThrowingTestResolverPolicy(exception); MockBuilderContext context = GetContext(); context.BuildKey = new NamedTypeBuildKey(typeof(ConstructorInjectionTestClass)); context.Policies.Set <IConstructorSelectorPolicy>( new TestSingleArgumentConstructorSelectorPolicy <ConstructorInjectionTestClass>(resolverPolicy), context.BuildKey); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, context.BuildKey); try { plan.BuildUp(context); Assert.True(false, string.Format("failure expected")); } catch (Exception e) { Assert.Same(exception, e); var operation = (ConstructorArgumentResolveOperation)context.CurrentOperation; Assert.NotNull(operation); Assert.Same(typeof(ConstructorInjectionTestClass), operation.TypeBeingConstructed); Assert.Equal("parameter", operation.ParameterName); } }
public void ExceptionThrownWhileSettingAPropertyIsBubbledUpAndTheCurrentOperationIsNotCleared() { MockBuilderContext context = GetContext(); var key = new NamedTypeBuildKey <OneExceptionThrowingPropertyClass>(); context.BuildKey = key; context.Existing = new OneExceptionThrowingPropertyClass(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, key); try { plan.BuildUp(context); Assert.Fail("failure expected"); } catch (Exception e) { Assert.AreSame(OneExceptionThrowingPropertyClass.PropertySetterException, e); var operation = (SettingPropertyOperation)context.CurrentOperation; Assert.IsNotNull(operation); Assert.AreSame(typeof(OneExceptionThrowingPropertyClass), operation.TypeBeingConstructed); Assert.AreEqual("Key", operation.PropertyName); } }
public void ResolvingANewInstanceOfAnInterfaceTypeThrows() { MockBuilderContext context = GetContext(); var key = new NamedTypeBuildKey <IComparable>(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, key); context.BuildKey = key; Assert.Throws <InvalidOperationException>(() => plan.BuildUp(context)); }
public void ResolvingANewInstanceOfADelegateTypeThrows() { MockBuilderContext context = GetContext(); var key = new NamedTypeBuildKey <Func <string, object> >(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, key); context.BuildKey = key; Assert.Throws <InvalidOperationException>(() => plan.BuildUp(context)); }
public void ResolvingANewInstanceOfATypeWithPrivateConstructorThrows() { MockBuilderContext context = GetContext(); var key = new NamedTypeBuildKey <NoPublicConstructorInjectionTestClass>(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, key); context.BuildKey = key; Assert.Throws <InvalidOperationException>(() => plan.BuildUp(context)); }
public void CannotCreatePlanForPrivateClass() { TestingBuilderContext context = GetContext(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, typeof(PrivateClassWithoutExplicitConstructor)); context.BuildKey = typeof(PrivateClassWithoutExplicitConstructor); plan.BuildUp(context); }
public void CanBuildUpObjectWithDefaultConstructorViaBuildPlan() { TestingBuilderContext context = GetContext(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, typeof(NullLogger)); context.BuildKey = typeof(NullLogger); plan.BuildUp(context); object result = context.Existing; Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(NullLogger)); }
public void TheCurrentOperationIsNullAfterSuccessfullyExecutingTheBuildPlan() { MockBuilderContext context = GetContext(); var key = new NamedTypeBuildKey <OnePropertyClass>(); context.BuildKey = key; context.Existing = new OnePropertyClass(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, key); plan.BuildUp(context); Assert.Null(context.CurrentOperation); }
public void CanCreateObjectWithoutExplicitConstructorDefined() { TestingBuilderContext context = GetContext(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, typeof(InternalObjectWithoutExplicitConstructor)); context.BuildKey = typeof(InternalObjectWithoutExplicitConstructor); plan.BuildUp(context); InternalObjectWithoutExplicitConstructor result = (InternalObjectWithoutExplicitConstructor)context.Existing; Assert.IsNotNull(result); }
public void CanCreatePlanForPrivateClass() { TestingBuilderContext context = GetContext(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, typeof(PrivateClassWithoutExplicitConstructor)); context.BuildKey = typeof(PrivateClassWithoutExplicitConstructor); plan.BuildUp(context); object result = context.Existing; Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(PrivateClassWithoutExplicitConstructor)); }
public void ExceptionThrownWhileInvokingTheConstructorIsBubbledUpAndTheCurrentOperationIsNotCleared() { MockBuilderContext context = GetContext(); context.BuildKey = new NamedTypeBuildKey(typeof(ThrowingConstructorInjectionTestClass)); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, context.BuildKey); var exception = Assert.Throws <ArgumentException>(() => plan.BuildUp(context)); var operation = context.CurrentOperation as InvokingConstructorOperation; Assert.NotNull(operation); Assert.IsType <ThrowingConstructorInjectionTestClass>(operation.TypeBeingConstructed); }
public void ExistingObjectIsUntouchedByConstructionPlan() { MockBuilderContext context = GetContext(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, new NamedTypeBuildKey(typeof(OptionalLogger))); var existing = new OptionalLogger("C:\\log.log"); context.BuildKey = new NamedTypeBuildKey(typeof(OptionalLogger)); context.Existing = existing; plan.BuildUp(context); object result = context.Existing; Assert.AreSame(existing, result); Assert.AreEqual("C:\\log.log", existing.LogFile); }
public void ExistingObjectIsUntouchedByConstructionPlan() { TestingBuilderContext context = GetContext(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, typeof(OptionalLogger)); OptionalLogger existing = new OptionalLogger("C:\\foo.bar"); context.BuildKey = typeof(OptionalLogger); context.Existing = existing; plan.BuildUp(context); object result = context.Existing; Assert.AreSame(existing, result); Assert.AreEqual("C:\\foo.bar", existing.LogFile); }
public void ExceptionThrownWhileInvokingTheInjectionMethodIsBubbledUpAndTheCurrentOperationIsNotCleared() { MockBuilderContext context = GetContext(); var key = new NamedTypeBuildKey <ObjectWithSingleThrowingInjectionMethod>(); context.BuildKey = key; context.Existing = new ObjectWithSingleThrowingInjectionMethod(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, key); var exception = Assert.Throws <ArgumentException>(() => plan.BuildUp(context)); var operation = context.CurrentOperation as InvokingMethodOperation; Assert.NotNull(operation); Assert.IsType <ObjectWithSingleThrowingInjectionMethod>(operation.TypeBeingConstructed); }
public void ResolvingANewInstanceOfADelegateTypeThrows() { MockBuilderContext context = GetContext(); var key = new NamedTypeBuildKey <Func <string, object> >(); IBuildPlanPolicy plan = GetPlanCreator(context).CreatePlan(context, key); context.BuildKey = key; try { plan.BuildUp(context); Assert.True(false, string.Format("should have thrown")); } catch (InvalidOperationException) { } }