コード例 #1
0
        public void GetHistory_NoChanges()
        {
            Assert.That(Records, Is.Empty);

            AreaValueModel model = new AreaValueModel {
                Area = "ROM", Value = 100
            };

            Repository.Add(model);
            Assert.That(Records.Count, Is.EqualTo(1));

            AmplaRecord record = Repository.FindRecord(model.Id);

            Assert.That(record, Is.Not.Null);

            Assert.That(record.GetValue("Area"), Is.EqualTo(model.Area));
            Assert.That(record.GetValue("Value"), Is.EqualTo(model.Value));
            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Id, Is.EqualTo(model.Id));

            AmplaAuditRecord auditRecord = Repository.GetHistory(model.Id);

            Assert.That(auditRecord, Is.Not.Null);

            Assert.That(auditRecord.Id, Is.EqualTo(model.Id));
            Assert.That(auditRecord.Location, Is.EqualTo(location));
            Assert.That(auditRecord.Module, Is.EqualTo(module));
            Assert.That(auditRecord.Changes, Is.Empty);
        }
コード例 #2
0
        public void GetHistory_WithChanges()
        {
            Assert.That(Records, Is.Empty);

            AreaValueModel model = new AreaValueModel {
                Area = "ROM", Value = 100
            };

            Repository.Add(model);
            Assert.That(Records.Count, Is.EqualTo(1));

            AmplaRecord record = Repository.FindRecord(model.Id);

            Assert.That(record, Is.Not.Null);

            Assert.That(record.GetValue("Area"), Is.EqualTo(model.Area));
            Assert.That(record.GetValue("Value"), Is.EqualTo(model.Value));
            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Id, Is.EqualTo(model.Id));

            AreaValueModel updated = new AreaValueModel {
                Id = model.Id, Area = "ROM", Value = 200
            };

            DateTime before = DateTime.Now.AddMinutes(-1);
            DateTime after  = DateTime.Now.AddMinutes(+1);

            Repository.Update(updated);
            record = Repository.FindRecord(model.Id);
            Assert.That(record, Is.Not.Null);

            Assert.That(record.GetValue("Area"), Is.EqualTo(model.Area));
            Assert.That(record.GetValue("Value"), Is.EqualTo(200));
            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Id, Is.EqualTo(model.Id));

            AmplaAuditRecord auditRecord = Repository.GetHistory(model.Id);

            Assert.That(auditRecord, Is.Not.Null);

            Assert.That(auditRecord.Id, Is.EqualTo(model.Id));
            Assert.That(auditRecord.Location, Is.EqualTo(location));
            Assert.That(auditRecord.Module, Is.EqualTo(module));
            Assert.That(auditRecord.Changes, Is.Not.Empty);
            Assert.That(auditRecord.Changes.Count, Is.EqualTo(1));

            AmplaAuditSession session = auditRecord.Changes[0];

            Assert.That(session.User, Is.EqualTo("User"));
            Assert.That(session.EditedTime, Is.InRange(before, after));
            Assert.That(session.Fields, Is.Not.Empty);

            AssertAuditField(session, "Value", "100", "200");
        }
コード例 #3
0
        public void FindRecord()
        {
            AreaModel match = new AreaModel {
                Area = "ROM", Value = 200
            };
            AreaModel noMatch = new AreaModel {
                Area = "ROM", Value = 100
            };
            AreaModel extra = new AreaModel {
                Area = "Mining", Value = 100
            };

            Repository.Add(match);
            Repository.Add(noMatch);
            Repository.Add(extra);

            Assert.That(Records.Count, Is.EqualTo(3));

            AmplaRecord record = Repository.FindRecord(match.Id);

            Assert.That(record, Is.Not.Null);
            Assert.That(record.GetValue("Area"), Is.EqualTo("ROM"));

            // it should not find a record that doesn't match the default filter
            record = Repository.FindRecord(extra.Id);

            Assert.That(record, Is.Null);
        }
コード例 #4
0
        public void GetVersions_NoChanges()
        {
            Assert.That(Records, Is.Empty);

            AreaValueModel model = new AreaValueModel {
                Area = "ROM", Value = 100
            };

            Repository.Add(model);
            Assert.That(Records.Count, Is.EqualTo(1));

            AmplaRecord record = Repository.FindRecord(model.Id);

            Assert.That(record, Is.Not.Null);

            Assert.That(record.GetValue("Area"), Is.EqualTo(model.Area));
            Assert.That(record.GetValue("Value"), Is.EqualTo(model.Value));
            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Id, Is.EqualTo(model.Id));

            ModelVersions versions = Repository.GetVersions(model.Id);

            Assert.That(versions, Is.Not.Null);
            Assert.That(versions.Versions, Is.Not.Empty);
            Assert.That(versions.Id, Is.EqualTo(record.Id));
            Assert.That(versions.Location, Is.EqualTo(record.Location));
            Assert.That(versions.Module, Is.EqualTo(record.Module));
            Assert.That(versions.ModelName, Is.EqualTo("Area Value Model"));

            ModelVersion <AreaValueModel> version = (ModelVersion <AreaValueModel>)versions.Versions[0];

            Assert.That(version.Model, Is.Not.Null);
            Assert.That(version.Model.Id, Is.EqualTo(model.Id));
            Assert.That(version.Model.Value, Is.EqualTo(model.Value));
            Assert.That(version.Model.Area, Is.EqualTo(model.Area));

            Assert.That(version.IsCurrentVersion, Is.True);
        }
コード例 #5
0
        public void AmplaRecordShowsLocalTime()
        {
            Assert.That(Records, Is.Empty);

            DateTime localHour = DateTime.Now.TrimToHour();

            AreaValueModel model = new AreaValueModel {
                Area = "ROM", Value = 100, Sample = localHour
            };

            Repository.Add(model);
            Assert.That(Records, Is.Not.Empty);

            int recordId = Records[0].RecordId;

            AmplaRecord record = Repository.FindRecord(recordId);

            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Id, Is.EqualTo(recordId));
            Assert.That(record.GetValue("Area"), Is.EqualTo("ROM"));
            Assert.That(record.GetValue("Value"), Is.EqualTo(100.0d));
            Assert.That(record.GetValue("Sample Period"), Is.EqualTo(localHour));
        }
コード例 #6
0
        public void GetVersion_WithChanges()
        {
            Assert.That(Records, Is.Empty);

            DateTime       beforeAdd = DateTime.Now.AddSeconds(-1);
            AreaValueModel model     = new AreaValueModel {
                Area = "ROM", Value = 100
            };

            Repository.Add(model);

            DateTime afterAdd = DateTime.Now.AddSeconds(+1);

            Assert.That(Records.Count, Is.EqualTo(1));

            AmplaRecord record = Repository.FindRecord(model.Id);

            Assert.That(record, Is.Not.Null);

            DateTime beforeUpdate = DateTime.Now.AddSeconds(-1);

            AreaValueModel updated = new AreaValueModel {
                Id = model.Id, Area = "ROM", Value = 200
            };

            DateTime afterUpdate = DateTime.Now.AddSeconds(1);

            Repository.Update(updated);
            record = Repository.FindRecord(model.Id);
            Assert.That(record, Is.Not.Null);

            Assert.That(record.GetValue("Area"), Is.EqualTo(model.Area));
            Assert.That(record.GetValue("Value"), Is.EqualTo(200));
            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Id, Is.EqualTo(model.Id));

            ModelVersions versions = Repository.GetVersions(model.Id);

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

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

            Assert.That(last.Model, Is.Not.Null);
            Assert.That(last.IsCurrentVersion, Is.False);
            Assert.That(last.Model.Id, Is.EqualTo(model.Id));
            Assert.That(last.Model.Value, Is.EqualTo(model.Value));
            Assert.That(last.Model.Area, Is.EqualTo(model.Area));
            Assert.That(last.User, Is.EqualTo("User"));
            Assert.That(last.VersionDate, Is.InRange(beforeAdd, afterAdd));
            Assert.That(last.Version, Is.EqualTo(1));

            Assert.That(current.Model, Is.Not.Null);
            Assert.That(current.IsCurrentVersion, Is.True);
            Assert.That(current.Model.Id, Is.EqualTo(updated.Id));
            Assert.That(current.Model.Value, Is.EqualTo(updated.Value));
            Assert.That(current.Model.Area, Is.EqualTo(updated.Area));
            Assert.That(current.User, Is.EqualTo("User"));
            Assert.That(current.VersionDate, Is.InRange(beforeUpdate, afterUpdate));
            Assert.That(current.Version, Is.EqualTo(2));
        }