예제 #1
0
        public void ToString_WithDateParameter_ReplacesParameterWithItsValue()
        {
            // arrange
            var sut  = new SqlClause();
            var date = new DateTime(2000, 1, 2, 3, 4, 5);

            sut.Add("@p1 @p2 @p3",
                    new SqlParameter {
                ParameterName = "@p1", SqlDbType = SqlDbType.DateTime, Value = date
            },
                    new SqlParameter {
                ParameterName = "@p2", SqlDbType = SqlDbType.Date, Value = (DateTime?)date
            },
                    new SqlParameter {
                ParameterName = "@p3", SqlDbType = SqlDbType.Time, Value = (DateTime?)date
            });


            // act
            var result = sut.ToString();


            // arrange
            result.Should().Be("'2000-01-02 03:04:05' " +
                               "'2000-01-02' " +
                               "'03:04:05'");
        }
예제 #2
0
        public void ToString_WithObjectParameter_ReplacesParameterWithItsToStringRepresentation()
        {
            // arrange
            var sut = new SqlClause();

            sut.Add("@p", new SqlParameter("@p", new { x = 1 }));


            // act
            var result = sut.ToString();


            // arrange
            result.Should().Be("'{ x = 1 }'");
        }
예제 #3
0
        public void ToString_WithPrefix_WithSuffix_WithSeparator_TwoExpressions_ReturnsCorrectSql()
        {
            // arrange
            var sut = new SqlClause();

            sut.Prefix = "prefix ";
            sut.ExpressionsSeparator = " and ";
            sut.Suffix = " suffix";
            sut.Add("a");
            sut.Add("b");


            // act
            var result = sut.ToString();


            // arrange
            result.Should().Be("prefix a and b suffix");
        }
예제 #4
0
        public void ToString_WithParameter_ReplacesParameterWithItsValue(object value, Type type, string expected)
        {
            // arrange
            if (value != null)
            {
                value = Convert.ChangeType(value, type);
            }

            var sut = new SqlClause();

            sut.Add("@p", new SqlParameter("@p", value));


            // act
            var result = sut.ToString();


            // arrange
            result.Should().Be(expected);
        }