Exemple #1
0
        public void Cast_WithValueAndDataType_ReturnsCast()
        {
            var cast = SqlExpression.Cast(5, SqlDataType.BigInt());

            Assert.Equal(5, cast.Value);
            Assert.Equal(SqlDataType.BigInt(), cast.DataType);
        }
        public void Cast()
        {
            var cast = SqlExpression.Cast(SqlExpression.Constant(45), PrimitiveTypes.String());

            SerializeAndAssert(cast, (serialized, deserialized) => {
                Assert.AreEqual(SqlExpressionType.Cast, deserialized.ExpressionType);
                Assert.IsInstanceOf <SqlConstantExpression>(deserialized.Value);
                Assert.IsInstanceOf <StringType>(deserialized.SqlType);
            });
        }
        public void ToSql_WithSqlCast_ReturnsSql()
        {
            const string expected = "SELECT [Id], [Name], CAST([Age] AS FLOAT(10)) FROM [User] WHERE [Id] = 5";
            var          actual   = Sql
                                    .Select((SqlColumn)"Id", (SqlColumn)"Name", SqlExpression.Cast((SqlColumn)"Age", SqlDataType.Float(10)))
                                    .From("User")
                                    .Where(SqlExpression.Equal("Id", 5))
                                    .Go()
                                    .ToSql();

            Assert.Equal(expected, actual);
        }
Exemple #4
0
        public void Accept_WithCast_VisitsEverything()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var mock    = fixture.Freeze <Mock <SqlVisitor> >();

            var query = Sql
                        .Select(SqlExpression.Cast((SqlColumn)"Age", SqlDataType.BigInt()))
                        .From("User")
                        .Go();

            query.Accept(mock.Object);

            mock.Verify(_ => _.Visit(It.IsAny <SqlCast>()), Times.Once);
        }
Exemple #5
0
        public void Cast_WithNullDataType_ThrowsArgumentNull()
        {
            var ex = Assert.Throws <ArgumentNullException>(() => SqlExpression.Cast(null, null));

            Assert.Equal("dataType", ex.ParamName);
        }
Exemple #6
0
        public void Cast_WithNullValue_ConvertsToNullConstant()
        {
            var cast = SqlExpression.Cast(null, SqlDataType.BigInt());

            Assert.Same(SqlConstant.Null, cast.Value);
        }