Exemple #1
0
        /// <summary>
        /// Copies reader fields into record fields finding matches by name and store flag.
        /// Reader must be in a "readable" state - "reader.Read()" should be executed by the caller
        /// <code>
        ///   if (reader.Read()) reader.CopyFieldsToRecordFields(record);
        /// </code>
        /// </summary>
        public static void CopyFieldsToRecordFields(this DbDataReader reader, RecordModel.Record record)
        {
            for (int i = 0; i < reader.FieldCount; i++)
            {
                var val = reader.GetValue(i);

                var fld = record.FindFieldByName(reader.GetName(i));

                if (fld == null)
                {
                    continue;
                }

                if (fld.StoreFlag == DataAccess.StoreFlag.LoadAndStore || fld.StoreFlag == DataAccess.StoreFlag.OnlyLoad)
                {
                    if (val == DBNull.Value)
                    {
                        fld.ValueAsObject = null; //same as field.Clear();
                    }
                    else
                    {
                        fld.ValueAsObject = val;
                    }
                }
            }
        }
Exemple #2
0
        public void ValidationExceptionOnPost()
        {
            var rec = R.Make <PersonRecord>();

            rec.Create();
            rec.fldRegistered.Value = true;
            rec.Post();//rest of required fields are blank
        }
Exemple #3
0
        private PersonRecord makeValidPerson()
        {
            var rec = R.Make <PersonRecord>();

            rec.Create();
            rec.fldName.Value       = "John Frank Bookman";
            rec.fldScore.Value      = 10;
            rec.fldSex.Value        = "M";
            rec.fldSalary.Value     = 75000M;
            rec.fldRegistered.Value = true;
            rec.fldDOB.Value        = DateTime.Parse("June 18, 1955");
            rec.fldMovieNames.Value.Add("Titanic");

            return(rec);
        }
Exemple #4
0
        public void DefaultValues()
        {
            var rec = R.Make <PersonRecord>();

            //this is black magic, never cast fields in normal use cases
            var fldName = (StringField)rec.fldName;

            fldName.DefaultValue    = "Hello!";
            fldName.HasDefaultValue = true;

            var fldRegistered = (BoolField)rec.fldRegistered;

            fldRegistered.DefaultValue    = false;
            fldRegistered.HasDefaultValue = true;

            rec.Create();//this should default field values

            Assert.AreEqual("Hello!", ~fldName);
            Assert.IsTrue(rec.fldName.HasValue);

            Assert.IsFalse(~fldRegistered);
            Assert.IsTrue(rec.fldName.HasValue);
        }
Exemple #5
0
        public void ListOfTFieldImmutability()
        {
            var rec = R.Make <PersonRecord>();

            rec.fldMovieNames.Value.Add("cant go");
        }
Exemple #6
0
        public void StateExceptionOnMutation()
        {
            var rec = R.Make <PersonRecord>();

            rec.fldName.Value = "aaa"; //cant write to non-init record
        }