using System.Threading.Tasks;
using Util.Data.Sql;
using Util.Tests.Configs;
using Util.Tests.Models;
using Xunit;
namespace Util.Data.Dapper.Tests.SqlQuery;
///
/// Sql Server Sql查询对象测试 - 获取单个对象测试
///
public partial class SqlServerSqlQueryTest {
///
/// 测试获取单个实体
///
[Fact]
public void TestExecuteSingle() {
var result = _sqlQuery.Select( "ProductId as Id,Code" ).From( "Products.Product" ).Where( "ProductId", TestConfig.Id ).ExecuteSingle();
Assert.Equal( TestConfig.Id, result.Id );
Assert.Equal( TestConfig.Value, result.Code );
}
///
/// 测试获取单个实体
///
[Fact]
public async Task TestExecuteSingleAsync() {
var result = await _sqlQuery.Select( "ProductId as Id,Code" ).From( "Products.Product" ).Where( "ProductId", TestConfig.Id ).ExecuteSingleAsync();
Assert.Equal( TestConfig.Id, result.Id );
Assert.Equal( TestConfig.Value, result.Code );
}
///
/// 测试获取单个实体
///
[Fact]
public void TestToEntity() {
var result = _sqlQuery.Select( "ProductId as Id,Code" ).From( "Products.Product" ).Where( "ProductId", TestConfig.Id ).ToEntity();
Assert.Equal( TestConfig.Id, result.Id );
Assert.Equal( TestConfig.Value, result.Code );
}
///
/// 测试获取单个实体
///
[Fact]
public async Task TestToEntityAsync() {
var result = await _sqlQuery.Select( "ProductId as Id,Code" ).From( "Products.Product" ).Where( "ProductId", TestConfig.Id ).ToEntityAsync();
Assert.Equal( TestConfig.Id, result.Id );
Assert.Equal( TestConfig.Value, result.Code );
}
}