public void RegisterDefaultValidatableObjectAdapterGuardClauses()
        {
            // Adapter type cannot be null
            ExceptionHelper.ExpectArgumentNullException(
                () => DataAnnotations4ModelValidatorProvider.RegisterDefaultValidatableObjectAdapter(null),
                "adapterType");

            // Adapter must derive from ModelValidator
            ExceptionHelper.ExpectArgumentException(
                () => DataAnnotations4ModelValidatorProvider.RegisterDefaultValidatableObjectAdapter(typeof(object)),
                "The type System.Object must derive from System.Web.Mvc.ModelValidator.\r\nParameter name: adapterType");

            // Adapter must have the expected constructor
            ExceptionHelper.ExpectArgumentException(
                () => DataAnnotations4ModelValidatorProvider.RegisterDefaultValidatableObjectAdapter(typeof(MyValidatableAdapterBadCtor)),
                "The type Microsoft.Web.Mvc.AspNet4.Test.DataAnnotations4ModelValidatorProviderTest+MyValidatableAdapterBadCtor must have a public constructor which accepts two parameters of types System.Web.Mvc.ModelMetadata and System.Web.Mvc.ControllerContext.\r\nParameter name: adapterType");
        }
        public void RegisterDefaultValidatableObjectAdapter()
        {
            var oldFactory = DataAnnotations4ModelValidatorProvider.DefaultValidatableFactory;

            try {
                // Arrange
                var metadata = ModelMetadataProviders.Current.GetMetadataForType(() => null, typeof(MyValidatableClass));
                var context  = new ControllerContext();
                DataAnnotations4ModelValidatorProvider.RegisterDefaultValidatableObjectAdapter(typeof(MyValidatableAdapter));

                // Act
                var result = new DataAnnotations4ModelValidatorProvider().GetValidators(metadata, context).Single();

                // Assert
                Assert.AreEqual(typeof(MyValidatableAdapter), result.GetType());
            }
            finally {
                DataAnnotations4ModelValidatorProvider.DefaultValidatableFactory = oldFactory;
            }
        }