public void CorrectEntry_SetItToNull_NullIsNotAllowed_Like() { string columnName = "Email"; using (var ctx = SqlServerValidationToolkitContext.Create()) { var column = ctx.Columns.Single(c => c.Name == columnName); var vr = column.ValidationRules.Single(); vr.NullValueTreatment = NullValueTreatment.InterpretAsError; vr.CompiledQuery = vr.Query; ctx.SaveChanges(); } int babyId; using (var ctx = TestDatabaseContext.Create(Settings.Default.ConnectionString)) { var baby = ctx.Babies.First(b => b.Email != null); baby.Email = null; ctx.SaveChanges(); babyId = baby.BabyID; } using (var ctx = SqlServerValidationToolkitContext.Create()) { bool babyEntryExisted = WrongBabyEntryExists(columnName, babyId, ctx); ctx.Validate(SqlServerValidationToolkitContext.Create(Settings.Default.ConnectionString)); bool babyEntryExists = WrongBabyEntryExists(columnName, babyId, ctx); Assert.IsFalse(babyEntryExisted); Assert.IsTrue(babyEntryExists); } }
public void CorrectMultipleValues() { var ctx = SqlServerValidationToolkitContext.Create(); Assert.IsTrue(WrongLengthEntriesExisting(ctx)); var ctxBabies = TestDatabaseContext.Create(Settings.Default.ConnectionString); CorrectLength(ctxBabies); ctx.Validate(SqlServerValidationToolkitContext.Create(Settings.Default.ConnectionString)); Assert.IsFalse(WrongLengthEntriesExisting(ctx)); }
/// <summary> /// Selects the Baby-Id from the WrongValues-View based on the predicate, /// finds the Baby, applies the correction and executes CheckColumn-Procedure /// </summary> /// <param name="pred">predicate to find the Id of the Baby with the wrong value</param> /// <param name="correction">Correction-Action</param> /// <returns>Baby-Id</returns> private static long ApplyCorrection(Expression <Func <WrongValue, bool> > pred, Action <TestDatabaseContext, Baby> correction) { var ctx = SqlServerValidationToolkitContext.Create(); foreach (var wv in ctx.WrongValues) { Console.WriteLine(wv); } var firstWrongWeightBabyId = ctx.WrongValues.Where(pred).Select(wrongValue => wrongValue.Id).First(); var ctxBabies = TestDatabaseContext.Create(Settings.Default.ConnectionString); var babyWithWrongWeight = ctxBabies.Babies.Find(firstWrongWeightBabyId); correction(ctxBabies, babyWithWrongWeight); ctx.Validate(SqlServerValidationToolkitContext.Create(Settings.Default.ConnectionString)); ctx.SaveChanges(); return(firstWrongWeightBabyId); }