Inheritance: ITimeStamped, ISoftDeleted
Example #1
0
        public void PreInsertHook_InterfaceHookCallsIntoGenericMethod()
        {
            var hook   = new TimestampPreInsertHook();
            var entity = new TimestampedSoftDeletedEntity();

            ((IHook)hook).HookObject(entity, null);
            Assert.AreEqual(DateTime.Today, entity.CreatedAt.Date);
        }
Example #2
0
        public void PreUpdateHook_HookCallsIntoGenericMethod()
        {
            var hook   = new TimestampPreUpdateHook();
            var entity = new TimestampedSoftDeletedEntity();

            ((IHook)hook).HookObject(entity, null);

            Assert.AreEqual(entity.ModifiedAt.Value.Date, DateTime.Today);
        }
Example #3
0
        public void PreDeleteHook_ReassignToModifiedState()
        {
            var hook     = new SoftDeletePreDeleteHook();
            var metadata = new HookEntityMetadata(EntityState.Deleted);
            var entity   = new TimestampedSoftDeletedEntity();

            hook.Hook(entity, metadata);

            Assert.AreEqual(true, metadata.HasStateChanged);
            Assert.AreEqual(EntityState.Modified, metadata.State);
        }
        public async void HookedDbContext_MustCallHooks_WhenRunningSaveChangesAsync()
        {
            var hooks = new IHook[]
                            {
                                new TimestampPreInsertHook()
                            };

            var context = new LocalContext(hooks);
            var entity = new TimestampedSoftDeletedEntity();
            context.Entities.Add(entity);
            await context.SaveChangesAsync();

            Assert.AreEqual(entity.CreatedAt.Date, DateTime.Today);
        }