Inheritance: ITimeStamped, ISoftDeleted
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        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);
        }