using System.Threading.Tasks;
using Util.Data.Sql;
using Util.Tests.Configs;
namespace Util.Data.Dapper.Tests.SqlQuery {
///
/// Oracle Sql查询对象测试 - 单值测试
///
public partial class OracleQueryTest {
#region ExecuteScalar
///
/// 测试获取单值
///
[Fact]
public void TestExecuteScalar_1() {
var result = _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ExecuteScalar();
Assert.Equal( TestConfig.Value, result.SafeString() );
}
///
/// 测试获取单值 - 泛型
///
[Fact]
public void TestExecuteScalar_2() {
var result = _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ExecuteScalar();
Assert.Equal( TestConfig.Value, result );
}
#endregion
#region ExecuteScalarAsync
///
/// 测试获取单值
///
[Fact]
public async Task TestExecuteScalarAsync_1() {
var result = await _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ExecuteScalarAsync();
Assert.Equal( TestConfig.Value, result.SafeString() );
}
///
/// 测试获取单值 - 泛型
///
[Fact]
public async Task TestExecuteScalarAsync_2() {
var result = await _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ExecuteScalarAsync();
Assert.Equal( TestConfig.Value, result );
}
#endregion
#region ToStringAsync
///
/// 测试获取字符串值
///
[Fact]
public async Task TestToStringAsync() {
var result = await _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToStringAsync();
Assert.Equal( TestConfig.Value, result );
}
#endregion
#region ToInt
///
/// 测试获取32位整型值
///
[Fact]
public void TestToInt() {
var result = _sqlQuery.Select( "IntPrice" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToInt();
Assert.Equal( TestConfig.IntValue, result );
}
#endregion
#region ToIntAsync
///
/// 测试获取32位整型值
///
[Fact]
public async Task TestToIntAsync() {
var result = await _sqlQuery.Select( "IntPrice" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToIntAsync();
Assert.Equal( TestConfig.IntValue, result );
}
#endregion
#region ToIntOrNull
///
/// 测试获取32位整型值 - 有值
///
[Fact]
public void TestToIntOrNull_1() {
var result = _sqlQuery.Select( "IntPrice" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToIntOrNull();
Assert.Equal( TestConfig.IntValue, result );
}
///
/// 测试获取32位可空整型值 - 空值
///
[Fact]
public void TestToIntOrNull_2() {
var result = _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToIntOrNull();
Assert.Null( result );
}
#endregion
#region ToIntOrNullAsync
///
/// 测试获取32位可空整型值 - 有值
///
[Fact]
public async Task TestToIntOrNullAsync_1() {
var result = await _sqlQuery.Select( "IntPrice" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToIntOrNullAsync();
Assert.Equal( TestConfig.IntValue, result );
}
///
/// 测试获取32位可空整型值 - 空值
///
[Fact]
public async Task TestToIntOrNullAsync_2() {
var result = await _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToIntOrNullAsync();
Assert.Null( result );
}
#endregion
#region ToLong
///
/// 测试获取64位整型值
///
[Fact]
public void TestToLong() {
var result = _sqlQuery.Select( "LongPrice" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToLong();
Assert.Equal( TestConfig.LongValue, result );
}
#endregion
#region ToLongAsync
///
/// 测试获取64位整型值
///
[Fact]
public async Task TestToLongAsync() {
var result = await _sqlQuery.Select( "LongPrice" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToLongAsync();
Assert.Equal( TestConfig.LongValue, result );
}
#endregion
#region ToLongOrNull
///
/// 测试获取64位可空整型值 - 有值
///
[Fact]
public void TestToLongOrNull_1() {
var result = _sqlQuery.Select( "LongPrice" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToLongOrNull();
Assert.Equal( TestConfig.LongValue, result );
}
///
/// 测试获取64位可空整型值 - 空值
///
[Fact]
public void TestToLongOrNull_2() {
var result = _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToLongOrNull();
Assert.Null( result );
}
#endregion
#region ToLongOrNullAsync
///
/// 测试获取64位可空整型值 - 有值
///
[Fact]
public async Task TestToLongOrNullAsync_1() {
var result = await _sqlQuery.Select( "LongPrice" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToLongOrNullAsync();
Assert.Equal( TestConfig.LongValue, result );
}
///
/// 测试获取64位可空整型值 - 空值
///
[Fact]
public async Task TestToLongOrNullAsync_2() {
var result = await _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToLongOrNullAsync();
Assert.Null( result );
}
#endregion
#region ToGuid
///
/// 测试获取Guid值
///
[Fact]
public void TestToGuid() {
var result = _sqlQuery.Select( "ProductId" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToGuid();
Assert.Equal( TestConfig.Id, result );
}
#endregion
#region ToGuidAsync
///
/// 测试获取Guid值
///
[Fact]
public async Task TestToGuidAsync() {
var result = await _sqlQuery.Select( "ProductId" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToGuidAsync();
Assert.Equal( TestConfig.Id, result );
}
#endregion
#region ToGuidOrNull
///
/// 测试获取可空Guid值 - 有值
///
[Fact]
public void TestToGuidOrNull_1() {
var result = _sqlQuery.Select( "ProductId" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToGuidOrNull();
Assert.Equal( TestConfig.Id, result );
}
///
/// 测试获取可空Guid值 - 空值
///
[Fact]
public void TestToGuidOrNull_2() {
var result = _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToGuidOrNull();
Assert.Null( result );
}
#endregion
#region ToGuidOrNullAsync
///
/// 测试获取可空Guid值 - 有值
///
[Fact]
public async Task TestToGuidOrNullAsync_1() {
var result = await _sqlQuery.Select( "ProductId" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToGuidOrNullAsync();
Assert.Equal( TestConfig.Id, result );
}
///
/// 测试获取可空Guid值 - 空值
///
[Fact]
public async Task TestToGuidOrNullAsync_2() {
var result = await _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToGuidOrNullAsync();
Assert.Null( result );
}
#endregion
#region ToBool
///
/// 测试获取布尔值
///
[Fact]
public void TestToBool() {
var result = _sqlQuery.Select( "Enabled" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToBool();
Assert.Equal( TestConfig.BoolValue, result );
}
#endregion
#region ToBoolAsync
///
/// 测试获取布尔值
///
[Fact]
public async Task TestToBoolAsync() {
var result = await _sqlQuery.Select( "Enabled" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToBoolAsync();
Assert.Equal( TestConfig.BoolValue, result );
}
#endregion
#region ToBoolOrNull
///
/// 测试获取可空布尔值 - 有值
///
[Fact]
public void TestToBoolOrNull_1() {
var result = _sqlQuery.Select( "Enabled" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToBoolOrNull();
Assert.Equal( TestConfig.BoolValue, result );
}
///
/// 测试获取可空布尔值 - 空值
///
[Fact]
public void TestToBoolOrNull_2() {
var result = _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToBoolOrNull();
Assert.Null( result );
}
#endregion
#region ToBoolOrNullAsync
///
/// 测试获取可空布尔值 - 有值
///
[Fact]
public async Task TestToBoolOrNullAsync_1() {
var result = await _sqlQuery.Select( "Enabled" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToBoolOrNullAsync();
Assert.Equal( TestConfig.BoolValue, result );
}
///
/// 测试获取可空布尔值 - 空值
///
[Fact]
public async Task TestToBoolOrNullAsync_2() {
var result = await _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToBoolOrNullAsync();
Assert.Null( result );
}
#endregion
#region ToFloat
///
/// 测试获取Float值
///
[Fact]
public void TestToFloat() {
var result = _sqlQuery.Select( "FloatPrice" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToFloat();
Assert.Equal( TestConfig.FloatValue, result );
}
#endregion
#region ToFloatAsync
///
/// 测试获取Float值
///
[Fact]
public async Task TestToFloatAsync() {
var result = await _sqlQuery.Select( "FloatPrice" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToFloatAsync();
Assert.Equal( TestConfig.FloatValue, result );
}
#endregion
#region ToFloatOrNull
///
/// 测试获取可空Float值 - 有值
///
[Fact]
public void TestToFloatOrNull_1() {
var result = _sqlQuery.Select( "FloatPrice" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToFloatOrNull();
Assert.Equal( TestConfig.FloatValue, result );
}
///
/// 测试获取可空Float值 - 空值
///
[Fact]
public void TestToFloatOrNull_2() {
var result = _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToFloatOrNull();
Assert.Null( result );
}
#endregion
#region ToFloatOrNullAsync
///
/// 测试获取可空Float值 - 有值
///
[Fact]
public async Task TestToFloatOrNullAsync_1() {
var result = await _sqlQuery.Select( "FloatPrice" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToFloatOrNullAsync();
Assert.Equal( TestConfig.FloatValue, result );
}
///
/// 测试获取可空Float值 - 空值
///
[Fact]
public async Task TestToFloatOrNullAsync_2() {
var result = await _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToFloatOrNullAsync();
Assert.Null( result );
}
#endregion
#region ToDouble
///
/// 测试获取Double值
///
[Fact]
public void TestToDouble() {
var result = _sqlQuery.Select( "Price" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToDouble();
Assert.Equal( TestConfig.DoubleValue, result );
}
#endregion
#region ToDoubleAsync
///
/// 测试获取Double值
///
[Fact]
public async Task TestToDoubleAsync() {
var result = await _sqlQuery.Select( "Price" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToDoubleAsync();
Assert.Equal( TestConfig.DoubleValue, result );
}
#endregion
#region ToDoubleOrNull
///
/// 测试获取可空Double值 - 有值
///
[Fact]
public void TestToDoubleOrNull_1() {
var result = _sqlQuery.Select( "Price" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToDoubleOrNull();
Assert.Equal( TestConfig.DoubleValue, result );
}
///
/// 测试获取可空Double值 - 空值
///
[Fact]
public void TestToDoubleOrNull_2() {
var result = _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToDoubleOrNull();
Assert.Null( result );
}
#endregion
#region ToDoubleOrNullAsync
///
/// 测试获取可空Double值 - 有值
///
[Fact]
public async Task TestToDoubleOrNullAsync_1() {
var result = await _sqlQuery.Select( "Price" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToDoubleOrNullAsync();
Assert.Equal( TestConfig.DoubleValue, result );
}
///
/// 测试获取可空Double值 - 空值
///
[Fact]
public async Task TestToDoubleOrNullAsync_2() {
var result = await _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToDoubleOrNullAsync();
Assert.Null( result );
}
#endregion
#region ToDecimal
///
/// 测试获取Decimal值
///
[Fact]
public void TestToDecimal() {
var result = _sqlQuery.Select( "Price" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToDecimal();
Assert.Equal( TestConfig.DecimalValue, result );
}
#endregion
#region ToDecimalAsync
///
/// 测试获取Decimal值
///
[Fact]
public async Task TestToDecimalAsync() {
var result = await _sqlQuery.Select( "Price" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToDecimalAsync();
Assert.Equal( TestConfig.DecimalValue, result );
}
#endregion
#region ToDecimalOrNull
///
/// 测试获取Decimal值 - 有值
///
[Fact]
public void TestToDecimalOrNull_1() {
var result = _sqlQuery.Select( "Price" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToDecimalOrNull();
Assert.Equal( TestConfig.DecimalValue, result );
}
///
/// 测试获取Decimal值 - 空值
///
[Fact]
public void TestToDecimalOrNull_2() {
var result = _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToDecimalOrNull();
Assert.Null( result );
}
#endregion
#region ToDecimalOrNullAsync
///
/// 测试获取可空Decimal值 - 有值
///
[Fact]
public async Task TestToDecimalOrNullAsync_1() {
var result = await _sqlQuery.Select( "Price" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToDecimalOrNullAsync();
Assert.Equal( TestConfig.DecimalValue, result );
}
///
/// 测试获取可空Decimal值 - 空值
///
[Fact]
public async Task TestToDecimalOrNullAsync_2() {
var result = await _sqlQuery.Select( "Code" ).From( "Product" ).Where( "ProductId", TestConfig.Id ).ToDecimalOrNullAsync();
Assert.Null( result );
}
#endregion
#region ToDateTime
///
/// 测试获取日期值
///
[Fact]
public void TestToDateTime() {
var result = _sqlQuery.Select( "Birthday" ).From( "Customer" ).Where( "CustomerId", 1 ).ToDateTime();
Assert.Equal( TestConfig.DateTimeValue, result );
}
#endregion
#region ToDateTimeAsync
///
/// 测试获取日期值
///
[Fact]
public async Task TestToDateTimeAsync() {
var result = await _sqlQuery.Select( "Birthday" ).From( "Customer" ).Where( "CustomerId", 1 ).ToDateTimeAsync();
Assert.Equal( TestConfig.DateTimeValue, result );
}
#endregion
#region ToDateTimeOrNull
///
/// 测试获取可空日期值 - 有值
///
[Fact]
public void TestToDateTimeOrNull_1() {
var result = _sqlQuery.Select( "Birthday" ).From( "Customer" ).Where( "CustomerId", 1 ).ToDateTimeOrNull();
Assert.Equal( TestConfig.DateTimeValue, result );
}
///
/// 测试获取可空日期值 - 空值
///
[Fact]
public void TestToDateTimeOrNull_2() {
var result = _sqlQuery.Select( "Code" ).From( "Customer" ).Where( "CustomerId", 1 ).ToDateTimeOrNull();
Assert.Null( result );
}
#endregion
#region ToDateTimeOrNullAsync
///
/// 测试获取可空日期值 - 有值
///
[Fact]
public async Task TestToDateTimeOrNullAsync_1() {
var result = await _sqlQuery.Select( "Birthday" ).From( "Customer" ).Where( "CustomerId", 1 ).ToDateTimeOrNullAsync();
Assert.Equal( TestConfig.DateTimeValue, result );
}
///
/// 测试获取可空日期值 - 空值
///
[Fact]
public async Task TestToDateTimeOrNullAsync_2() {
var result = await _sqlQuery.Select( "Code" ).From( "Customer" ).Where( "CustomerId", 1 ).ToDateTimeOrNullAsync();
Assert.Null( result );
}
#endregion
}
}