Example #1
0
        public void GetParameterNameInExceptionMessageOnFailedResolution()
        {
            TestingBuilderContext context = TestingBuilderContext.GetFullContext();

            try
            {
                context.ExecuteBuildUp(typeof(FileLogger), null);
                Assert.Fail();
            }
            catch (BuildFailedException ex)
            {
                Assert.IsTrue(ex.Message.Contains("logFile"));
                return;
            }
        }
Example #2
0
        public void GetProperExceptionMessageWhenBuildingInterface()
        {
            TestingBuilderContext context = TestingBuilderContext.GetFullContext();

            try
            {
                context.ExecuteBuildUp(typeof(ISomethingOrOther), null);
                Assert.Fail();
            }
            catch (BuildFailedException ex)
            {
                Assert.IsTrue(ex.Message.Contains("is an interface"));
                return;
            }
        }
        public void GetExpectedExceptionMessageWhenPropertiesAreNotResolved()
        {
            TestingBuilderContext   context  = TestingBuilderContext.GetFullContext();
            ClassThatTakesInterface existing = new ClassThatTakesInterface();

            try
            {
                context.ExecuteBuildUp(typeof(ClassThatTakesInterface), existing);
                Assert.Fail();
            }
            catch (BuildFailedException ex)
            {
                StringAssert.Contains(ex.Message, "property \"Foo\"");
                return;
            }
        }
        public void GetProperExceptionMessageWhenFailingToResolveMethodParameter()
        {
            TestingBuilderContext context     = TestingBuilderContext.GetFullContext();
            ILifetimePolicy       intLifetime = new SingletonLifetimePolicy();

            intLifetime.SetValue(42);
            context.PersistentPolicies.Set(intLifetime, typeof(int));

            ObjectWithInjectionMethod existing = new ObjectWithInjectionMethod();

            try
            {
                context.ExecuteBuildUp(typeof(ObjectWithInjectionMethod), existing);
                Assert.Fail();
            }
            catch (BuildFailedException ex)
            {
                StringAssert.Contains(ex.Message, "DoSomething");
                StringAssert.Contains(ex.Message, "stringParam");
            }
        }