Ejemplo n.º 1
0
        public SqlGeneratorResult()
        {
            Parameters = new List<IDataParameter>();

            var quotedStrategy = new QuotedUnparameterizationStrategy();
            var nonQuotedStrategy = new NonQuotedUnparameterizationStrategy();
            var escapedStringStrategy = new EscapedStringUnparameterizationStrategy();

            _strategyRegistry = new Dictionary<DbType, ISqlUnparameterizationStrategy>
            {
                { DbType.AnsiString, escapedStringStrategy },
                { DbType.Byte, nonQuotedStrategy },
                { DbType.Boolean, nonQuotedStrategy },
                { DbType.Currency, nonQuotedStrategy },
                { DbType.Date, quotedStrategy },
                { DbType.DateTime, quotedStrategy },
                { DbType.Decimal, nonQuotedStrategy },
                { DbType.Double, nonQuotedStrategy },
                { DbType.Guid, quotedStrategy },
                { DbType.Int16, nonQuotedStrategy },
                { DbType.Int32, nonQuotedStrategy },
                { DbType.Int64, nonQuotedStrategy },
                { DbType.SByte, nonQuotedStrategy },
                { DbType.Single, nonQuotedStrategy },
                { DbType.String, escapedStringStrategy },
                { DbType.Time, quotedStrategy },
                { DbType.UInt16, nonQuotedStrategy },
                { DbType.UInt32, nonQuotedStrategy },
                { DbType.UInt64, nonQuotedStrategy },
                { DbType.VarNumeric, nonQuotedStrategy },
                { DbType.AnsiStringFixedLength, escapedStringStrategy },
                { DbType.StringFixedLength, escapedStringStrategy },
                { DbType.DateTime2, quotedStrategy }
            };
        }
        public void EscapedUnparameterizationStrategy_UnparameterizesCorrectly()
        {
            const string parameterValue = "g'day";
            var parameter = new SqlParameter("parameterName", parameterValue);
            var strategy = new EscapedStringUnparameterizationStrategy();

            Assert.That(strategy.Unparameterize(parameter), Is.EqualTo(String.Format("'{0}'", parameterValue.Replace("'", "''"))));
        }