Esempio n. 1
0
        public void ToString_ShouldReturnStringRepresentation()
        {
            var format  = "{0}:{1}{2}";
            var builder = new StringBuilder();

            builder.AppendLine(NamedFluentModel.MODEL_NAME);
            builder.AppendFormat(format, NamedFluentModel.BOOLEAN_PROPERTY_NAME, NamedFluentModel.BOOLEAN_VALUE, Environment.NewLine);
            builder.AppendFormat(format, NamedFluentModel.DATE_PROPERTY_NAME, NamedFluentModel.DATE_VALUE, Environment.NewLine);
            builder.AppendFormat(format, NamedFluentModel.DOUBLE_PROPERTY_NAME, NamedFluentModel.DOUBLE_VALUE, Environment.NewLine);
            builder.AppendFormat(format, NamedFluentModel.INTEGER_PROPERTY_NAME, NamedFluentModel.INTEGER_VALUE, Environment.NewLine);
            builder.AppendFormat(format, NamedFluentModel.OBJECT_PROPERTY_NAME, NamedFluentModel.OBJECT_VALUE, Environment.NewLine);

            var fluentObject = new FluentObject();

            fluentObject.Name = NamedFluentModel.MODEL_NAME;
            fluentObject.Add(NamedFluentModel.BOOLEAN_PROPERTY_NAME, NamedFluentModel.BOOLEAN_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.DATE_PROPERTY_NAME, NamedFluentModel.DATE_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.DOUBLE_PROPERTY_NAME, NamedFluentModel.DOUBLE_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.INTEGER_PROPERTY_NAME, NamedFluentModel.INTEGER_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.OBJECT_PROPERTY_NAME, NamedFluentModel.OBJECT_VALUE.ToString());

            var fluentObjectString   = fluentObject.ToString();
            var expectedObjectString = builder.ToString();

            Assert.AreEqual(fluentObjectString, expectedObjectString);
        }
        public void InitializeTest()
        {
            _queryExecutor        = new Mock <IQueryExecutor>();
            _queryProviderFactory = new QueryProviderFactory();
            _queryProvider        = new QueryProvider <NamedFluentModelBase>();
            _fluentQueriable      = new BasicFluentQueryable <NamedFluentModelBase>(_queryExecutor.Object, _queryProviderFactory);

            _fluentObject = new FluentObject(NamedFluentModelBase.MODEL_NAME);
            _fluentObject.Add(NamedFluentModelBase.BOOLEAN_PROPERTY_NAME, NamedFluentModelBase.BOOLEAN_VALUE.ToString());
            _fluentObject.Add(NamedFluentModelBase.DATE_PROPERTY_NAME, NamedFluentModelBase.DATE_VALUE.ToString());
        }
        public DataConnector()
        {
            var fluentObject = new FluentObject("e_contacts");

            fluentObject.Add("ID", "4457");
            fluentObject.Add("p_name", "Benjamin Colin");
            fluentObject.Add("p_birthDate", "1978-8-12");
            fluentObject.Add("p_weight", "78.4");
            fluentObject.Add("p_doNotTrack", "111555999");

            _objects = new[] { fluentObject };
        }
Esempio n. 4
0
        public void FluentObject_ConstructsWithNameParameter()
        {
            var fluentObject = new FluentObject(NamedFluentModel.MODEL_NAME);

            fluentObject.Add(NamedFluentModel.BOOLEAN_PROPERTY_NAME, NamedFluentModel.BOOLEAN_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.DATE_PROPERTY_NAME, NamedFluentModel.DATE_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.DOUBLE_PROPERTY_NAME, NamedFluentModel.DOUBLE_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.INTEGER_PROPERTY_NAME, NamedFluentModel.INTEGER_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.OBJECT_PROPERTY_NAME, NamedFluentModel.OBJECT_VALUE.ToString());

            Assertions(fluentObject);
        }
        public void ShouldMapFromFluentObject_WithAttributeNames()
        {
            var fluentObject = new FluentObject(NamedFluentModel.MODEL_NAME);

            fluentObject.Add(NamedFluentModel.BOOLEAN_PROPERTY_NAME, NamedFluentModel.BOOLEAN_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.DATE_PROPERTY_NAME, NamedFluentModel.DATE_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.DOUBLE_PROPERTY_NAME, NamedFluentModel.DOUBLE_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.INTEGER_PROPERTY_NAME, NamedFluentModel.INTEGER_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.OBJECT_PROPERTY_NAME, NamedFluentModel.OBJECT_VALUE.ToString());
            fluentObject.Add(NamedFluentModel.READONLY_PROPERTY_NAME, NamedFluentModel.READONLY_VALUE);
            fluentObject.Add(NamedFluentModel.CONDITIONED_PROPERTY_NAME, NamedFluentModel.CONDITIONED_VALUE);
            fluentObject.Add(NamedFluentModel.CONDITIONED_REVERSE_PROPERTY_NAME, NamedFluentModel.CONDITIONED_REVERSE_VALUE);

            var fluentModel = fluentObject.MapFromFluentObject <NamedFluentModel>();

            Assert.IsNotNull(fluentModel);

            Assert.AreEqual(fluentModel.BooleanProperty, NamedFluentModel.BOOLEAN_VALUE);
            Assert.AreEqual(fluentModel.DateProperty, NamedFluentModel.DATE_VALUE);
            Assert.AreEqual(fluentModel.DoubleProperty, NamedFluentModel.DOUBLE_VALUE);
            Assert.AreEqual(fluentModel.IntegerProperty, NamedFluentModel.INTEGER_VALUE);
            Assert.AreEqual(fluentModel.ObjectProperty, NamedFluentModel.OBJECT_VALUE);
            Assert.AreEqual(fluentModel.ReadonlyProperty, NamedFluentModel.READONLY_VALUE);
            Assert.AreEqual(fluentModel.ConditionedProperty, NamedFluentModel.CONDITIONED_VALUE);
            Assert.AreNotEqual(fluentModel.ConditionedReverseProperty, NamedFluentModel.CONDITIONED_REVERSE_VALUE);
        }
Esempio n. 6
0
        /// <summary>
        /// Sets the value of given property for given FluentObject.
        /// </summary>
        /// <param name="prop">Source property</param>
        /// <param name="source">Source object</param>
        /// <param name="target">Target FluentObject</param>
        public static void SetValue(this PropertyInfo prop, object source, ref FluentObject target)
        {
            if (prop == null)
            {
                throw new ArgumentNullException("prop");
            }

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var fluentPropertyAttribute = prop.GetCustomAttributes(typeof(FluentPropertyAttribute), false).SingleOrDefault() as FluentPropertyAttribute;

            if (fluentPropertyAttribute == null)
            {
                throw new ArgumentException("Property is not FluentProperty", "prop");
            }

            object[] converterParameters;
            var      converter = prop.GetConverter(out converterParameters);

            var key         = fluentPropertyAttribute.Name ?? prop.Name;
            var value       = prop.GetValue(source);
            var valueString = converter != null?converter.ConvertBack(value, converterParameters) : value.ToString();

            target.Add(key, valueString);
        }
Esempio n. 7
0
        public void ShouldMapEnumValueFromFluentObject()
        {
            var fluentObject = new FluentObject(ConvertableModel.MODEL_NAME);

            fluentObject.Add(ConvertableModel.CONVERTABLE_PROPERTY_NAME, ConvertableModel.CONVERTABLE_STRING_VALUE);

            var model = fluentObject.MapFromFluentObject <ConvertableModel>();

            Assert.IsNotNull(model);
            Assert.AreEqual(model.ConvertableProperty, ConvertableModel.CONVERTABLE_ENUM_VALUE);
        }
        public void ShouldMapFromFluentObjectToNestedModel()
        {
            var fluentObject = new FluentObject(NestedModelFields.MODEL_NAME);

            fluentObject.Add(NestedModelFields.FIELD_NAME, NestedModelFields.FIELD_VALUE.ToString());
            fluentObject.Add(NestedModelFields.CONDITIONAL_FIELD_NAME, NestedModelFields.CONDITIONAL_FIELD_VALUE.ToString());
            fluentObject.Add(NestedModelFields.CONDITIONAL_REVERSED_FIELD_NAME, NestedModelFields.CONDITIONAL_REVERSED_FIELD_VALUE.ToString());
            fluentObject.Add(NestedModelFields.READONLY_FIELD_NAME, NestedModelFields.READONLY_FIELD_VALUE.ToString());
            fluentObject.Add(NestedModelFields.DEPENDENT_FIELD_NAME, NestedModelFields.DEPENDENT_FIELD_VALUE.ToString());
            fluentObject.Add(NestedModelFields.DEPENDENT_REVERSED_FIELD_NAME, NestedModelFields.DEPENDENT_REVERSED_FIELD_VALUE.ToString());

            var nestedModel = fluentObject.MapFromFluentObject <NestedModel>();

            Assert.IsNotNull(nestedModel);
            Assert.AreEqual(nestedModel.StringProperty, NestedModelFields.FIELD_VALUE);
            Assert.AreEqual(nestedModel.ConditionalProperty, NestedModelFields.CONDITIONAL_FIELD_VALUE);
            Assert.AreEqual(nestedModel.ConditionalReversedProperty, 0);
            Assert.AreEqual(nestedModel.ReadonlyProperty, NestedModelFields.READONLY_FIELD_VALUE);
            Assert.AreEqual(nestedModel.DependentProperty, NestedModelFields.DEPENDENT_FIELD_VALUE);
            Assert.AreEqual(nestedModel.DependentReversedProperty, NestedModelFields.DEPENDENT_REVERSED_FIELD_VALUE);
        }