示例#1
0
        public void WriteFragment_SubQuery()
        {
            IQuery query  = sql.Query.From("person");
            string result = ToStringBuilder.Build(b => b.WriteFragment(query));

            Assert.Equal("(FROM person)", result);
        }
示例#2
0
        public void WriteFragment_Parentheses()
        {
            IFrom  from   = sql.From("person");
            string result = ToStringBuilder.Build(b => b.WriteFragment(from, true));

            Assert.Equal("(FROM person)", result);
        }
示例#3
0
        public void WriteValue_Fragment()
        {
            IFrom  from   = sql.From("person");
            string result = ToStringBuilder.Build(b => b.WriteValue(from));

            Assert.Equal("FROM person", result);
        }
示例#4
0
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>A string that represents the current object.</returns>
 public override string ToString()
 {
     return(ToStringBuilder.Build(b => b.Write("OVER(")
                                  .IfNotNull(PartitionByValue, x => b.Write("PARTITION BY ").WriteFragment(x))
                                  .IfNotNull(OrderByValue, x => b.Write(" ").WriteFragment(x))
                                  .IfNotNull(RangeValue, x => b.Write(" ").WriteFragment(x)).Write(")")));
 }
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>A string that represents the current object.</returns>
 public override string ToString()
 {
     return(ToStringBuilder.Build(b => b
                                  .IfNotNull(OffsetValue, x => b.Write("OFFSET ").WriteValue(x).Write(" "))
                                  .IfNotNull(FetchValue, x => b.Write("FETCH ").WriteValue(x)).Write(" ")
                                  .RemoveLast(1)));
 }
示例#6
0
        public void Join()
        {
            string[] values = new string[] { "a", "b", "c" };
            string   result = ToStringBuilder.Build(b => b
                                                    .Join(", ", values, (x) => b.Write(x)));

            Assert.Equal("a, b, c", result);
        }
示例#7
0
        public void ForEach_Delegate_With_Index()
        {
            string[] values = new string[] { "a", "b", "c" };
            string   result = ToStringBuilder.Build(b => b
                                                    .ForEach(values, (x, i) => b.Write(x).Write(i.ToString())));

            Assert.Equal("a0b1c2", result);
        }
示例#8
0
        public void ForEach()
        {
            string[] values = new string[] { "a", "b", "c" };
            string   result = ToStringBuilder.Build(b => b
                                                    .ForEach(values, (x) => b.Write(x)));

            Assert.Equal("abc", result);
        }
示例#9
0
        public void IfNot_False()
        {
            IFrom  from   = null;
            string result = ToStringBuilder.Build(b => b
                                                  .IfNot(from == null, () => b.WriteFragment(from)));

            Assert.Equal("", result);
        }
示例#10
0
        public void IfNot_True()
        {
            IFrom  from   = sql.From("person");
            string result = ToStringBuilder.Build(b => b
                                                  .IfNot(from == null, () => b.WriteFragment(from)));

            Assert.Equal("FROM person", result);
        }
示例#11
0
        public void IfNotNull_Delegate_Without_Value_Null_Value()
        {
            IFrom  from   = null;
            string result = ToStringBuilder.Build(b => b
                                                  .IfNotNull(from, () => b.WriteFragment(from)));

            Assert.Equal("", result);
        }
示例#12
0
        public void IfNotNull_Delegate_Without_Value()
        {
            IFrom  from   = sql.From("person");
            string result = ToStringBuilder.Build(b => b
                                                  .IfNotNull(from, () => b.WriteFragment(from)));

            Assert.Equal("FROM person", result);
        }
示例#13
0
        public void IfNotNull_Null_Value()
        {
            IFrom  from   = null;
            string result = ToStringBuilder.Build(b => b
                                                  .IfNotNull(from, (x) => b.WriteFragment(x)));

            Assert.Equal("", result);
        }
示例#14
0
        public void IfNotNull()
        {
            IFrom  from   = sql.From("person");
            string result = ToStringBuilder.Build(b => b
                                                  .IfNotNull(from, (x) => b.WriteFragment(x)));

            Assert.Equal("FROM person", result);
        }
示例#15
0
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>A string that represents the current object.</returns>
 public override string ToString()
 {
     return(ToStringBuilder.Build(b => b.Write("CASE")
                                  .ForEach(Conditions, (x, i) => b
                                           .Write(" WHEN ").WriteFragment(Conditions[i])
                                           .Write(" THEN ").WriteValue(Values[i]))
                                  .IfNotNull(ElseValue, x => b.Write(" ELSE ").WriteValue(x))));
 }
示例#16
0
        public void Join_Delegate_With_Index()
        {
            string[] values = new string[] { "a", "b", "c" };
            string   result = ToStringBuilder.Build(b => b
                                                    .Join(", ", values, (x, i) => b.Write(x).Write(i.ToString())));

            Assert.Equal("a0, b1, c2", result);
        }
示例#17
0
        public void WriteParameter_Boolean()
        {
            string resultTrue  = ToStringBuilder.Build(b => b.WriteParameter(true));
            string resultFalse = ToStringBuilder.Build(b => b.WriteParameter(false));

            Assert.Equal("true", resultTrue);
            Assert.Equal("false", resultFalse);
        }
示例#18
0
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>A string that represents the current object.</returns>
 public override string ToString()
 {
     return(ToStringBuilder.Build(b => b
                                  .IfNotNull(BeforeValue, x => b.WriteFragment(x).Write(" "))
                                  .Write(base.ToString())
                                  .IfNotNull(OffsetValue, x => b.Write(" ").WriteFragment(x))
                                  .IfNotNull(AfterValue, x => b.Write(" ").WriteFragment(x))));
 }
示例#19
0
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>A string that represents the current object.</returns>
 public override string ToString()
 {
     return(ToStringBuilder.Build(b => b.Write("UPDATE").IfNotNull(TopValue, x => b.Write(" ").WriteFragment(x))));
 }
示例#20
0
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>A string that represents the current object.</returns>
 public override string ToString()
 {
     return(ToStringBuilder.Build(b => b.WriteFragment(Left, false).Write(" " + Op + " ")
                                  .WriteFragment(Right, false)));
 }
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>A string that represents the current object.</returns>
 public override string ToString()
 {
     return(ToStringBuilder.Build(b => b.WriteValue(Value).Write(" " + Op)));
 }
示例#22
0
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>A string that represents the current object.</returns>
 public override string ToString()
 {
     return(ToStringBuilder.Build(b => b.Write("INSERT INTO")
                                  .IfNotNull(IntoValue, x => b.Write(" ").WriteFragment(x))
                                  .If(Values.Count > 0, () => b.Write(" (").Write(base.ToString()).Write(")"))));
 }
示例#23
0
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>A string that represents the current object.</returns>
 public override string ToString()
 {
     return(ToStringBuilder.Build(b => b.IfNotNull(TableName, x => b.Write(x).Write(".")).Write(ColumnName)));
 }
示例#24
0
        public void WriteParameter_Enumerable()
        {
            string result = ToStringBuilder.Build(b => b.WriteParameter(new object[] { "value", true, false, 1, null }));

            Assert.Equal("[\"value\", true, false, 1, NULL]", result);
        }
示例#25
0
        public void WriteParameter_Null()
        {
            string result = ToStringBuilder.Build(b => b.WriteParameter(null));

            Assert.Equal("NULL", result);
        }
示例#26
0
        public void WriteParameter_Integer()
        {
            string result = ToStringBuilder.Build(b => b.WriteParameter(1));

            Assert.Equal("1", result);
        }
示例#27
0
        public void WriteParameter_String()
        {
            string result = ToStringBuilder.Build(b => b.WriteParameter("value"));

            Assert.Equal("\"value\"", result);
        }
示例#28
0
        public void Write()
        {
            string result = ToStringBuilder.Build(b => b.Write("SELECT"));

            Assert.Equal("SELECT", result);
        }
示例#29
0
        public void WriteParameter_Enumerable_Max_Length()
        {
            string result = ToStringBuilder.Build(b => b.WriteParameter(Enumerable.Range(1, 20)));

            Assert.Equal("[1, 2, 3, 4, 5, ...]", result);
        }
示例#30
0
        public void RemoveLast()
        {
            string result = ToStringBuilder.Build(b => b.Write("SELECT").RemoveLast(3));

            Assert.Equal("SEL", result);
        }