예제 #1
0
        public void Happy_path_with_no_validation_errors()
        {
            ValidationBuildSession session =
                validatedSession(
                    registry => registry.InstanceOf <IWidget>().Is.Object(new ColorWidget("Red")));

            Assert.AreEqual(0, session.ValidationErrors.Length);
        }
예제 #2
0
        public void Create_an_instance_for_the_first_time_happy_path()
        {
            ValidationBuildSession session =
                validatedSession(
                    r => r.InstanceOf <IWidget>().Is.Object(new ColorWidget("Red")));

            Assert.AreEqual(0, session.BuildErrors.Length);
        }
        public void Successfully_build_an_object_that_has_multiple_validation_errors()
        {
            ValidationBuildSession session =
                validatedSession(
                    registry =>
                    registry.For <SomethingThatHasValidationFailures>().Use <SomethingThatHasValidationFailures>());

            Assert.AreEqual(2, session.ValidationErrors.Length);
        }
예제 #4
0
        public void Successfully_build_an_object_that_has_multiple_validation_errors()
        {
            ValidationBuildSession session =
                validatedSession(
                    registry =>
                    registry.BuildInstancesOf <SomethingThatHasValidationFailures>().TheDefaultIsConcreteType
                    <SomethingThatHasValidationFailures>());

            Assert.AreEqual(2, session.ValidationErrors.Length);
        }
예제 #5
0
        public void Request_an_instance_for_the_second_time_successfully_and_get_the_same_object()
        {
            var session = new ValidationBuildSession(new PluginGraph());

            var    instance = new ObjectInstance(new ColorWidget("Red"));
            object widget1  = session.CreateInstance(typeof(IWidget), instance);
            object widget2  = session.CreateInstance(typeof(IWidget), instance);

            Assert.AreSame(widget1, widget2);
        }
예제 #6
0
        /// <summary>
        /// Use with caution!  Does a full environment test of the configuration of this container.  Will try to create every configured
        /// instance and afterward calls any methods marked with the [ValidationMethod] attribute
        /// </summary>
        public void AssertConfigurationIsValid()
        {
            var session = new ValidationBuildSession(_pipelineGraph, _interceptorLibrary);

            session.PerformValidations();

            if (!session.Success)
            {
                throw new StructureMapConfigurationException(session.BuildErrorMessages());
            }
        }
예제 #7
0
        public void Create_an_instance_that_has_a_build_failure()
        {
            Instance instance = errorInstance().WithName("Bad");
            ValidationBuildSession session =
                validatedSession(registry => registry.InstanceOf <IWidget>().IsThis(instance));

            BuildError error = getFirstAndOnlyError(session);

            Assert.AreEqual(instance, error.Instance);
            Assert.AreEqual(typeof(IWidget), error.PluginType);
            Assert.IsNotNull(error.Exception);
        }
예제 #8
0
        private ValidationBuildSession validatedSession(Action <Registry> action)
        {
            var registry = new Registry();

            action(registry);

            PluginGraph graph   = registry.Build();
            var         session = new ValidationBuildSession(graph);

            session.PerformValidations();

            return(session);
        }
예제 #9
0
        public void Create_an_instance_that_fails_because_of_an_inline_child()
        {
            ValidationBuildSession session = validatedSession(
                r =>
            {
                r.InstanceOf <SomethingThatNeedsAWidget>().Is.OfConcreteType <SomethingThatNeedsAWidget>()
                .WithName("BadInstance")
                .CtorDependency <IWidget>().Is(errorInstance());
            });

            BuildError error = getFirstAndOnlyError(session);

            Assert.AreEqual("BadInstance", error.Instance.Name);
            Assert.AreEqual(typeof(SomethingThatNeedsAWidget), error.PluginType);
        }
예제 #10
0
        public void Validate_a_single_object_with_both_a_passing_validation_method_and_a_failing_validation_method()
        {
            var instance = new ObjectInstance(new WidgetWithOneValidationFailure());
            ValidationBuildSession session =
                validatedSession(registry => registry.InstanceOf <IWidget>().IsThis(instance));


            Assert.AreEqual(1, session.ValidationErrors.Length);

            ValidationError error = session.ValidationErrors[0];

            Assert.AreEqual(typeof(IWidget), error.PluginType);
            Assert.AreEqual(instance, error.Instance);
            Assert.AreEqual("ValidateFailure", error.MethodName);
            Assert.IsInstanceOfType(typeof(NotImplementedException), error.Exception);
        }
예제 #11
0
        public void Attach_dependency_to_the_build_error_but_do_not_create_new_error_for_dependency()
        {
            ValidationBuildSession session = validatedSession(r =>
            {
                r.InstanceOf <IWidget>().IsThis(errorInstance().WithName("BadInstance"));

                r.InstanceOf <SomethingThatNeedsAWidget>().Is.OfConcreteType <SomethingThatNeedsAWidget>()
                .WithName("DependentInstance")
                .CtorDependency <IWidget>().Is(x => x.TheInstanceNamed("BadInstance"));
            });

            BuildError error = getFirstAndOnlyError(session);

            Assert.AreEqual(1, error.Dependencies.Count);
            BuildDependency dependency = error.Dependencies[0];

            Assert.AreEqual(typeof(SomethingThatNeedsAWidget), dependency.PluginType);
            Assert.AreEqual("DependentInstance", dependency.Instance.Name);
        }
예제 #12
0
        public void Create_an_instance_that_fails_and_an_instance_that_depends_on_that_exception()
        {
            ValidationBuildSession session = validatedSession(r =>
            {
                r.InstanceOf <IWidget>().IsThis(errorInstance().WithName("BadInstance"));


                r.InstanceOf <SomethingThatNeedsAWidget>().Is.OfConcreteType <SomethingThatNeedsAWidget>()
                .WithName("DependentInstance")
                .CtorDependency <IWidget>().Is(x => x.TheInstanceNamed("BadInstance"));
            });

            Assert.AreEqual(1, session.BuildErrors.Length);

            BuildError error = session.Find(typeof(SomethingThatNeedsAWidget), "DependentInstance");

            Assert.IsNull(error);

            BuildError error2 = session.Find(typeof(IWidget), "BadInstance");

            Assert.IsNotNull(error2);
        }
예제 #13
0
 private BuildError getFirstAndOnlyError(ValidationBuildSession session)
 {
     Assert.AreEqual(1, session.BuildErrors.Length);
     return(session.BuildErrors[0]);
 }