public void TestString()
        {
            Assert.AreEqual(SqQueryBuilder.SqlType.String().GetType(), this.Table.ColString.SqlType.GetType());
            Assert.AreEqual("[AT].[ColString]", this.Table.ColString.ToSql());
            Assert.IsFalse(this.Table.ColString.IsNullable);

            DerivedTable dt           = new DerivedTable();
            var          customColumn = this.Table.ColString.AddToDerivedTable(dt);

            Assert.AreEqual(this.Table.ColString.ColumnName, customColumn.ColumnName);
            Assert.IsTrue(dt.Columns.Contains(customColumn));

            var customColumn2 = this.Table.ColString.ToCustomColumn(this.NewSource);

            Assert.AreEqual(this.Table.ColString.ColumnName, customColumn2.ColumnName);

            var reader = new Mock <ISqDataRecordReader>();

            this.Table.ColString.Read(reader.Object);
            customColumn.Read(reader.Object);

            reader.Verify(r => r.GetString(It.Is <string>(name => name == customColumn.ColumnName.Name)), Times.Exactly(2));

            Assert.Throws <SqExpressException>(() => this.Table.ColString.ReadAsString(reader.Object));
            reader.Setup(r => r.GetNullableString(It.Is <string>(name => name == customColumn.ColumnName.Name))).Returns("AbC");
            Assert.AreEqual("AbC", this.Table.ColString.ReadAsString(reader.Object));

            Assert.AreEqual($"'{"AbC"}'", this.Table.ColString.FromString("AbC").ToSql());
            Assert.Throws <SqExpressException>(() => this.Table.ColString.FromString(null));
        }
        public void TestNullableBoolean()
        {
            Assert.AreEqual(SqQueryBuilder.SqlType.Boolean, this.Table.ColNullableBoolean.SqlType);
            Assert.AreEqual("[AT].[ColNullableBoolean]", this.Table.ColNullableBoolean.ToSql());
            Assert.IsTrue(this.Table.ColNullableBoolean.IsNullable);

            DerivedTable dt           = new DerivedTable();
            var          customColumn = this.Table.ColNullableBoolean.AddToDerivedTable(dt);

            Assert.AreEqual(this.Table.ColNullableBoolean.ColumnName, customColumn.ColumnName);
            Assert.IsTrue(dt.Columns.Contains(customColumn));

            var customColumn2 = this.Table.ColNullableBoolean.ToCustomColumn(this.NewSource);

            Assert.AreEqual(this.Table.ColNullableBoolean.ColumnName, customColumn2.ColumnName);

            var reader = new Mock <ISqDataRecordReader>();

            this.Table.ColNullableBoolean.Read(reader.Object);
            customColumn.Read(reader.Object);

            reader.Verify(r => r.GetNullableBoolean(It.Is <string>(name => name == customColumn.ColumnName.Name)), Times.Exactly(2));

            Assert.IsNull(this.Table.ColNullableBoolean.ReadAsString(reader.Object));
            reader.Setup(r => r.GetNullableBoolean(It.Is <string>(name => name == customColumn.ColumnName.Name))).Returns(true);
            Assert.AreEqual(true.ToString(), this.Table.ColNullableBoolean.ReadAsString(reader.Object));

            Assert.AreEqual("0", this.Table.ColNullableBoolean.FromString("False").ToSql());
            Assert.AreEqual("NULL", this.Table.ColNullableBoolean.FromString(null).ToSql());
        }
        public void TestNullableGuid()
        {
            Assert.AreEqual(SqQueryBuilder.SqlType.Guid, this.Table.ColNullableGuid.SqlType);
            Assert.AreEqual("[AT].[ColNullableGuid]", this.Table.ColNullableGuid.ToSql());
            Assert.IsTrue(this.Table.ColNullableGuid.IsNullable);

            DerivedTable dt           = new DerivedTable();
            var          customColumn = this.Table.ColNullableGuid.AddToDerivedTable(dt);

            Assert.AreEqual(this.Table.ColNullableGuid.ColumnName, customColumn.ColumnName);
            Assert.IsTrue(dt.Columns.Contains(customColumn));

            var customColumn2 = this.Table.ColNullableGuid.ToCustomColumn(this.NewSource);

            Assert.AreEqual(this.Table.ColNullableGuid.ColumnName, customColumn2.ColumnName);

            var reader = new Mock <ISqDataRecordReader>();

            this.Table.ColNullableGuid.Read(reader.Object);
            customColumn.Read(reader.Object);

            reader.Verify(r => r.GetNullableGuid(It.Is <string>(name => name == customColumn.ColumnName.Name)), Times.Exactly(2));

            var guid       = new Guid("3E0F7FA1-E7CA-4F6E-BF19-69C398565EA2");
            var guidString = guid.ToString("D");

            Assert.IsNull(this.Table.ColNullableGuid.ReadAsString(reader.Object));
            reader.Setup(r => r.GetNullableGuid(It.Is <string>(name => name == customColumn.ColumnName.Name))).Returns(guid);
            Assert.AreEqual(guidString, this.Table.ColNullableGuid.ReadAsString(reader.Object));

            Assert.AreEqual($"'{guidString}'", this.Table.ColNullableGuid.FromString(guidString).ToSql());
            Assert.AreEqual("NULL", this.Table.ColNullableGuid.FromString(null).ToSql());
        }
        public void TestNullableDateTime()
        {
            Assert.AreEqual(SqQueryBuilder.SqlType.DateTime().GetType(), this.Table.ColNullableDateTime.SqlType.GetType());
            Assert.AreEqual("[AT].[ColNullableDateTime]", this.Table.ColNullableDateTime.ToSql());
            Assert.IsTrue(this.Table.ColNullableDateTime.IsNullable);

            DerivedTable dt           = new DerivedTable();
            var          customColumn = this.Table.ColNullableDateTime.AddToDerivedTable(dt);

            Assert.AreEqual(this.Table.ColNullableDateTime.ColumnName, customColumn.ColumnName);
            Assert.IsTrue(dt.Columns.Contains(customColumn));

            var customColumn2 = this.Table.ColNullableDateTime.ToCustomColumn(this.NewSource);

            Assert.AreEqual(this.Table.ColNullableDateTime.ColumnName, customColumn2.ColumnName);

            var reader = new Mock <ISqDataRecordReader>();

            this.Table.ColNullableDateTime.Read(reader.Object);
            customColumn.Read(reader.Object);

            reader.Verify(r => r.GetNullableDateTime(It.Is <string>(name => name == customColumn.ColumnName.Name)), Times.Exactly(2));

            var date       = new DateTime(2021, 10, 21, 9, 25, 37);
            var dateString = date.ToString("yyyy-MM-ddTHH:mm:ss.fff");

            Assert.IsNull(this.Table.ColNullableDateTime.ReadAsString(reader.Object));
            reader.Setup(r => r.GetNullableDateTime(It.Is <string>(name => name == customColumn.ColumnName.Name))).Returns(date);
            Assert.AreEqual(dateString, this.Table.ColNullableDateTime.ReadAsString(reader.Object));

            Assert.AreEqual($"'{dateString}'", this.Table.ColNullableDateTime.FromString(dateString).ToSql());
            Assert.AreEqual("NULL", this.Table.ColNullableDateTime.FromString(null).ToSql());
        }
        public void TestNullableDouble()
        {
            Assert.AreEqual(SqQueryBuilder.SqlType.Double, this.Table.ColNullableDouble.SqlType);
            Assert.AreEqual("[AT].[ColNullableDouble]", this.Table.ColNullableDouble.ToSql());
            Assert.IsTrue(this.Table.ColNullableDouble.IsNullable);

            DerivedTable dt           = new DerivedTable();
            var          customColumn = this.Table.ColNullableDouble.AddToDerivedTable(dt);

            Assert.AreEqual(this.Table.ColNullableDouble.ColumnName, customColumn.ColumnName);
            Assert.IsTrue(dt.Columns.Contains(customColumn));

            var customColumn2 = this.Table.ColNullableDouble.ToCustomColumn(this.NewSource);

            Assert.AreEqual(this.Table.ColNullableDouble.ColumnName, customColumn2.ColumnName);

            var reader = new Mock <ISqDataRecordReader>();

            this.Table.ColNullableDouble.Read(reader.Object);
            customColumn.Read(reader.Object);

            reader.Verify(r => r.GetNullableDouble(It.Is <string>(name => name == customColumn.ColumnName.Name)), Times.Exactly(2));

            Assert.IsNull(this.Table.ColNullableDouble.ReadAsString(reader.Object));
            reader.Setup(r => r.GetNullableDouble(It.Is <string>(name => name == customColumn.ColumnName.Name))).Returns(-12.34567);
            Assert.AreEqual((-12.34567).ToString("F", CultureInfo.InvariantCulture), this.Table.ColNullableDouble.ReadAsString(reader.Object));

            Assert.AreEqual(12.34567.ToString("F", CultureInfo.InvariantCulture), this.Table.ColNullableDouble.FromString(12.34567.ToString("F", CultureInfo.InvariantCulture)).ToSql());
            Assert.AreEqual("NULL", this.Table.ColNullableDouble.FromString(null).ToSql());
        }
        public void TestDecimal()
        {
            Assert.AreEqual(SqQueryBuilder.SqlType.Decimal().GetType(), this.Table.ColDecimal.SqlType.GetType());
            Assert.AreEqual("[AT].[ColDecimal]", this.Table.ColDecimal.ToSql());
            Assert.IsFalse(this.Table.ColDecimal.IsNullable);

            DerivedTable dt           = new DerivedTable();
            var          customColumn = this.Table.ColDecimal.AddToDerivedTable(dt);

            Assert.AreEqual(this.Table.ColDecimal.ColumnName, customColumn.ColumnName);
            Assert.IsTrue(dt.Columns.Contains(customColumn));

            var customColumn2 = this.Table.ColDecimal.ToCustomColumn(this.NewSource);

            Assert.AreEqual(this.Table.ColDecimal.ColumnName, customColumn2.ColumnName);

            var reader = new Mock <ISqDataRecordReader>();

            this.Table.ColDecimal.Read(reader.Object);
            customColumn.Read(reader.Object);

            reader.Verify(r => r.GetDecimal(It.Is <string>(name => name == customColumn.ColumnName.Name)), Times.Exactly(2));

            Assert.Throws <SqExpressException>(() => this.Table.ColDecimal.ReadAsString(reader.Object));
            reader.Setup(r => r.GetNullableDecimal(It.Is <string>(name => name == customColumn.ColumnName.Name))).Returns(-12.34567m);
            Assert.AreEqual((-12.34567m).ToString("F", CultureInfo.InvariantCulture), this.Table.ColDecimal.ReadAsString(reader.Object));

            Assert.AreEqual(12.34567m.ToString("F", CultureInfo.InvariantCulture), this.Table.ColDecimal.FromString(12.34567m.ToString("F", CultureInfo.InvariantCulture)).ToSql());
            Assert.Throws <SqExpressException>(() => this.Table.ColDecimal.FromString(null));
        }
        public void TestDateTime()
        {
            Assert.AreEqual(SqQueryBuilder.SqlType.DateTime().GetType(), this.Table.ColDateTime.SqlType.GetType());
            Assert.AreEqual("[AT].[ColDateTime]", this.Table.ColDateTime.ToSql());
            Assert.IsFalse(this.Table.ColDateTime.IsNullable);

            DerivedTable dt           = new DerivedTable();
            var          customColumn = this.Table.ColDateTime.AddToDerivedTable(dt);

            Assert.AreEqual(this.Table.ColDateTime.ColumnName, customColumn.ColumnName);
            Assert.IsTrue(dt.Columns.Contains(customColumn));

            var customColumn2 = this.Table.ColDateTime.ToCustomColumn(this.NewSource);

            Assert.AreEqual(this.Table.ColDateTime.ColumnName, customColumn2.ColumnName);

            var reader = new Mock <ISqDataRecordReader>();

            this.Table.ColDateTime.Read(reader.Object);
            customColumn.Read(reader.Object);

            reader.Verify(r => r.GetDateTime(It.Is <string>(name => name == customColumn.ColumnName.Name)), Times.Exactly(2));

            var date1       = new DateTime(2021, 10, 21, 9, 25, 37);
            var dateString1 = date1.ToString("yyyy-MM-ddTHH:mm:ss.fff");

            Assert.Throws <SqExpressException>(() => this.Table.ColDateTime.ReadAsString(reader.Object));
            reader.Setup(r => r.GetNullableDateTime(It.Is <string>(name => name == customColumn.ColumnName.Name))).Returns(date1);
            Assert.AreEqual(dateString1, this.Table.ColDateTime.ReadAsString(reader.Object));

            Assert.AreEqual($"'{dateString1}'", this.Table.ColDateTime.FromString(dateString1).ToSql());
            Assert.Throws <SqExpressException>(() => this.Table.ColDateTime.FromString(null));

            var date2           = new DateTime(2021, 10, 21);
            var dateString2     = date2.ToString("yyyy-MM-dd");
            var dateString2Full = date2.ToString("yyyy-MM-ddTHH:mm:ss.fff");

            reader.Setup(r => r.GetNullableDateTime(It.Is <string>(name => name == customColumn.ColumnName.Name))).Returns(date2);
            Assert.AreEqual(dateString2Full, this.Table.ColDateTime.ReadAsString(reader.Object));

            Assert.AreEqual($"'{dateString2}'", this.Table.ColDateTime.FromString(dateString2).ToSql());
            Assert.Throws <SqExpressException>(() => this.Table.ColDateTime.FromString(null));
        }
Beispiel #8
0
        public void TestByte()
        {
            Assert.AreEqual(SqQueryBuilder.SqlType.Byte, this.Table.ColByte.SqlType);
            Assert.AreEqual("[AT].[ColByte]", this.Table.ColByte.ToSql());
            Assert.IsFalse(this.Table.ColByte.IsNullable);

            DerivedTable dt           = new DerivedTable();
            var          customColumn = this.Table.ColByte.AddToDerivedTable(dt);

            Assert.AreEqual(this.Table.ColByte.ColumnName, customColumn.ColumnName);
            Assert.IsTrue(dt.Columns.Contains(customColumn));

            var customColumn2 = this.Table.ColByte.ToCustomColumn(this.NewSource);

            Assert.AreEqual(this.Table.ColByte.ColumnName, customColumn2.ColumnName);

            var reader = new Mock <ISqDataRecordReader>();

            this.Table.ColByte.Read(reader.Object);
            customColumn.Read(reader.Object);

            reader.Verify(r => r.GetByte(It.Is <string>(name => name == customColumn.ColumnName.Name)), Times.Exactly(2));
        }