public HttpResponseMessage Get()
 {
     Address address = new Address
     {
         Province = "江苏省",
         City = "苏州市",
         District = "工业园区",
         Street = "星湖街328号"
     };
     Contact contact = new Contact
     {
         Name = "张三",
         PhoneNo = "123456789",
         EmailAddress = "*****@*****.**",
         Address = address
     };
     IBodyModelValidator validator = new DefaultBodyModelValidator();
     HttpActionContext actionContext = new HttpActionContext
     {
         ControllerContext = this.ControllerContext
     };
     ModelMetadataProvider metadataProvider =actionContext.GetMetadataProvider();
     validator.Validate(contact, typeof(Contact), metadataProvider,actionContext, "contact");
     return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest,actionContext.ModelState);
 }
        public void Validate_DoesNotUseOverridden_GetHashCodeOrEquals()
        {
            // Arrange
            ModelMetadataProvider     metadataProvider = new DataAnnotationsModelMetadataProvider();
            HttpActionContext         actionContext    = ContextUtil.CreateActionContext();
            DefaultBodyModelValidator validator        = new DefaultBodyModelValidator();
            object instance = new[]
            {
                new TypeThatOverridesEquals {
                    Funny = "hehe"
                },
                new TypeThatOverridesEquals {
                    Funny = "hehe"
                }
            };

            // Act & Assert
            Assert.DoesNotThrow(
                () =>
                validator.Validate(
                    instance,
                    typeof(TypeThatOverridesEquals[]),
                    metadataProvider,
                    actionContext,
                    String.Empty
                    )
                );
        }
        public void Validate_DoesNotUseOverridden_GetHashCodeOrEquals()
        {
            // Arrange
            ModelMetadataProvider metadataProvider = new DataAnnotationsModelMetadataProvider();
            HttpActionContext actionContext = ContextUtil.CreateActionContext();
            DefaultBodyModelValidator validator = new DefaultBodyModelValidator();
            object instance = new[] { new TypeThatOverridesEquals { Funny = "hehe" }, new TypeThatOverridesEquals { Funny = "hehe" } };

            // Act & Assert
            Assert.DoesNotThrow(
                () => validator.Validate(instance, typeof(TypeThatOverridesEquals[]), metadataProvider, actionContext, String.Empty));
        }