Exemplo n.º 1
0
        public void SubmitWithNullFields()
        {
            SimpleEnergyModel model = new SimpleEnergyModel
            {
                Location       = location,
                StartTime      = DateTime.Now,
                CauseLocation  = null,
                Cause          = null,
                Classification = null
            };

            Repository.Add(model);

            Assert.That(model.Id, Is.GreaterThan(0));

            Assert.That(Records, Is.Not.Empty);

            InMemoryRecord record = Records[0];

            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Module, Is.EqualTo(module));
            Assert.That(record.GetFieldValue("Start Time", DateTime.MinValue), Is.GreaterThan(DateTime.MinValue));
            Assert.That(record.Find("Cause Location"), Is.Null);
            Assert.That(record.Find("Cause"), Is.Null);
            Assert.That(record.Find("Classification"), Is.Null);
        }
Exemplo n.º 2
0
        private DataSubmissionResult UpdateDataRecord(SubmitDataRecord submitDataRecord, string user)
        {
            int recordId = (int)submitDataRecord.MergeCriteria.SetId;

            Dictionary <int, InMemoryRecord> database = amplaDatabase.GetModuleRecords(submitDataRecord.Module.ToString());

            InMemoryRecord record   = FindRecord(database, submitDataRecord.Location, submitDataRecord.Module, recordId);
            DateTime       editTime = DateTime.UtcNow;

            foreach (Field field in submitDataRecord.Fields)
            {
                string oldValue = string.Empty;

                FieldValue fieldValue = record.Find(field.Name);
                if (fieldValue == null)
                {
                    record.Fields.Add(new FieldValue(field.Name, field.Value));
                }
                else
                {
                    oldValue         = fieldValue.Value;
                    fieldValue.Value = field.Value;
                }
                AddAuditRecord(record, editTime, field.Name, oldValue, field.Value, user);
            }

            return(new DataSubmissionResult
            {
                RecordAction = RecordAction.Update,
                SetId = recordId
            });
        }
Exemplo n.º 3
0
 private void AddDefault <T>(InMemoryRecord amplaRecord, string field, T defaultValue)
 {
     if (amplaRecord.Find(field) == null)
     {
         amplaRecord.SetFieldValue(field, defaultValue);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Updates the record status.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <returns></returns>
 public UpdateRecordStatusResponse UpdateRecordStatus(UpdateRecordStatusRequest request)
 {
     return(TryCatchThrowFault(() =>
     {
         List <UpdateRecordStatusResult> results = new List <UpdateRecordStatusResult>();
         CheckCredentials(request.Credentials);
         foreach (UpdateRecordStatus recordStatus in request.UpdateRecords)
         {
             string module = recordStatus.Module.ToString();
             Dictionary <int, InMemoryRecord> database = amplaDatabase.GetModuleRecords(module);
             CheckReportingPoint(module, recordStatus.Location);
             int recordId = (int)recordStatus.MergeCriteria.SetId;
             InMemoryRecord record = FindRecord(database, recordStatus.Location, recordStatus.Module, recordId);
             FieldValue confirmed = record.Find("Confirmed");
             if (confirmed != null)
             {
                 record.Fields.Remove(confirmed);
             }
             string value = recordStatus.RecordAction == UpdateRecordStatusAction.Confirm ? "True" : "False";
             record.Fields.Add(new FieldValue("Confirmed", value));
             results.Add(new UpdateRecordStatusResult
             {
                 Location = recordStatus.Location,
                 Module = recordStatus.Module,
                 RecordAction = recordStatus.RecordAction,
                 SetId = recordId
             });
         }
         return new UpdateRecordStatusResponse {
             UpdateRecordStatusResults = results.ToArray()
         };
     }));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Deletes the records.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public DeleteRecordsResponse DeleteRecords(DeleteRecordsRequest request)
        {
            return(TryCatchThrowFault(() =>
            {
                DateTime editTime = DateTime.Now;
                List <DeleteRecordsResult> results = new List <DeleteRecordsResult>();
                string user = CheckCredentials(request.Credentials);
                foreach (DeleteRecord deleteRecord in request.DeleteRecords)
                {
                    Dictionary <int, InMemoryRecord> database = amplaDatabase.GetModuleRecords(deleteRecord.Module.ToString());

                    CheckReportingPoint(deleteRecord.Module.ToString(), deleteRecord.Location);
                    int recordId = (int)deleteRecord.MergeCriteria.SetId;
                    InMemoryRecord record = FindRecord(database, deleteRecord.Location, deleteRecord.Module, recordId);
                    FieldValue deleted = record.Find("Deleted");
                    if (deleted != null)
                    {
                        record.Fields.Remove(deleted);
                    }
                    record.Fields.Add(new FieldValue("Deleted", "True"));
                    AddAuditRecord(record, editTime, "IsDeleted", false.ToString(), true.ToString(), user);

                    results.Add(new DeleteRecordsResult
                    {
                        Location = deleteRecord.Location,
                        Module = deleteRecord.Module,
                        RecordAction = DeleteRecordsAction.Delete,
                        SetId = recordId
                    });
                }
                return new DeleteRecordsResponse {
                    DeleteRecordsResults = results.ToArray()
                };
            }));
        }
        public void SubmitWithBasicFields()
        {
            SimplePlanningModel model = new SimplePlanningModel
            {
                Location     = location,
                PlannedStart = DateTime.Today,
                PlannedEnd   = DateTime.Today.AddDays(1),
                State        = "Available",
                ActivityId   = "ABC-123"
            };

            Repository.Add(model);

            Assert.That(model.Id, Is.GreaterThan(0));

            Assert.That(Records, Is.Not.Empty);

            InMemoryRecord record = Records[0];

            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Module, Is.EqualTo(module));
            Assert.That(record.GetFieldValue("Planned Start Time", DateTime.MinValue), Is.EqualTo(DateTime.Today.ToUniversalTime()));
            Assert.That(record.GetFieldValue("Planned End Time", DateTime.MinValue), Is.EqualTo(DateTime.Today.AddDays(1).ToUniversalTime()));
            Assert.That(record.Find("State"), Is.Null);
            Assert.That(record.GetFieldValue("ActivityId", ""), Is.EqualTo("ABC-123"));
        }
Exemplo n.º 7
0
        public void SubmitWithClassificationAsString()
        {
            SimpleEnergyModel model = new SimpleEnergyModel {
                Location = location, StartTime = DateTime.Now, Classification = "Unplanned Process"
            };

            Repository.Add(model);

            Assert.That(model.Id, Is.GreaterThan(0));

            Assert.That(Records, Is.Not.Empty);

            InMemoryRecord record = Records[0];

            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Find("Classification"), Is.Null);
        }
Exemplo n.º 8
0
        public void SubmitWithCauseAsString()
        {
            SimpleEnergyModel model = new SimpleEnergyModel {
                Location = location, StartTime = DateTime.Now, Cause = "Broken"
            };

            Repository.Add(model);

            Assert.That(model.Id, Is.GreaterThan(0));

            Assert.That(Records, Is.Not.Empty);

            InMemoryRecord record = Records[0];

            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Find("Cause"), Is.Null);
        }
        public void NullActivityId()
        {
            SimplePlanningModel model = new SimplePlanningModel {
                Location = location
            };

            Repository.Add(model);

            Assert.That(model.Id, Is.GreaterThan(0));

            Assert.That(Records, Is.Not.Empty);

            InMemoryRecord record = Records[0];

            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Find("ActivityId"), Is.Null);
            Assert.That(record.GetFieldValue("Planned Start Time", DateTime.MinValue), Is.GreaterThan(DateTime.MinValue));
            Assert.That(record.GetFieldValue("Planned End Time", DateTime.MinValue), Is.GreaterThan(DateTime.MinValue));
        }
Exemplo n.º 10
0
        public void DefaultStartTime()
        {
            DateTime before = DateTime.Now.AddMinutes(-1);
            DateTime after  = DateTime.Now.AddMinutes(+1);

            SimpleEnergyModel model = new SimpleEnergyModel {
                Location = location
            };

            Repository.Add(model);

            Assert.That(model.Id, Is.GreaterThan(0));

            Assert.That(Records, Is.Not.Empty);

            InMemoryRecord record = Records[0];

            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Find("Sample Period"), Is.Null);
            Assert.That(record.GetFieldValue("Start Time", DateTime.MinValue), Is.InRange(before.ToUniversalTime(), after.ToUniversalTime()));
        }
Exemplo n.º 11
0
        public void AddNewModel()
        {
            Assert.That(Records, Is.Empty);

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

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

            InMemoryRecord record = Records[0];

            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.RecordId, Is.GreaterThan(0));
            Assert.That(record.GetFieldValue("Area", ""), Is.EqualTo("ROM"));
            Assert.That(record.GetFieldValue <double>("Value", 0), Is.EqualTo(100.0d));
            Assert.That(record.GetFieldValue("Sample Period", DateTime.MinValue), Is.Not.EqualTo(DateTime.MinValue));
            Assert.That(record.Find("Location"), Is.Not.Null);

            Assert.That(model.Id, Is.EqualTo(record.RecordId));
        }