public void Should_validate_when_unique_key_in_context_set() { var context = new OEContext(); var productSet = context.Set <ProductWithSingleKeyProperty>(); var product1 = new ProductWithSingleKeyProperty() { Id = 1, Name = "First product", UnitPrice = 100 }; productSet.Add(product1); var product2 = new ProductWithSingleKeyProperty() { Id = 2, Name = "Second product", UnitPrice = 100 }; productSet.Add(product2); var validationResults = new List <ValidationResultWithSeverityLevel>(); var result = productSet.Validate(validationResults); Assert.AreEqual(true, result); Assert.AreEqual(0, validationResults.Count()); validationResults = new List <ValidationResultWithSeverityLevel>(); result = context.Validate(validationResults); Assert.AreEqual(true, result); Assert.AreEqual(0, validationResults.Count()); }
public void Should_validate_and_no_errors_when_no_conditions() { var context = new OEContext(); var productSet = context.Set <ProductWithCustomValidationProviderNoSeverity>(); productSet.SetValidationProvider(new CustomValidationServiceProvider()); var product = new ProductWithCustomValidationProviderNoSeverity() { Id = -1, Name = null, UnitPrice = -1 }; productSet.Add(product); var validationResults = new List <ValidationResultWithSeverityLevel>(); var result = productSet.Validate(validationResults); Assert.AreEqual(false, result); Assert.AreEqual(3, validationResults.Count()); Assert.AreSame(product, validationResults[0].Entity); Assert.AreEqual("Id", validationResults[0].MemberNames.ElementAt(0)); Assert.AreSame(product, validationResults[1].Entity); Assert.AreEqual("Name", validationResults[1].MemberNames.ElementAt(0)); Assert.AreSame(product, validationResults[2].Entity); Assert.AreEqual("UnitPrice", validationResults[2].MemberNames.ElementAt(0)); validationResults = new List <ValidationResultWithSeverityLevel>(); result = context.Validate(validationResults); Assert.AreEqual(false, result); Assert.AreEqual(3, validationResults.Count()); Assert.AreSame(product, validationResults[0].Entity); Assert.AreEqual("Id", validationResults[0].MemberNames.ElementAt(0)); Assert.AreSame(product, validationResults[1].Entity); Assert.AreEqual("Name", validationResults[1].MemberNames.ElementAt(0)); Assert.AreSame(product, validationResults[2].Entity); Assert.AreEqual("UnitPrice", validationResults[2].MemberNames.ElementAt(0)); }