public void CreateBehavior_ShouldThrowATargetInvocationException_WithAConfigurationErrorsExceptionAsInnerException_IfTheTypeNameIsNull()
        {
            BootstrapperElementTestBootstrapperElementMock bootstrapperElement = new BootstrapperElementTestBootstrapperElementMock {TypeName = null};
            Assert.IsNull(bootstrapperElement.TypeName);

            try
            {
                bootstrapperElement.CreateBehavior();
            }
            catch(Exception exception)
            {
                if(exception is TargetInvocationException)
                {
                    Assert.AreEqual("Could not create behavior.", exception.Message);

                    if(exception.InnerException == null || !(exception.InnerException is ConfigurationErrorsException))
                        Assert.Fail(string.Format("The inner exception should be of type \"{0}\".", typeof(ConfigurationErrorsException).FullName));

                    Assert.AreEqual("The type/typename for the bootstrapper can not be null or empty.", exception.InnerException.Message);

                    throw;
                }

                Assert.Fail(string.Format("The thrown exception should be of type \"{0}\".", typeof(TargetInvocationException).FullName));
            }
        }
        public void CreateBehavior_ShouldThrowATargetInvocationException_WithAConfigurationErrorsExceptionAsInnerException_IfTheTypeNameIsTheNameOfANonExistingType()
        {
            BootstrapperElementTestBootstrapperElementMock bootstrapperElement = new BootstrapperElementTestBootstrapperElementMock {TypeName = "SomeInvalidType"};
            Assert.AreEqual("SomeInvalidType", bootstrapperElement.TypeName);

            try
            {
                bootstrapperElement.CreateBehavior();
            }
            catch(Exception exception)
            {
                if(exception is TargetInvocationException)
                {
                    Assert.AreEqual("Could not create behavior.", exception.Message);

                    if(exception.InnerException == null || !(exception.InnerException is ConfigurationErrorsException))
                        Assert.Fail(string.Format("The inner exception should be of type \"{0}\".", typeof(ConfigurationErrorsException).FullName));

                    Assert.AreEqual("Could not get a type from the string representation \"SomeInvalidType\".", exception.InnerException.Message);

                    throw;
                }

                Assert.Fail(string.Format("The thrown exception should be of type \"{0}\".", typeof(TargetInvocationException).FullName));
            }
        }
 public void CreateBehavior_ShouldReturnAnObjectOfTypeBootstrapperBehavior_IfTheTypeNameIsTheNameOfATypeThatInheritsFromIBootstrapper()
 {
     BootstrapperElementTestBootstrapperElementMock bootstrapperElement = new BootstrapperElementTestBootstrapperElementMock {TypeName = typeof(BootstrapperElementTestBootstrapperMock).FullName + ", " + typeof(BootstrapperElementTestBootstrapperMock).Assembly.GetName().Name};
     BootstrapperBehavior bootstrapperBehavior = (BootstrapperBehavior) bootstrapperElement.CreateBehavior();
 }
        public void CreateBehavior_ShouldThrowATargetInvocationException_WithAConfigurationErrorsExceptionAsInnerException_IfTheTypeNameIsTheNameOfATypeThatNotInheritsFromIBootstrapper()
        {
            BootstrapperElementTestBootstrapperElementMock bootstrapperElement = new BootstrapperElementTestBootstrapperElementMock {TypeName = typeof(object).FullName};
            Assert.AreEqual("System.Object", bootstrapperElement.TypeName);

            try
            {
                bootstrapperElement.CreateBehavior();
            }
            catch(Exception exception)
            {
                if(exception is TargetInvocationException)
                {
                    Assert.AreEqual("Could not create behavior.", exception.Message);

                    if(exception.InnerException == null || !(exception.InnerException is ConfigurationErrorsException))
                        Assert.Fail(string.Format("The inner exception should be of type \"{0}\".", typeof(ConfigurationErrorsException).FullName));

                    Assert.AreEqual("The bootstrapper type \"System.Object\" does not implement the interface \"HansKindberg.ServiceModel.IBootstrapper\".", exception.InnerException.Message);

                    throw;
                }

                Assert.Fail(string.Format("The thrown exception should be of type \"{0}\".", typeof(TargetInvocationException).FullName));
            }
        }