public void DbResultToSampleObjectAllowMissing()
        {
            const string mandatoryField         = "Mandatory";
            const int    expectedMandatoryValue = 890;

            {
                DataTable dt = DatasetGenerator.CreateNewBasicDataTable(
                    new string[] { mandatoryField },
                    new Type[] { typeof(int) });

                using (IDataReader dr = DatasetGenerator.CreateBasicDataReader(dt, expectedMandatoryValue))
                {
                    dr.Read();

                    SampleObject obj = new SampleObject();

                    DbAutoFillHelper.FillObjectFromDataReader(dr, obj);

                    Assert.AreEqual(expectedMandatoryValue, obj.Mandatory);
                }
            }

            {
                DataTable dt = DatasetGenerator.CreateNewBasicDataTable(new string[] { }, new Type[] { });

                using (IDataReader dr = DatasetGenerator.CreateBasicDataReader(dt, new object[] { }))
                {
                    dr.Read();
                    SampleObject obj = new SampleObject();

                    Assert.ThrowsException <MissingFieldException>(() => { DbAutoFillHelper.FillObjectFromDataReader(dr, obj); });
                }
            }
        }
Exemple #2
0
        public void GetDbAnonymousValue_Test()
        {
            DbAnonymousValue <int> value = new DbAnonymousValue <int>();

            DbAutoFillHelper.FillObjectFromDataReader(value, _dataReader);

            Assert.AreEqual(value.GetValue(), ANONYMOUS_SET_VALUE);
        }
        public void FillObjectFromDataReader_GoodValues_Test()
        {
            _dvco = new DefaultValuesClassObject();

            DbAutoFillHelper.FillObjectFromDataReader(_dvco, _dataReader);

            Assert.AreEqual(_dvco.Parameter1, DATAREADER_PARAMETER_1_VALUE);
            Assert.AreEqual(_dvco.Parameter2, DATAREADER_PARAMETER_2_VALUE);
            Assert.AreEqual(_dvco.FromDBParameter, DATAREADER_FROMDBPARAMETER_VALUE);
            Assert.AreNotEqual(_dvco.NoneParameter, DATAREADER_NONEPARAMETER_VALUE);
            Assert.AreNotEqual(_dvco.ToDBParameter, DATAREADER_ToDBPARAMETER_VALUE);
        }
 private void ReadResultsToDbResponse <TObjects>(IDbCommand command, DbResponse <TObjects> response)
     where TObjects : new()
 {
     using (IDataReader reader = command.ExecuteReader())
     {
         while (reader.Read())
         {
             TObjects obj = new TObjects();
             DbAutoFillHelper.FillObjectFromDataReader(reader, obj);
             response.ResultSet.Add(obj);
         }
     }
 }
        public void Advanced_GetParametersFromDataReader_GoodValues_Test()
        {
            AdvancedAutoFillClass aafc   = new AdvancedAutoFillClass();
            IDataReader           reader = CreateAdvancedDataReader();

            reader.Read();
            DbAutoFillHelper.FillObjectFromDataReader(aafc, reader);

            Assert.AreEqual(aafc.AliasedParameter, ADVANCED_DATAREADER_ALIASED_VALUE);
            Assert.AreEqual(aafc.DbTypeParameter, ADVANCED_DATAREADER_DBTYPE_VALUE);
            Assert.AreEqual(aafc.DbTypeParameterDefault, ADVANCED_DATAREADER_DBTYPEDEFAULT_VALUE);
            Assert.AreEqual(aafc.ParameterPrefixOverride, ADVANCED_DATAREADER_PREFIX_VALUE);
        }
Exemple #6
0
        public void FillObjectFromDataReader_StructuredGood_Test()
        {
            DbAutoFillHelper.FillObjectFromDataReader(_dvco, _dataReader);

            Assert.IsTrue(_dvco.MyStructuredField.Records.Count > 0);
            MyGenericObject mgo = _dvco.FindGenericObjectFromId(int.Parse(OBJECT_FILL_ELEMENT1_ID));

            Assert.IsNotNull(mgo);

            Assert.AreEqual(mgo.name, OBJECT_FILL_ELEMENT1_NAME);

            mgo = _dvco.FindGenericObjectFromId(int.Parse(OBJECT_FILL_ELEMENT2_ID));
            Assert.IsNotNull(mgo);

            Assert.AreEqual(mgo.name, OBJECT_FILL_ELEMENT2_NAME);
        }
        public void DbResultsToBasicObject()
        {
            const string expectedStringValue = "String";
            const int    expectedIntValue    = 76;
            const string stringPropName      = "StringProperty";
            const string intPropName         = "IntField";

            DataTable dt = DatasetGenerator.CreateNewBasicDataTable(
                new string[] { stringPropName, intPropName },
                new Type[] { typeof(string), typeof(int) });

            using (IDataReader dr = DatasetGenerator.CreateBasicDataReader(dt, expectedStringValue, expectedIntValue))
            {
                dr.Read();

                BasicObject obj = new BasicObject();
                DbAutoFillHelper.FillObjectFromDataReader(dr, obj);

                Assert.AreEqual(obj.StringProperty, expectedStringValue);
                Assert.AreEqual(obj.IntField, expectedIntValue);
            }
        }
        public void DbResultToComplexObject()
        {
            const string nameINField               = "NameIN";
            const string toDbUuidField             = "ToDbUuid";
            const string fromDbIdField             = "FromDbId";
            const string expectedAliasedColumnName = "ALittleTest";

            const string expectedNameINValue       = "ComplexObject";
            const int    unexpectedToDbUuidValue   = 23;
            const int    expectedFromDbUuid        = 3;
            const int    expectedToDbUuidValue     = -19;
            const bool   expectedAliaseColumnValue = true;

            DataTable dt = DatasetGenerator.CreateNewBasicDataTable(
                new string[] { nameINField, toDbUuidField, fromDbIdField, expectedAliasedColumnName },
                new Type[] { typeof(string), typeof(int), typeof(int), typeof(string) });

            using (IDataReader dr = DatasetGenerator.CreateBasicDataReader(dt,
                                                                           expectedNameINValue,
                                                                           unexpectedToDbUuidValue,
                                                                           expectedFromDbUuid,
                                                                           expectedAliaseColumnValue))
            {
                dr.Read();

                ComplexObject obj = new ComplexObject();
                obj.ToDbUuid = expectedToDbUuidValue;

                DbAutoFillHelper.FillObjectFromDataReader(dr, obj);

                Assert.AreEqual(expectedNameINValue, obj.NameIN);
                Assert.AreNotEqual(unexpectedToDbUuidValue, obj.ToDbUuid);
                Assert.AreEqual(expectedToDbUuidValue, obj.ToDbUuid);
                Assert.AreEqual(expectedFromDbUuid, obj.FromDbId);
                Assert.AreEqual(expectedAliaseColumnValue, obj.Aliased);
            }
        }