Ejemplo n.º 1
0
        public void Ctor_WithTextWriterAndWriterSettings_UsesSpecifiedSettings()
        {
            var           settings = new SqlWriterSettings();
            TestSqlWriter writer   = new TestSqlWriter(new StringWriter(new StringBuilder()), settings);

            Assert.Same(settings, writer.SettingsTest);
        }
Ejemplo n.º 2
0
        public void Ctor_WithDialect_ReturnsDialect()
        {
            var builder = new StringBuilder();
            var writer  = new TestSqlWriter(builder, SqlDialect.Default);

            Assert.NotNull(writer.DialectTest);
            Assert.Same(SqlDialect.Default, writer.DialectTest);
        }
Ejemplo n.º 3
0
        public void EnsureNotDisposed_WhenNotDisposed_DoesNotThrow()
        {
            var builder = new StringBuilder();

            using (var writer = new TestSqlWriter(builder))
            {
                writer.EnsureNotDisposedTest();
            }
        }
Ejemplo n.º 4
0
        public void WriteDataType_WritesDataType(SqlDataType dataType, string expected)
        {
            var builder = new StringBuilder();

            using (var writer = new TestSqlWriter(builder))
            {
                writer.WriteDataType(dataType);
            }
            Assert.Equal(expected, builder.ToString());
        }
Ejemplo n.º 5
0
        public void WriteKeyword_WritesKeyword()
        {
            var builder = new StringBuilder();

            using (var writer = new TestSqlWriter(builder))
            {
                writer.WriteKeyword(SqlKeywords.Select);
            }
            Assert.Equal("SELECT", builder.ToString());
        }
Ejemplo n.º 6
0
        public void WriteValue_WithString_WritesString()
        {
            var builder = new StringBuilder();

            using (var writer = new TestSqlWriter(builder))
            {
                writer.WriteValue("The rain in spain falls mainly on the plain.");
            }
            Assert.Equal("'The rain in spain falls mainly on the plain.'", builder.ToString());
        }
Ejemplo n.º 7
0
        public void WriteValue_WithFloatingPoint_WritesFloatingPoint()
        {
            var builder = new StringBuilder();

            using (var writer = new TestSqlWriter(builder))
            {
                writer.WriteValue(Math.PI);
            }
            Assert.Equal(Math.PI.ToString(CultureInfo.InvariantCulture), builder.ToString());
        }
Ejemplo n.º 8
0
        public void WriteValue_WithInteger_WritesInteger()
        {
            var builder = new StringBuilder();

            using (var writer = new TestSqlWriter(builder))
            {
                writer.WriteValue(long.MaxValue);
            }
            Assert.Equal(long.MaxValue.ToString(CultureInfo.InvariantCulture), builder.ToString());
        }
Ejemplo n.º 9
0
        public void WriteValue_WithNullValue_WritesNull()
        {
            var builder = new StringBuilder();

            using (var writer = new TestSqlWriter(builder))
            {
                writer.WriteValue(null);
            }
            Assert.Equal("NULL", builder.ToString());
        }
Ejemplo n.º 10
0
        public void EnsureNotDisposed_WhenDisposed_ThrowsObjectDisposed()
        {
            var           builder = new StringBuilder();
            TestSqlWriter writer;

            using (writer = new TestSqlWriter(builder))
            {
            }

            Assert.Throws <ObjectDisposedException>(() => writer.EnsureNotDisposedTest());
        }
Ejemplo n.º 11
0
        public void WriteValue_WithOther_WritesDouble()
        {
            var value   = new { id = 5 };
            var builder = new StringBuilder();

            using (var writer = new TestSqlWriter(builder))
            {
                writer.WriteValue(value);
            }
            Assert.Equal($"'{Convert.ToString(value, CultureInfo.InvariantCulture)}'", builder.ToString());
        }
Ejemplo n.º 12
0
        public void WriteParameter_WithParameterName_WritesParameter()
        {
            string expected;
            var    builder = new StringBuilder();

            using (var writer = new TestSqlWriter(builder))
            {
                writer.WriteParameter("Id");
                expected = writer.DialectTest.FormatParameterName("Id");
            }

            Assert.Equal(expected, builder.ToString());
        }
Ejemplo n.º 13
0
        public void WriteParameter_WithNullOrWhiteSpaceParameterName_ThrowsArgumentNull(string parameterName)
        {
            var ex = Assert.Throws <ArgumentNullException>(() =>
            {
                var builder = new StringBuilder();
                using (var writer = new TestSqlWriter(builder))
                {
                    writer.WriteParameter(parameterName);
                }
            });

            Assert.Equal(nameof(parameterName), ex.ParamName);
        }
Ejemplo n.º 14
0
        public void WriteLimit_WithNullOffset_WritesLimitWithCountOnly()
        {
            var expected = "LIMIT 10";
            var dialect  = new MySqlDialect();
            var builder  = new StringBuilder();

            using (TestSqlWriter writer = new TestSqlWriter(builder, dialect))
            {
                dialect.WriteLimit(writer, null, 10);
            }

            var actual = builder.ToString();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 15
0
        public void WriteKeyword_WithWriteKeywordsInLowerCase_WritesKeywordsInLowerCase()
        {
            var builder  = new StringBuilder();
            var settings = new SqlWriterSettings
            {
                WriteKeywordsInLowerCase = true
            };

            using (var writer = new TestSqlWriter(builder, settings))
            {
                writer.WriteKeyword(SqlKeywords.Select);
            }

            Assert.Equal("select", builder.ToString());
        }
Ejemplo n.º 16
0
        public void WriteDataType_WithWriteDataTypeInLowerCase_WritesDataTypesInLowerCase(SqlDataType dataType, string expected)
        {
            var builder  = new StringBuilder();
            var settings = new SqlWriterSettings
            {
                WriteDataTypesInLowerCase = true
            };

            using (var writer = new TestSqlWriter(builder, settings))
            {
                writer.WriteDataType(dataType);
            }

            Assert.Equal(expected, builder.ToString());
        }
Ejemplo n.º 17
0
        public void WriteLimit_WithNullOffset_WritesZeroOffset()
        {
            var expected = "OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY";
            var dialect  = new SqlServerDialect();
            var builder  = new StringBuilder();

            using (TestSqlWriter writer = new TestSqlWriter(builder, dialect))
            {
                dialect.WriteLimit(writer, null, 10);
            }

            var actual = builder.ToString();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 18
0
        public void WriteLimit_WithNullCount_WritesOffsetOnly()
        {
            var expected = "OFFSET 42 ROWS";
            var dialect  = new SqlServerDialect();
            var builder  = new StringBuilder();

            using (TestSqlWriter writer = new TestSqlWriter(builder, dialect))
            {
                dialect.WriteLimit(writer, 42, null);
            }

            var actual = builder.ToString();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 19
0
        public void WriteRaw_WritesRawText()
        {
            var builder = new StringBuilder();

            using (var writer = new TestSqlWriter(builder))
            {
                writer.WriteRawTest("WriteRaw");
                writer.WriteRawTest("() ");
                writer.WriteRawTest("does n");
                writer.WriteRawTest("ot wri");
                writer.WriteRawTest("te spaces between");
                writer.WriteRawTest(" calls.");
            }

            Assert.Equal("WriteRaw() does not write spaces between calls.", builder.ToString());
        }
Ejemplo n.º 20
0
        public void Write_WritesText()
        {
            var builder = new StringBuilder();

            using (var writer = new TestSqlWriter(builder))
            {
                writer.WriteTest("Write()");
                writer.WriteTest("does");
                writer.WriteTest("write");
                writer.WriteTest("spaces");
                writer.WriteTest("between");
                writer.WriteTest("calls.");
            }

            Assert.Equal("Write() does write spaces between calls.", builder.ToString());
        }