Пример #1
0
        private void AssertPropertyNotGetValue <TModel>(ModelProperties <TModel> modelProperties, TModel model, string property) where TModel : new()
        {
            string value;
            bool   result = modelProperties.TryGetPropertyValue(model, property, out value);

            Assert.That(result, Is.False, "Unexpected Result for {0}", property);
        }
Пример #2
0
        public void RoundTripEmptyProperties()
        {
            SimpleModel model = new SimpleModel {
                Id = 1, Name = string.Empty, Value = 0
            };
            SimpleModel newModel = new SimpleModel();

            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            string id;
            string name;
            string value;

            modelProperties.TryGetPropertyValue(model, "Id", out id);
            modelProperties.TryGetPropertyValue(model, "Name", out name);
            modelProperties.TryGetPropertyValue(model, "Value", out value);

            modelProperties.TrySetValueFromString(newModel, "Id", id);
            modelProperties.TrySetValueFromString(newModel, "Name", name);
            modelProperties.TrySetValueFromString(newModel, "Value", value);

            Assert.That(newModel.Id, Is.EqualTo(1));
            Assert.That(newModel.Name, Is.EqualTo(string.Empty));
            Assert.That(newModel.Value, Is.EqualTo(0));
        }
Пример #3
0
        public void GetLocationWithRecurse()
        {
            SimpleModelWithRecurse model = new SimpleModelWithRecurse();
            ModelProperties <SimpleModelWithRecurse> modelProperties = new ModelProperties <SimpleModelWithRecurse>();

            Assert.That(modelProperties.GetLocation(model), Is.EqualTo(null));
        }
Пример #4
0
        public void GetLocationWithoutRecurse()
        {
            SimpleModel model = new SimpleModel();
            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            Assert.That(modelProperties.GetLocation(model), Is.EqualTo("Enterprise.Site.Area.Simple"));
        }
Пример #5
0
        public void RoundTripProperties()
        {
            SimpleModel model = new SimpleModel {
                Id = 100, Name = "Ampla", Value = 1.234
            };
            SimpleModel newModel = new SimpleModel();

            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            string id;
            string name;
            string value;

            modelProperties.TryGetPropertyValue(model, "Id", out id);
            modelProperties.TryGetPropertyValue(model, "Name", out name);
            modelProperties.TryGetPropertyValue(model, "Value", out value);

            modelProperties.TrySetValueFromString(newModel, "Id", id);
            modelProperties.TrySetValueFromString(newModel, "Name", name);
            modelProperties.TrySetValueFromString(newModel, "Value", value);

            Assert.That(newModel.Id, Is.EqualTo(100));
            Assert.That(newModel.Name, Is.EqualTo("Ampla"));
            Assert.That(newModel.Value, Is.EqualTo(1.234D));
        }
Пример #6
0
        private void AssertPropertyGetValue <TModel>(ModelProperties <TModel> modelProperties, TModel model, string property, string expected) where TModel : new()
        {
            string value;
            bool   result = modelProperties.TryGetPropertyValue(model, property, out value);

            Assert.That(result, Is.True, "Unexpected Result for {0}", property);
            Assert.That(value, Is.EqualTo(expected), "TryGetPropertyValue('{0}')", property);
        }
        public void GetPropertiesReturnsAmplaField()
        {
            ModelProperties <ModelWithAmplaField> modelProperties = new ModelProperties <ModelWithAmplaField>();

            var properties = modelProperties.GetProperties();

            Assert.That(properties.Count, Is.EqualTo(1));
            Assert.That(properties[0], Is.EqualTo("Full Name"));
        }
        public void GetPropertiesReturnsAmplaField()
        {
            ModelProperties <ModelWithTimeSpanField> modelProperties = new ModelProperties <ModelWithTimeSpanField>();

            var properties = modelProperties.GetProperties();

            Assert.That(properties.Count, Is.EqualTo(1));
            Assert.That(properties[0], Is.EqualTo("Duration"));
        }
Пример #9
0
        public void TryGetPropertyWithInvalidProperty()
        {
            SimpleModel model = new SimpleModel();

            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            AssertPropertyNotGetValue(modelProperties, model, "InvalidId");
            AssertPropertyNotGetValue(modelProperties, model, "InvalidName");
            AssertPropertyNotGetValue(modelProperties, model, "InvalidValue");
        }
Пример #10
0
        public void TryGetPropertyWithDefaultValues()
        {
            SimpleModel model = new SimpleModel();

            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            AssertPropertyGetValue(modelProperties, model, "Id", "0");
            AssertPropertyGetValue(modelProperties, model, "Name", null);
            AssertPropertyGetValue(modelProperties, model, "Value", "0");
        }
Пример #11
0
        public void TryGetPropertyWithEmptyValues()
        {
            SimpleModel model = new SimpleModel {
                Id = 0, Name = "", Value = 0D
            };

            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            AssertPropertyGetValue(modelProperties, model, "Id", "0");
            AssertPropertyGetValue(modelProperties, model, "Name", "");
            AssertPropertyGetValue(modelProperties, model, "Value", "0");
        }
Пример #12
0
        public void TryGetPropertyWithValidValues()
        {
            SimpleModel model = new SimpleModel {
                Id = 100, Name = "Ampla", Value = 1.234
            };

            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            AssertPropertyGetValue(modelProperties, model, "Id", "100");
            AssertPropertyGetValue(modelProperties, model, "Name", "Ampla");
            AssertPropertyGetValue(modelProperties, model, "Value", "1.234");
        }
        public void SetAmplaFieldProperty()
        {
            ModelProperties <ModelWithAmplaField> modelProperties = new ModelProperties <ModelWithAmplaField>();
            ModelWithAmplaField model = new ModelWithAmplaField {
                FullName = "John Doe"
            };

            bool result = modelProperties.TrySetValueFromString(model, "Full Name", "Jane Doe");

            Assert.That(model.FullName, Is.EqualTo("Jane Doe"));
            Assert.That(result, Is.True);
        }
Пример #14
0
        public void SetAmplaFieldProperty()
        {
            ModelProperties <ModelWithLocationField> modelProperties = new ModelProperties <ModelWithLocationField>();
            ModelWithLocationField model = new ModelWithLocationField {
                Location = "Enterprise.Site"
            };

            bool result = modelProperties.TrySetValueFromString(model, "Location", "Enterprise.Site.Area");

            Assert.That(model.Location, Is.EqualTo("Enterprise.Site.Area"));
            Assert.That(result, Is.True);
        }
        public void SetAmplaFieldProperty()
        {
            ModelProperties <ModelWithTimeSpanField> modelProperties = new ModelProperties <ModelWithTimeSpanField>();
            ModelWithTimeSpanField model = new ModelWithTimeSpanField {
                Display = TimeSpan.FromHours(1)
            };

            bool result = modelProperties.TrySetValueFromString(model, "Duration", "1800");

            Assert.That(model.Display, Is.EqualTo(TimeSpan.FromMinutes(30)));
            Assert.That(result, Is.True);
        }
Пример #16
0
        public void TestInheritedModel()
        {
            ModelProperties <InheritedModel> modelProperties = new ModelProperties <InheritedModel>();

            Assert.That(modelProperties.GetLocation(null), Is.EqualTo("Enterprise.Site.Area.Simple"));
            Assert.That(modelProperties.Module, Is.EqualTo(AmplaModules.Production));

            IList <string> properties = modelProperties.GetProperties();

            Assert.That(properties, Contains.Item("Id").And.Contains("Name").And.Contains("Value"));
            Assert.That(properties.Count, Is.EqualTo(3));
        }
Пример #17
0
        public void IsDefaultValue()
        {
            SimpleModel model = new SimpleModel();
            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            Assert.That(modelProperties.IsDefaultValue(model, "Id"), Is.True, "Id");
            Assert.That(modelProperties.IsDefaultValue(model, "Value"), Is.True, "Value");
            model.Id = 100;
            Assert.That(modelProperties.IsDefaultValue(model, "Id"), Is.False, "Id");
            model.Value = 12.34;
            Assert.That(modelProperties.IsDefaultValue(model, "Value"), Is.False, "Value");
        }
Пример #18
0
        public void TestReadOnlyProperties()
        {
            ModelWithReadOnly model = new ModelWithReadOnly();

            ModelProperties <ModelWithReadOnly> modelProperties = new ModelProperties <ModelWithReadOnly>();

            Assert.That(modelProperties.GetProperties().Count, Is.EqualTo(4));

            model.Name = "name1";
            AssertPropertyGetValue(modelProperties, model, "ReadOnlyName", "name1");
            AssertPropertyNotSetValue(modelProperties, model, "ReadOnlyName", "invalid name");
        }
Пример #19
0
        public void GetAmplaFieldProperty()
        {
            ModelProperties <ModelWithLocationField> modelProperties = new ModelProperties <ModelWithLocationField>();
            ModelWithLocationField model = new ModelWithLocationField {
                Location = "Enterprise.Site"
            };

            string value;
            bool   result = modelProperties.TryGetPropertyValue(model, "Location", out value);

            Assert.That(value, Is.EqualTo("Enterprise.Site"));
            Assert.That(result, Is.True);
        }
        public void GetAmplaFieldProperty()
        {
            ModelProperties <ModelWithAmplaField> modelProperties = new ModelProperties <ModelWithAmplaField>();
            ModelWithAmplaField model = new ModelWithAmplaField {
                FullName = "John Doe"
            };

            string value;
            bool   result = modelProperties.TryGetPropertyValue(model, "Full Name", out value);

            Assert.That(value, Is.EqualTo("John Doe"));
            Assert.That(result, Is.True);
        }
        public void GetAmplaFieldProperty()
        {
            ModelProperties <ModelWithTimeSpanField> modelProperties = new ModelProperties <ModelWithTimeSpanField>();
            ModelWithTimeSpanField model = new ModelWithTimeSpanField {
                Display = TimeSpan.FromHours(1)
            };

            string value;
            bool   result = modelProperties.TryGetPropertyValue(model, "Duration", out value);

            Assert.That(value, Is.EqualTo("3600"));
            Assert.That(result, Is.True);
        }
Пример #22
0
        public void GetLocationDefault()
        {
            ModelProperties <ModelWithLocationField> modelProperties = new ModelProperties <ModelWithLocationField>();
            ModelWithLocationField model = new ModelWithLocationField {
                Location = null
            };

            Assert.That(modelProperties.GetLocation(null), Is.EqualTo("Enterprise"));
            Assert.That(modelProperties.GetLocation(model), Is.EqualTo("Enterprise"));

            model.Location = "Enterprise.Site.Area";

            Assert.That(modelProperties.GetLocation(model), Is.EqualTo("Enterprise.Site.Area"));
        }
Пример #23
0
        public void TrySetPropertyWithValidValues()
        {
            SimpleModel model = new SimpleModel();

            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            AssertPropertySetValue(modelProperties, model, "Id", "100");
            AssertPropertySetValue(modelProperties, model, "Name", "Ampla");
            AssertPropertySetValue(modelProperties, model, "Value", "1.234");

            Assert.That(model.Id, Is.EqualTo(100));
            Assert.That(model.Name, Is.EqualTo("Ampla"));
            Assert.That(model.Value, Is.EqualTo(1.234D));
        }
Пример #24
0
        public void GetPropertiesReturnsLocationField()
        {
            ModelProperties <ModelWithLocationField> modelProperties = new ModelProperties <ModelWithLocationField>();
            ModelWithLocationField model = new ModelWithLocationField();

            var properties = modelProperties.GetProperties();

            Assert.That(properties.Count, Is.EqualTo(1));
            Assert.That(properties[0], Is.EqualTo("Location"));

            Assert.That(modelProperties.IsDefaultValue(model, "Location"), Is.True);

            model.Location = "Enterprise.Site";
            Assert.That(modelProperties.IsDefaultValue(model, "Location"), Is.False);
        }
Пример #25
0
        public void TrySetPropertyWithEmptyValues()
        {
            SimpleModel model = new SimpleModel {
                Id = 1, Name = "Name", Value = 1.234
            };

            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            AssertPropertySetValue(modelProperties, model, "Id", "0");
            AssertPropertySetValue(modelProperties, model, "Name", "");
            AssertPropertySetValue(modelProperties, model, "Value", "0");

            Assert.That(model.Id, Is.EqualTo(0));
            Assert.That(model.Name, Is.EqualTo(""));
            Assert.That(model.Value, Is.EqualTo(0));
        }
Пример #26
0
        public void TrySetPropertyWithNullValues()
        {
            SimpleModel model = new SimpleModel {
                Id = 1, Name = "Name", Value = 1.234
            };

            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            AssertPropertyNotSetValue(modelProperties, model, "Id", null);
            AssertPropertySetValue(modelProperties, model, "Name", null);
            AssertPropertyNotSetValue(modelProperties, model, "Value", null);

            Assert.That(model.Id, Is.EqualTo(1));
            Assert.That(model.Name, Is.EqualTo(null));
            Assert.That(model.Value, Is.EqualTo(1.234));
        }
Пример #27
0
        public void TestWriteOnlyProperties()
        {
            ModelWithWriteOnly model = new ModelWithWriteOnly();

            ModelProperties <ModelWithWriteOnly> modelProperties = new ModelProperties <ModelWithWriteOnly>();

            Assert.That(modelProperties.GetProperties().Count, Is.EqualTo(4));

            AssertPropertySetValue(modelProperties, model, "Id", "100");
            AssertPropertySetValue(modelProperties, model, "Name", "old name");
            AssertPropertySetValue(modelProperties, model, "Value", "123.4");

            Assert.That(model.Id, Is.EqualTo(100));
            Assert.That(model.Name, Is.EqualTo("old name"));
            Assert.That(model.Value, Is.EqualTo(123.4));

            AssertPropertySetValue(modelProperties, model, "WriteOnlyName", "new name");
            Assert.That(model.Name, Is.EqualTo("new name"));

            AssertPropertyNotGetValue(modelProperties, model, "WriteOnlyName");
        }
Пример #28
0
        public void CloneModel()
        {
            SimpleModel model = new SimpleModel();

            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            SimpleModel clone = modelProperties.CloneModel(model);

            Assert.That(ReferenceEquals(model, clone), Is.False);

            AssertPropertyGetValue(modelProperties, model, "Id", "0");
            AssertPropertyGetValue(modelProperties, model, "Name", null);
            AssertPropertyGetValue(modelProperties, model, "Value", "0");

            AssertPropertyGetValue(modelProperties, clone, "Id", "0");
            AssertPropertyGetValue(modelProperties, clone, "Name", null);
            AssertPropertyGetValue(modelProperties, clone, "Value", "0");

            model.Id++;

            Assert.That(clone.Id, Is.Not.EqualTo(model.Id));
        }
Пример #29
0
        public void CloneModelWithValues()
        {
            SimpleModel model = new SimpleModel {
                Id = 100, Name = "Ampla", Value = 1.234
            };

            ModelProperties <SimpleModel> modelProperties = new ModelProperties <SimpleModel>();

            SimpleModel clone = modelProperties.CloneModel(model);

            Assert.That(ReferenceEquals(model, clone), Is.False);

            AssertPropertyGetValue(modelProperties, model, "Id", "100");
            AssertPropertyGetValue(modelProperties, model, "Name", "Ampla");
            AssertPropertyGetValue(modelProperties, model, "Value", "1.234");

            AssertPropertyGetValue(modelProperties, clone, "Id", "100");
            AssertPropertyGetValue(modelProperties, clone, "Name", "Ampla");
            AssertPropertyGetValue(modelProperties, clone, "Value", "1.234");

            model.Id++;

            Assert.That(clone.Id, Is.Not.EqualTo(model.Id));
        }
Пример #30
0
        private void AssertPropertyNotSetValue <TModel>(ModelProperties <TModel> modelProperties, TModel model, string property, string value) where TModel : new()
        {
            bool result = modelProperties.TrySetValueFromString(model, property, value);

            Assert.That(result, Is.False, "Unexpected Result for {0}", property);
        }