protected override void OnSetUp()
        {
            base.OnSetUp();
            database = new SimpleAmplaDatabase();
            database.EnableModule(module);

            configuration = new SimpleAmplaConfiguration();
            configuration.EnableModule(module);
            configuration.AddLocation(module, location);
            configuration.SetDefaultView(module, ProductionViews.AreaValueModelView());

            webServiceClient = new SimpleDataWebServiceClient(database, configuration, new SimpleSecurityWebServiceClient("User"));
            repository       = new AmplaReadOnlyRepository <AreaValueModel>(new AmplaRepository <AreaValueModel>(webServiceClient, credentialsProvider));
        }
        public void GetVersion_NotRelevantChanges()
        {
            Assert.That(Records, Is.Empty);

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

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

            int recordId = Records[0].RecordId;

            InMemoryRecord record = new InMemoryRecord(ProductionViews.AreaValueModelView())
            {
                Module   = module,
                Location = location,
                RecordId = recordId
            };

            record.SetFieldValue("Sample Period", DateTime.Today);

            UpdateRecord(record);

            Assert.That(Records.Count, Is.EqualTo(1));
            Assert.That(Records[0].GetFieldValue("Sample Period", DateTime.MinValue), Is.EqualTo(DateTime.Today.ToUniversalTime()));

            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));  // one version change ('Sample Period') is not relevant

            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(current.Model, Is.Not.Null);
            Assert.That(current.IsCurrentVersion, Is.True);
            Assert.That(current.Model.Id, Is.EqualTo(model.Id));
            Assert.That(current.Model.Value, Is.EqualTo(model.Value));
            Assert.That(current.Model.Area, Is.EqualTo(model.Area));
        }
Esempio n. 3
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));
        }