public void DbParametersFromComplexObject()
        {
            const string expectedNameInName       = "p_NameIN_IN";
            const string expectedToDbUuidName     = "p_ToDbUuid";
            const string expectedNameINValue      = "ComplexObject";
            const string expectedAliasedFieldName = "p_ALittleTest";
            const int    expectedToDbUuidValue    = 5;

            ComplexObject obj = new ComplexObject
            {
                NameIN   = expectedNameINValue,
                ToDbUuid = expectedToDbUuidValue,
                FromDbId = 66,
                Aliased  = true
            };

            DbAutoFillHelper.FillDbParametersFromObject(command, obj);

            Assert.AreEqual(expectedNameInName, command.Parameters[expectedNameInName].ParameterName);
            Assert.AreEqual(expectedNameINValue, command.Parameters[expectedNameInName].Value);
            Assert.AreEqual(expectedToDbUuidName, command.Parameters[expectedToDbUuidName].ParameterName);
            Assert.AreEqual(expectedToDbUuidValue, command.Parameters[expectedToDbUuidName].Value);
            Assert.AreEqual(expectedAliasedFieldName, command.Parameters[expectedAliasedFieldName].ParameterName);
            Assert.ThrowsException <IndexOutOfRangeException>(() => { string n = command.Parameters["FromDbId"].ParameterName; });
            Assert.ThrowsException <IndexOutOfRangeException>(() => { string n = command.Parameters["Unsettable"].ParameterName; });
        }
        public void DbParametersFromBasicObject()
        {
            const int    expectedInt            = 11;
            const string expectedString         = "HollyMolly";
            const string expectedIntName        = "IntField";
            const string expectedStringProperty = "StringProperty";

            BasicObject obj = new BasicObject
            {
                IntField       = expectedInt,
                StringProperty = expectedString
            };

            DbAutoFillHelper.FillDbParametersFromObject(command, obj);

            Assert.AreEqual(obj.IntField, command.Parameters[expectedIntName].Value);
            Assert.AreEqual(obj.StringProperty, command.Parameters[expectedStringProperty].Value);
        }
        private void AddParametersWithValueToCommand(IDbCommand command, params object[] parameters)
        {
            if (parameters == null || parameters.Length == 0)
            {
                return;
            }

            foreach (object parameter in parameters)
            {
                if (parameter != null && false == (parameter is DBNull))
                {
                    IDbAnonymousValue anonymousParam = parameter as IDbAnonymousValue;

                    if (anonymousParam != null)
                    {
                        DbAutoFillHelper.AddParameterWithValue(command, anonymousParam.Alias, anonymousParam.GetValue(), null);
                    }
                    else
                    {
                        DbAutoFillHelper.FillDbParametersFromObject(command, parameter);
                    }
                }
            }
        }