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));
        }
        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));
        }
        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);
        }
        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 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);
        }
示例#6
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 <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);
        }