public void 驗證ProductModel() { var productModel = new ProductModel { MyPerson = new Person { Id = 1, Name = string.Empty, Birthday = new DateTime(1991, 9, 1) }, MyProduct = new Product { Cost = 100, SellPrice = 105 } }; var validator = new DataAnnotationValidator(); var isValid = validator.TryValidate(productModel); Assert.AreEqual(false, isValid); Assert.AreEqual(2, validator.ValidationResults.Count); }
public void GivenProductModel_MyPerson為(Table table) { var productModel = new ProductModel(); var person = table.CreateInstance<Person>(); productModel.MyPerson = person; ScenarioContext.Current.Set<ProductModel>(productModel); }