Beispiel #1
0
        public void SingleRecordThatHasBeenDeleted()
        {
            DateTime         createdTime = DateTime.Today.AddDays(-1);
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            record.AddColumn("CreatedDateTime", typeof(DateTime));
            record.AddColumn("Deleted", typeof(bool));

            record.SetValue("CreatedDateTime", Iso8601DateTimeConverter.ConvertFromLocalDateTime(createdTime));
            record.SetValue("Deleted", "True");
            auditRecord.Changes.Add
            (
                AddSession("User", DateTime.Today, "IsDeleted", "False", "True")
            );

            AmplaRecordHistory <ProductionModel> amplaRecordHistory = new AmplaRecordHistory <ProductionModel>(record, auditRecord, viewProperties);
            List <AmplaRecordChanges>            changes            = amplaRecordHistory.Reconstruct();

            Assert.That(changes, Is.Not.Empty);
            Assert.That(changes.Count, Is.EqualTo(2));
            Assert.That(changes[0].Operation, Is.EqualTo("Create Record"));
            Assert.That(changes[0].User, Is.EqualTo("System"));
            Assert.That(changes[0].Changes, Is.Empty);
            Assert.That(changes[1].Operation, Is.EqualTo("Delete Record"));
            Assert.That(changes[1].User, Is.EqualTo("User"));
            Assert.That(changes[1].Changes, Is.Not.Empty);
            AmplaAuditField deleted = changes[1].Changes[0];

            Assert.That(deleted.Name, Is.EqualTo("IsDeleted"));
        }
        public override List <AmplaRecordChanges> DetectChanges()
        {
            List <AmplaRecordChanges> recordChanges = new List <AmplaRecordChanges>();

            if (amplaRecord.GetValueOrDefault(deletedDisplayName, false))
            {
                if (amplaAuditRecord.Changes != null)
                {
                    foreach (AmplaAuditSession session in amplaAuditRecord.Changes)
                    {
                        AmplaAuditField isDeleted = session.Fields.FirstOrDefault(f => f.Name == deletedName);
                        if (isDeleted != null)
                        {
                            AmplaRecordChanges changes = new AmplaRecordChanges
                            {
                                VersionDateTime = session.EditedTime,
                                User            = session.User,
                                Operation       = Operation,
                                Changes         = new [] { new AmplaAuditField()
                                                           {
                                                               Name          = deletedName,
                                                               OriginalValue = "False",
                                                               EditedValue   = "True"
                                                           } },
                                Display = string.Format("{0} deleted record", session.User)
                            };
                            recordChanges.Add(changes);
                        }
                    }
                }
            }
            return(recordChanges);
        }
        protected static AmplaAuditSession AddSession(string user, DateTime time, string[] fields, string[] oldValues,
                                                      string[] newValues)
        {
            AmplaAuditSession session = new AmplaAuditSession(user, time);

            Assert.That(fields.Length, Is.GreaterThan(0));
            Assert.That(fields.Length, Is.EqualTo(oldValues.Length));
            Assert.That(fields.Length, Is.EqualTo(newValues.Length));
            for (int i = 0; i < fields.Length; i++)
            {
                AmplaAuditField field = new AmplaAuditField
                {
                    Name          = fields[i],
                    OriginalValue = oldValues[i],
                    EditedValue   = newValues[i]
                };
                session.Fields.Add(field);
            }
            return(session);
        }
Beispiel #4
0
 private bool IncludeField(AmplaAuditField field)
 {
     return((field.OriginalValue != field.EditedValue) &&
            !ignoreFields.Contains(field.Name));
 }