Пример #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"));
        }
Пример #2
0
        public bool Bind()
        {
            if (response.RowSets.Length == 0)
            {
                return(false);
            }

            RowSet rowSet = response.RowSets[0];

            foreach (Row row in rowSet.Rows)
            {
                AmplaRecord model = new AmplaRecord(Convert.ToInt32(row.id))
                {
                    Module    = modelProperties.Module.ToString(),
                    ModelName = modelProperties.GetModelName()
                };

                foreach (var column in rowSet.Columns)
                {
                    model.AddColumn(column.displayName, DataTypeHelper.GetDataType(column.type));
                }

                foreach (XmlElement cell in row.Any)
                {
                    string field = XmlConvert.DecodeName(cell.Name);
                    string value = cell.InnerText;
                    model.SetValue(field, value);
                }

                model.SetMappedProperties(amplaViewProperties.GetFieldMappings());
                records.Add(model);
            }
            return(true);
        }
Пример #3
0
        public void ShowSimpleUsersName()
        {
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            record.AddColumn("CreatedDateTime", typeof(DateTime));
            record.AddColumn("CreatedBy", typeof(string));

            record.SetValue("CreatedBy", "System Configuration.Users.User");
            DateTime created = DateTime.Today.AddHours(1);

            record.SetValue("CreatedDateTime", Iso8601DateTimeConverter.ConvertFromLocalDateTime(created));

            CreateRecordEventDectection <ProductionModel> recordEventDectection = new CreateRecordEventDectection <ProductionModel>(record, auditRecord, viewProperties);
            List <AmplaRecordChanges> changes = recordEventDectection.DetectChanges();

            Assert.That(changes, Is.Not.Empty);
            Assert.That(changes[0].Operation, Is.EqualTo("Create Record"));
            Assert.That(changes[0].User, Is.EqualTo("User"));
            Assert.That(changes[0].VersionDateTime, Is.EqualTo(created));
            Assert.That(changes[0].Changes, Is.Empty);
            Assert.That(changes[0].Display, Is.EqualTo("User created record"));
        }
Пример #4
0
        public void SingleRecordWithCreateHistory()
        {
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            record.AddColumn("CreatedDateTime", typeof(DateTime));
            record.AddColumn("CreatedBy", typeof(string));

            record.SetValue("CreatedBy", "Admin");
            DateTime created = DateTime.Today.AddHours(1);

            record.SetValue("CreatedDateTime", Iso8601DateTimeConverter.ConvertFromLocalDateTime(created));

            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(1));
            Assert.That(changes[0].Operation, Is.EqualTo("Create Record"));
            Assert.That(changes[0].User, Is.EqualTo("Admin"));
            Assert.That(changes[0].VersionDateTime, Is.EqualTo(created));
            Assert.That(changes[0].Changes, Is.Empty);
        }
Пример #5
0
        public void DetectChangesWithDeletedRecords()
        {
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            record.AddColumn("Sample Period", typeof(DateTime));
            record.SetValue("Sample Period", Iso8601DateTimeConverter.ConvertFromLocalDateTime(DateTime.Today.AddDays(-1)));
            auditRecord.Changes = new List <AmplaAuditSession>
            {
                AddSession("User", DateTime.Today, "IsDeleted", "False", "True")
            };

            ModifyRecordEventDectection <ProductionModel> recordEventDectection = new ModifyRecordEventDectection <ProductionModel>(record, auditRecord, viewProperties);
            List <AmplaRecordChanges> changes = recordEventDectection.DetectChanges();

            Assert.That(changes, Is.Empty);
        }
Пример #6
0
        public void BindWithEmptyOriginalValue_double()
        {
            AmplaRecord amplaRecord = new AmplaRecord(100)
            {
                Location = location, Module = module, ModelName = ""
            };

            amplaRecord.AddColumn("Value", typeof(double));
            amplaRecord.AddColumn("Area", typeof(string));
            amplaRecord.SetValue("Value", "100.0");
            amplaRecord.SetValue("Area", "ROM");

            AmplaAuditRecord auditRecord = new AmplaAuditRecord
            {
                Id       = amplaRecord.Id,
                Location = amplaRecord.Location,
                Module   = amplaRecord.Module,
                Changes  = new List <AmplaAuditSession>
                {
                    new AmplaAuditSession("User", DateTime.Today)
                }
            };

            auditRecord.Changes[0].Fields.Add(new AmplaAuditField
            {
                Name          = "Value",
                OriginalValue = "",
                EditedValue   = "100"
            });

            AreaValueModel model = new AreaValueModel {
                Id = 100, Area = "ROM", Value = 100.0d
            };
            ModelVersions modelVersions = new ModelVersions(amplaRecord);
            IModelProperties <AreaValueModel> modelProperties = new ModelProperties <AreaValueModel>();

            AmplaViewProperties <AreaValueModel> viewProperties = new AmplaViewProperties <AreaValueModel>(modelProperties);
            GetViewsResponse view = new GetViewsResponse
            {
                Context = new GetViewsResponseContext(),
                Views   = new[] { ProductionViews.AreaValueModelView() }
            };

            viewProperties.Initialise(view);
            AmplaGetDataVersionsBinding <AreaValueModel> binding =
                new AmplaGetDataVersionsBinding <AreaValueModel>(amplaRecord, auditRecord, model, modelVersions,
                                                                 modelProperties, viewProperties);

            Assert.That(binding.Validate(), Is.True);
            Assert.That(binding.Bind(), Is.True);

            Assert.That(modelVersions.Versions, Is.Not.Empty);
            Assert.That(modelVersions.Versions.Count, Is.EqualTo(2));

            ModelVersion <AreaValueModel> last    = (ModelVersion <AreaValueModel>)modelVersions.Versions[0];
            ModelVersion <AreaValueModel> current = (ModelVersion <AreaValueModel>)modelVersions.Versions[1];

            Assert.That(last.IsCurrentVersion, Is.False);
            Assert.That(current.IsCurrentVersion, Is.True);

            Assert.That(last.Model.Area, Is.EqualTo(model.Area));
            Assert.That(current.Model.Area, Is.EqualTo(model.Area));

            Assert.That(last.Model.Value, Is.EqualTo(0d));
            Assert.That(current.Model.Value, Is.EqualTo(100d));

            Assert.That(last.Model.Id, Is.EqualTo(100));
            Assert.That(current.Model.Id, Is.EqualTo(100));
        }