public void ShouldCreateSoftDeleteLogForMultiplePropertiesChanged()
        {
            //create a softdeletable entity and soft delete it
            var deletable = new SoftDeletableModel();

            Db.SoftDeletableModels.Add(deletable);

            //save it to database
            Db.SaveChanges();

            deletable.AssertAuditForAddition(Db, deletable.Id,
                                             null, x => x.Id);

            //soft delete entity
            deletable.Delete();
            deletable.Description = RandomText;

            //save changes
            Db.SaveChanges();

            //assert for soft deletion
            deletable.AssertAuditForSoftDeletion(Db, deletable.Id, null, new AuditLogDetail
            {
                NewValue      = true.ToString(),
                OriginalValue = false.ToString(),
                PropertyName  = nameof(deletable.IsDeleted)
            },
                                                 new AuditLogDetail
            {
                NewValue      = deletable.Description,
                OriginalValue = null,
                PropertyName  = nameof(deletable.Description)
            });
        }
Пример #2
0
        public void ShouldCreateSoftDeleteLog2()
        {
            var options = new DbContextOptionsBuilder <TestTrackerContext>()
                          .UseSqlServer(TestConnectionString)
                          .Options;

            //create a softdeletable entity and soft delete it
            var deletable = new SoftDeletableModel();

            using (TestTrackerContext ttc = new TestTrackerContext(options))
            {
                ttc.SoftDeletableModels.Add(deletable); //add
                ttc.SaveChanges();                      //add

                deletable.AssertAuditForAddition(ttc, deletable.Id, null, x => x.Id);

                ttc.SoftDeletableModels.Remove(deletable); //soft delete
                ttc.SaveChanges();                         //soft delete

                //assert for soft deletion
                deletable.AssertAuditForSoftDeletion(ttc, deletable.Id, null, new AuditLogDetail
                {
                    NewValue      = true.ToString(),
                    OriginalValue = false.ToString(),
                    PropertyName  = nameof(deletable.IsDeleted)
                });
            }
        }
Пример #3
0
        public async Task ShouldCreateUnDeletedLogForMultiplePropertiesChanged()
        {
            var options = new DbContextOptionsBuilder <TestTrackerContext>()
                          .UseSqlServer(TestConnectionString)
                          .Options;

            string oldDescription = rdg.Get <string>();
            string newDescription = rdg.Get <string>();

            var deletable = new SoftDeletableModel
            {
                Description = oldDescription
            };

            using (TestTrackerContext ttc = new TestTrackerContext(options))
            {
                ttc.Set <SoftDeletableModel>().Attach(deletable);
                ttc.Entry(deletable).State = EntityState.Added;
                await ttc.SaveChangesAsync();

                deletable.AssertAuditForAddition(ttc, deletable.Id, null, x => x.Id, x => x.Description);

                deletable.IsDeleted = true;
                await ttc.SaveChangesAsync();

                deletable.AssertAuditForSoftDeletion(ttc, deletable.Id, null,
                                                     new AuditLogDetail
                {
                    PropertyName  = nameof(deletable.IsDeleted),
                    OriginalValue = false.ToString(),
                    NewValue      = true.ToString()
                });

                deletable.IsDeleted   = false;
                deletable.Description = newDescription;
                await ttc.SaveChangesAsync();

                deletable.AssertAuditForUndeletion(ttc, deletable.Id, null,
                                                   new AuditLogDetail
                {
                    PropertyName  = nameof(deletable.IsDeleted),
                    OriginalValue = true.ToString(),
                    NewValue      = false.ToString()
                },
                                                   new AuditLogDetail
                {
                    PropertyName  = nameof(deletable.Description),
                    OriginalValue = oldDescription,
                    NewValue      = newDescription
                });
            }
        }
        public async Task ShouldCreateUnDeletedLogForMultiplePropertiesChanged()
        {
            string oldDescription = RandomText;
            string newDescription = RandomText;

            var deletable = new SoftDeletableModel
            {
                Description = oldDescription
            };

            Db.Set <SoftDeletableModel>().Attach(deletable);
            Db.Entry(deletable).State = EntityState.Added;
            await Db.SaveChangesAsync();

            deletable.AssertAuditForAddition(Db, deletable.Id, null,
                                             x => x.Id, x => x.Description);

            deletable.Delete();
            await Db.SaveChangesAsync();

            deletable.AssertAuditForSoftDeletion(Db, deletable.Id, null,
                                                 new AuditLogDetail
            {
                PropertyName  = nameof(deletable.IsDeleted),
                OriginalValue = false.ToString(),
                NewValue      = true.ToString()
            });

            deletable.IsDeleted   = false;
            deletable.Description = newDescription;
            await Db.SaveChangesAsync();

            deletable.AssertAuditForUndeletion(Db, deletable.Id, null,
                                               new AuditLogDetail
            {
                PropertyName  = nameof(deletable.IsDeleted),
                OriginalValue = true.ToString(),
                NewValue      = false.ToString()
            },
                                               new AuditLogDetail
            {
                PropertyName  = nameof(deletable.Description),
                OriginalValue = oldDescription,
                NewValue      = newDescription
            });
        }
Пример #5
0
        public void ShouldCreateSoftDeleteLogForMultiplePropertiesChanged()
        {
            var options = new DbContextOptionsBuilder <TestTrackerContext>()
                          .UseSqlServer(TestConnectionString)
                          .Options;

            //create a softdeletable entity and soft delete it
            var deletable = new SoftDeletableModel();

            using (TestTrackerContext ttc = new TestTrackerContext(options))
            {
                ttc.SoftDeletableModels.Add(deletable);

                //save it to database
                ttc.SaveChanges();

                deletable.AssertAuditForAddition(ttc, deletable.Id, null, x => x.Id);

                //soft delete entity
                deletable.IsDeleted   = true;
                deletable.Description = rdg.Get <string>();

                //save changes
                ttc.SaveChanges();

                //assert for soft deletion
                deletable.AssertAuditForSoftDeletion(ttc, deletable.Id, null, new AuditLogDetail
                {
                    NewValue      = true.ToString(),
                    OriginalValue = false.ToString(),
                    PropertyName  = nameof(deletable.IsDeleted)
                },
                                                     new AuditLogDetail
                {
                    NewValue      = deletable.Description,
                    OriginalValue = null,
                    PropertyName  = nameof(deletable.Description)
                });
            }
        }
        public void ShouldCreateUnDeletedLog()
        {
            var deletable = new SoftDeletableModel
            {
                Description = RandomText,
            };

            Db.Set <SoftDeletableModel>().Attach(deletable);
            Db.Entry(deletable).State = EntityState.Added;
            Db.SaveChanges();

            deletable.AssertAuditForAddition(Db, deletable.Id, null,
                                             x => x.Id, x => x.Description);

            deletable.Delete();
            Db.SaveChanges();

            deletable.AssertAuditForSoftDeletion(Db, deletable.Id, null,
                                                 new AuditLogDetail
            {
                PropertyName  = nameof(deletable.IsDeleted),
                OriginalValue = false.ToString(),
                NewValue      = true.ToString()
            });

            deletable.IsDeleted = false;
            Db.SaveChanges();

            deletable.AssertAuditForUndeletion(Db, deletable.Id, null,
                                               new AuditLogDetail
            {
                PropertyName  = nameof(deletable.IsDeleted),
                OriginalValue = true.ToString(),
                NewValue      = false.ToString()
            });
        }