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