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"));
        }
        public void CreatedByDefault()
        {
            SimpleDataWebServiceClient webServiceClient = Create();

            InMemoryRecord record = ProductionRecords.NewRecord().MarkAsNew();

            SubmitDataRequest request = new SubmitDataRequest
            {
                Credentials       = CreateCredentials(),
                SubmitDataRecords = new[]
                {
                    record.ConvertToSubmitDataRecord()
                }
            };

            DateTime before = DateTime.Now.AddSeconds(-10).ToUniversalTime();
            DateTime after  = before.AddSeconds(+20);

            SubmitDataResponse response = webServiceClient.SubmitData(request);

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

            Assert.That(DatabaseRecords.Count, Is.EqualTo(1));
            InMemoryRecord inserted = DatabaseRecords[0];

            Assert.That(inserted.GetFieldValue("CreatedBy", "null"), Is.EqualTo("User"));
            Assert.That(inserted.GetFieldValue("CreatedDateTime", DateTime.MinValue), Is.InRange(before, after));
        }
Exemplo n.º 3
0
        public void RecordUsesUtcTime()
        {
            Assert.That(Records, Is.Empty);

            DateTime beforeUtc = DateTime.UtcNow.AddMinutes(-5);
            DateTime afterUtc  = DateTime.UtcNow.AddMinutes(+5);

            DateTime beforeLocal = beforeUtc.ToLocalTime();
            DateTime afterLocal  = afterUtc.ToLocalTime();

            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.GreaterThan(beforeUtc).And.LessThan(afterUtc));

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

            AreaValueModel updated = Repository.FindById(record.RecordId);

            Assert.That(updated.Sample, Is.GreaterThan(beforeLocal).And.LessThan(afterLocal));
        }
Exemplo n.º 4
0
        public void ModelsUseLocalTime()
        {
            Assert.That(Records, Is.Empty);

            DateTime localHour = DateTime.Now.TrimToHour();

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

            DateTime utcHour = localHour.ToUniversalTime();

            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.EqualTo(utcHour));

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

            AreaValueModel updated = Repository.FindById(record.RecordId);

            Assert.That(updated.Sample, Is.EqualTo(localHour));
        }
        public void CreatedBySetInRequest()
        {
            SimpleDataWebServiceClient webServiceClient = Create();

            InMemoryRecord record = ProductionRecords.NewRecord().MarkAsNew();

            record.SetFieldValue("CreatedBy", "UnitTests");
            record.SetFieldValue("CreatedDateTime", DateTime.Today);

            SubmitDataRequest request = new SubmitDataRequest
            {
                Credentials       = CreateCredentials(),
                SubmitDataRecords = new[]
                {
                    record.ConvertToSubmitDataRecord()
                }
            };

            SubmitDataResponse response = webServiceClient.SubmitData(request);

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

            Assert.That(DatabaseRecords.Count, Is.EqualTo(1));
            InMemoryRecord inserted = DatabaseRecords[0];

            Assert.That(inserted.GetFieldValue("CreatedBy", "null"), Is.EqualTo("UnitTests"));
            Assert.That(inserted.GetFieldValue("CreatedDateTime", DateTime.MinValue), Is.EqualTo(DateTime.Today.ToUniversalTime()));
        }
Exemplo n.º 6
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.º 7
0
        public void GetViaModel()
        {
            DateTime before = DateTime.Now.AddMinutes(-1);
            DateTime after  = DateTime.Now.AddMinutes(+1);

            LocationModel model = new LocationModel {
                Location = Locations[1]
            };

            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(Locations[1]));
            Assert.That(record.Module, Is.EqualTo("Production"));
            Assert.That(record.GetFieldValue("Sample Period", DateTime.MinValue), Is.InRange(before.ToUniversalTime(), after.ToUniversalTime()));

            LocationModel getModel = Repository.FindById(model.Id);

            Assert.That(getModel.Sample, Is.InRange(before, after));
            Assert.That(getModel.Location, Is.EqualTo(Locations[1]));
        }
Exemplo n.º 8
0
        public void SaveUsingModelClass()
        {
            ProductionModel model = new ProductionModel {
                Location = location
            };

            DateTime before = DateTime.UtcNow.AddSeconds(-1);

            dynamic record = ViewPoint.Save(model);

            DateTime after = before.AddSeconds(5);

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

            Assert.That(record.Location, Is.EqualTo(location));

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

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

            InMemoryRecord amplaRecord = Records[0];

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

            Assert.That(amplaRecord.Location, Is.EqualTo(location));
            Assert.That(amplaRecord.Module, Is.EqualTo(module));

            Assert.That(amplaRecord.GetFieldValue("Sample Period", DateTime.MinValue), Is.InRange(before, after));
        }
        public void DefaultStartTimeAndEndTime()
        {
            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.GetFieldValue("Planned Start Time", DateTime.MinValue), Is.GreaterThan(DateTime.MinValue));
            Assert.That(record.GetFieldValue("Planned End Time", DateTime.MinValue), Is.GreaterThan(DateTime.MinValue));
        }
        public void SubmitWithValidCauseLocation()
        {
            IdentifierEnergyModel model = new IdentifierEnergyModel {
                Location = location, StartTime = DateTime.Now, CauseLocation = "Enterprise.Site"
            };

            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.GetFieldValue("Cause Location", string.Empty), Is.EqualTo("Enterprise.Site"));
        }
        public void WithEmptyActivityId()
        {
            SimplePlanningModel model = new SimplePlanningModel {
                Location = location, ActivityId = string.Empty
            };

            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.º 12
0
        public void UpdateModelWithNoChanges()
        {
            Assert.That(Records, Is.Empty);

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

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

            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(model.Id, Is.EqualTo(record.RecordId));

            AreaValueModel updateModel = Repository.FindById(model.Id);

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

            int currentMessages = Messages.Count;

            Assert.That(currentMessages, Is.GreaterThan(0));

            updateModel.Value = 100;
            Repository.Update(updateModel);

            Assert.That(Messages.Count, Is.EqualTo(currentMessages + 1), string.Join("\r\n", Messages));
            // record is not submitted
            Assert.That(Records.Count, Is.EqualTo(1));

            record = Records[0];
            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.RecordId, Is.EqualTo(model.Id));
            Assert.That(record.GetFieldValue("Area", ""), Is.EqualTo("ROM"));
            Assert.That(record.GetFieldValue <double>("Value", 0), Is.EqualTo(100.0d));
        }
Exemplo n.º 13
0
        public void AddNewModelWithExistingId()
        {
            Assert.That(Records, Is.Empty);

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

            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.RecordId, Is.Not.EqualTo(99));
            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(model.Id, Is.EqualTo(record.RecordId));
        }
Exemplo n.º 14
0
        public void SubmitWithBasicFields()
        {
            SimpleQualityModel model = new SimpleQualityModel
            {
                Location     = location,
                SamplePeriod = DateTime.Today,
                Duration     = 600
            };

            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("Sample Period", DateTime.MinValue), Is.EqualTo(DateTime.Today.ToUniversalTime()));
            Assert.That(record.GetFieldValue("Duration", 0), Is.EqualTo(600));
        }
Exemplo n.º 15
0
        public void UpdateModel()
        {
            Assert.That(Records, Is.Empty);

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

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

            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(model.Id, Is.EqualTo(record.RecordId));

            AreaValueModel updateModel = Repository.FindById(model.Id);

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

            updateModel.Value = 200;
            Repository.Update(updateModel);

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

            record = Records[0];
            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.RecordId, Is.EqualTo(model.Id));
            Assert.That(record.GetFieldValue("Area", ""), Is.EqualTo("ROM"));
            Assert.That(record.GetFieldValue <double>("Value", 0), Is.EqualTo(200.0d));
        }
        public void SubmitWithClassification()
        {
            IdentifierEnergyModel model = new IdentifierEnergyModel {
                Location = location, StartTime = DateTime.Now, Classification = 200
            };

            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.GetFieldValue("Classification", -1), Is.EqualTo(200));
        }
Exemplo n.º 17
0
        public void AddAValidLocation()
        {
            LocationModel model = new LocationModel {
                Location = Locations[1]
            };

            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(Locations[1]));
            Assert.That(record.Module, Is.EqualTo("Production"));
            Assert.That(record.GetFieldValue("Sample Period", DateTime.MinValue), Is.GreaterThan(DateTime.MinValue));
        }
        public void DefaultStartTime()
        {
            DateTime before = DateTime.Now.AddMinutes(-1);
            DateTime after  = DateTime.Now.AddMinutes(+1);

            SimpleKnowledgeModel model = new SimpleKnowledgeModel {
                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.GetFieldValue("Sample Period", DateTime.MinValue), Is.InRange(before.ToUniversalTime(), after.ToUniversalTime()));
        }
Exemplo n.º 19
0
        public override bool Matches(InMemoryRecord record)
        {
            T fieldValue = record.GetFieldValue(field, default(T));

            return(Equals(fieldValue, value));
        }