public void Can_Override_annotation_based_configuration_for_property() { var model = new TrackedModelWithMultipleProperties { Category = RandomChar, //tracked ->skipped Description = RandomText, //skipped IsSpecial = true, //tracked -> skipped StartDate = new DateTime(2015, 5, 5), //skipped Name = RandomText, //tracked Value = RandomNumber //skipped -> Tracked }; EntityTracker .OverrideTracking <TrackedModelWithMultipleProperties>() //enable vaue .Enable(x => x.Value) //disable for isSpecial .Disable(x => x.IsSpecial) //disable category .Disable(x => x.Category); Db.TrackedModelsWithMultipleProperties.Add(model); string userName = RandomText; Db.SaveChanges(userName); model.AssertAuditForAddition(Db, model.Id, userName, x => x.Id, x => x.Name, x => x.Value); }
public async Task Can_Override_annotation_based_configuration_for_entity_skipTracking() { var model = new NormalModel(); EntityTracker .OverrideTracking <NormalModel>() .Disable(); string userName = RandomText; Db.NormalModels.Add(model); await Db.SaveChangesAsync(userName); model.AssertNoLogs(Db, model.Id); }
public void Can_Override_annotation_based_configuration_for_property() { var options = new DbContextOptionsBuilder <TestTrackerContext>() .UseSqlServer(TestConnectionString) .Options; var model = new TrackedModelWithMultipleProperties { Category = rdg.Get <Char>(), //tracked ->skipped Description = rdg.Get <string>(), //skipped IsSpecial = true, //tracked -> skipped StartDate = new DateTime(2015, 5, 5), //skipped Name = rdg.Get <string>(), //tracked Value = rdg.Get <int>() //skipped -> Tracked }; EntityTracker .OverrideTracking <TrackedModelWithMultipleProperties>() //enable vaue .Enable(x => x.Value) //disable for isSpecial .Disable(x => x.IsSpecial) //disable category .Disable(x => x.Category); using (TestTrackerContext ttc = new TestTrackerContext(options)) { ttc.TrackedModelWithMultipleProperties.Add(model); string userName = rdg.Get <string>(); ttc.SaveChanges(userName); model.AssertAuditForAddition(ttc, model.Id, userName, x => x.Id, x => x.Name, x => x.Value); } }
public async Task Can_Override_annotation_based_configuration_for_entity_skipTracking() { var options = new DbContextOptionsBuilder <TestTrackerContext>() .UseSqlServer(TestConnectionString) .Options; var model = new NormalModel(); EntityTracker .OverrideTracking <NormalModel>() .Disable(); string userName = rdg.Get <string>(); using (TestTrackerContext ttc = new TestTrackerContext(options)) { ttc.NormalModels.Add(model); await ttc.SaveChangesAsync(userName); model.AssertNoLogs(ttc, model.Id); } }
public void CanOverrideUntrackedBaseClassProperties() { EntityTracker .OverrideTracking <TrackedExtendedModel>() .Enable(x => x.UntrackedProperty); var existingEntity = ObjectFactory.Create <TrackedExtendedModel>(save: true, testDbContext: Db); var originalValue = existingEntity.UntrackedProperty; var newValue = RandomText; existingEntity.UntrackedProperty = newValue; Db.SaveChanges(); existingEntity.AssertAuditForModification(Db, existingEntity.Id, null, new AuditLogDetail { PropertyName = nameof(existingEntity.UntrackedProperty), OriginalValue = originalValue, NewValue = newValue }); }
public static OverrideTrackingResponse <T> OverrideTracking <T>(this EntityTypeConfiguration <T> entityTypeConfig) where T : class { return(EntityTracker.OverrideTracking <T>()); }