[Bug] Fixed QueryAsync not return dynamic type

This commit is contained in:
Wei 2022-03-14 11:57:23 +08:00
parent 309d649c64
commit 9a92d74fa0
6 changed files with 45 additions and 30 deletions

View File

@ -16,6 +16,10 @@
--- ---
### 1.24.1
- [Bug] Fiexd QueryAsync configulation not working #338
- [Bug] Fixed QueryAsync not return dynamic type
### 1.24.0 ### 1.24.0
- [New] Query support strict open xml, thanks [Weilence (Lowell)](https://github.com/Weilence) #335 - [New] Query support strict open xml, thanks [Weilence (Lowell)](https://github.com/Weilence) #335
- [New] SaveAs use the configured CultureInfo to write format cell value, thanks [0xced (Cédric Luthi)](https://github.com/0xced) #333 - [New] SaveAs use the configured CultureInfo to write format cell value, thanks [0xced (Cédric Luthi)](https://github.com/0xced) #333

View File

@ -24,6 +24,10 @@
--- ---
### 1.24.1
- [Bug] 修正 QueryAsync configulation 没有效果问题 #338
- [Bug] 修正 QueryAsync 无法使用 dynamic 类别
### 1.24.0 ### 1.24.0
- [New] Query 支持 strict open xml, 感谢 [Weilence (Lowell)](https://github.com/Weilence) #335 - [New] Query 支持 strict open xml, 感谢 [Weilence (Lowell)](https://github.com/Weilence) #335
- [New] SaveAs 以自订的 CultureInfo 转换 Format cell 值, 感谢[0xced (Cédric Luthi)](https://github.com/0xced) #333 - [New] SaveAs 以自订的 CultureInfo 转换 Format cell 值, 感谢[0xced (Cédric Luthi)](https://github.com/0xced) #333

View File

@ -17,7 +17,13 @@
--- ---
### 1.24.1
- [Bug] 修正 QueryAsync configulation 沒有效果問題 #338
- [Bug] 修正 QueryAsync 無法使用 dynamic 類別
### 1.24.0 ### 1.24.0
- [New] Query 支持 strict open xml, 感謝 [Weilence (Lowell)](https://github.com/Weilence) #335 - [New] Query 支持 strict open xml, 感謝 [Weilence (Lowell)](https://github.com/Weilence) #335
- [New] SaveAs 以自訂的 CultureInfo 轉換 Format cell 值, 感謝[0xced (Cédric Luthi)](https://github.com/0xced) #333 - [New] SaveAs 以自訂的 CultureInfo 轉換 Format cell 值, 感謝[0xced (Cédric Luthi)](https://github.com/0xced) #333
- [New] SaveAsByTemplate 預設忽略 template 缺少參數 key 錯誤, OpenXmlConfiguration.IgnoreTemplateParameterMissing 可以開關此卡控. #I4WXFB - [New] SaveAsByTemplate 預設忽略 template 缺少參數 key 錯誤, OpenXmlConfiguration.IgnoreTemplateParameterMissing 可以開關此卡控. #I4WXFB

View File

@ -798,7 +798,7 @@ namespace MiniExcelLibs.Tests
using (var stream = new MemoryStream()) using (var stream = new MemoryStream())
{ {
stream.SaveAs(new[] { new { V = "test1" }, new { V = "test2" } }); stream.SaveAs(new[] { new { V = "test1" }, new { V = "test2" } });
var q = await stream.QueryAsync(true); var q = (await stream.QueryAsync(true)).Cast<IDictionary<string,object>>();
var rows = q.ToList(); var rows = q.ToList();
Assert.Equal("test1", rows[0]["V"]); Assert.Equal("test1", rows[0]["V"]);
Assert.Equal("test2", rows[1]["V"]); Assert.Equal("test2", rows[1]["V"]);

View File

@ -149,7 +149,7 @@ namespace MiniExcelLibs.Tests
var path = @"../../../../../samples/xlsx/TestCenterEmptyRow/TestCenterEmptyRow.xlsx"; var path = @"../../../../../samples/xlsx/TestCenterEmptyRow/TestCenterEmptyRow.xlsx";
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(); var d = (await stream.QueryAsync()).Cast<IDictionary<string,object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal("a", rows[0]["A"]); Assert.Equal("a", rows[0]["A"]);
Assert.Equal("b", rows[0]["B"]); Assert.Equal("b", rows[0]["B"]);
@ -185,7 +185,7 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal(1d, rows[0]["a"]); Assert.Equal(1d, rows[0]["a"]);
Assert.Null(rows[0]["b"]); Assert.Null(rows[0]["b"]);
@ -220,7 +220,7 @@ namespace MiniExcelLibs.Tests
var path = @"../../../../../samples/xlsx/TestDynamicQueryBasic_WithoutHead.xlsx"; var path = @"../../../../../samples/xlsx/TestDynamicQueryBasic_WithoutHead.xlsx";
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d= await stream.QueryAsync(); var d= (await stream.QueryAsync()).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal("MiniExcel", rows[0]["A"]); Assert.Equal("MiniExcel", rows[0]["A"]);
Assert.Equal(1d, rows[0]["B"]); Assert.Equal(1d, rows[0]["B"]);
@ -235,7 +235,7 @@ namespace MiniExcelLibs.Tests
var path = @"../../../../../samples/xlsx/TestDynamicQueryBasic.xlsx"; var path = @"../../../../../samples/xlsx/TestDynamicQueryBasic.xlsx";
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal("MiniExcel", rows[0]["Column1"]); Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]); Assert.Equal(1d, rows[0]["Column2"]);
@ -329,7 +329,7 @@ namespace MiniExcelLibs.Tests
var path = @"../../../../../samples/xlsx/TestDatetimeSpanFormat_ClosedXml.xlsx"; var path = @"../../../../../samples/xlsx/TestDatetimeSpanFormat_ClosedXml.xlsx";
using (var stream = FileHelper.OpenRead(path)) using (var stream = FileHelper.OpenRead(path))
{ {
var d = await stream.QueryAsync(); var d = (await stream.QueryAsync()).Cast<IDictionary<string, object>>();
var row = d.First(); var row = d.First();
var a = row["A"]; var a = row["A"];
var b = row["B"]; var b = row["B"];
@ -399,7 +399,7 @@ namespace MiniExcelLibs.Tests
var path = @"../../../../../samples/xlsx/TestWihoutRAttribute.xlsx"; var path = @"../../../../../samples/xlsx/TestWihoutRAttribute.xlsx";
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(); var d = (await stream.QueryAsync()).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
var keys = (rows.First() as IDictionary<string, object>).Keys; var keys = (rows.First() as IDictionary<string, object>).Keys;
@ -455,7 +455,7 @@ namespace MiniExcelLibs.Tests
{ {
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: false); var d = (await stream.QueryAsync(useHeaderRow: false)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal(3, rows.Count); Assert.Equal(3, rows.Count);
Assert.Equal("A", rows[0]["A"]); Assert.Equal("A", rows[0]["A"]);
@ -464,7 +464,7 @@ namespace MiniExcelLibs.Tests
} }
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal(2, rows.Count); Assert.Equal(2, rows.Count);
Assert.Equal("A", rows[0]["A"]); Assert.Equal("A", rows[0]["A"]);
@ -524,7 +524,7 @@ namespace MiniExcelLibs.Tests
{ {
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: false); var d = (await stream.QueryAsync(useHeaderRow: false)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal(3, rows.Count); Assert.Equal(3, rows.Count);
Assert.Equal("A", rows[0]["A"]); Assert.Equal("A", rows[0]["A"]);
@ -533,7 +533,7 @@ namespace MiniExcelLibs.Tests
} }
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal(2, rows.Count); Assert.Equal(2, rows.Count);
Assert.Equal("A", rows[0]["A"]); Assert.Equal("A", rows[0]["A"]);
@ -598,7 +598,7 @@ namespace MiniExcelLibs.Tests
{ {
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal(2, rows.Count); Assert.Equal(2, rows.Count);
Assert.Equal(@"""<>+-*//}{\\n", rows[0]["a"]); Assert.Equal(@"""<>+-*//}{\\n", rows[0]["a"]);
@ -609,7 +609,7 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d= await stream.QueryAsync(); var d= (await stream.QueryAsync()).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal(3, rows.Count); Assert.Equal(3, rows.Count);
Assert.Equal("a", rows[0]["A"]); Assert.Equal("a", rows[0]["A"]);
@ -706,13 +706,13 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(); var d = (await stream.QueryAsync()).Cast<IDictionary<string, object>>();
var row = d.First(); var row = d.First();
Assert.Equal("HelloWorld1", row["A"]); Assert.Equal("HelloWorld1", row["A"]);
} }
{ {
var d = await MiniExcel.QueryAsync(path); var d = (await MiniExcel.QueryAsync(path)).Cast<IDictionary<string, object>>();
var rows = d.Take(10); var rows = d.Take(10);
Assert.Equal(10, rows.Count()); Assert.Equal(10, rows.Count());
} }
@ -752,7 +752,7 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: false); var d = (await stream.QueryAsync(useHeaderRow: false)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal("Column1", rows[0]["A"]); Assert.Equal("Column1", rows[0]["A"]);
Assert.Equal("Column2", rows[0]["B"]); Assert.Equal("Column2", rows[0]["B"]);
@ -764,7 +764,7 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal(2, rows.Count); Assert.Equal(2, rows.Count);
Assert.Equal("MiniExcel", rows[0]["Column1"]); Assert.Equal("MiniExcel", rows[0]["Column1"]);
@ -814,7 +814,7 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal("MiniExcel", rows[0]["Column1"]); Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]); Assert.Equal(1d, rows[0]["Column2"]);
@ -860,7 +860,7 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: false); var d = (await stream.QueryAsync(useHeaderRow: false)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal("Column1", rows[0]["A"]); Assert.Equal("Column1", rows[0]["A"]);
Assert.Equal("Column2", rows[0]["B"]); Assert.Equal("Column2", rows[0]["B"]);
@ -872,7 +872,7 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal("MiniExcel", rows[0]["Column1"]); Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]); Assert.Equal(1d, rows[0]["Column2"]);
@ -903,7 +903,7 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal("MiniExcel", rows[0]["Column1"]); Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]); Assert.Equal(1d, rows[0]["Column2"]);
@ -929,7 +929,7 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal("MiniExcel", rows[0]["Column1"]); Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]); Assert.Equal(1d, rows[0]["Column2"]);
@ -959,7 +959,7 @@ namespace MiniExcelLibs.Tests
using (var transaction = connection.BeginTransaction()) using (var transaction = connection.BeginTransaction())
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var rows = await stream.QueryAsync(); var rows = (await stream.QueryAsync()).Cast<IDictionary<string, object>>();
foreach (var row in rows) foreach (var row in rows)
connection.Execute("insert into T (A,B) values (@A,@B)", new { A = row["A"],B = row["B"] }, transaction: transaction); connection.Execute("insert into T (A,B) values (@A,@B)", new { A = row["A"],B = row["B"] }, transaction: transaction);
transaction.Commit(); transaction.Commit();
@ -986,7 +986,7 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal("MiniExcel", rows[0]["Column1"]); Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]); Assert.Equal(1d, rows[0]["Column2"]);
@ -1015,7 +1015,7 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal("MiniExcel", rows[0]["Column1"]); Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]); Assert.Equal(1d, rows[0]["Column2"]);
@ -1041,7 +1041,7 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
var d = await stream.QueryAsync(useHeaderRow: true); var d = (await stream.QueryAsync(useHeaderRow: true)).Cast<IDictionary<string, object>>();
var rows = d.ToList(); var rows = d.ToList();
Assert.Equal("MiniExcel", rows[0]["Column1"]); Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]); Assert.Equal(1d, rows[0]["Column2"]);

View File

@ -3,6 +3,7 @@ using System.Linq;
using System; using System;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.Generic;
namespace MiniExcelLibs.Tests namespace MiniExcelLibs.Tests
{ {
@ -43,28 +44,28 @@ namespace MiniExcelLibs.Tests
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
{ {
var q = await stream.QueryAsync(sheetName: "Sheet3"); var q = (await stream.QueryAsync(sheetName: "Sheet3")).Cast<IDictionary<string, object>>();
var rows = q.ToList(); var rows = q.ToList();
Assert.Equal(5, rows.Count); Assert.Equal(5, rows.Count);
Assert.Equal(3d, rows[0]["A"]); Assert.Equal(3d, rows[0]["A"]);
Assert.Equal(3d, rows[0]["B"]); Assert.Equal(3d, rows[0]["B"]);
} }
{ {
var q = await stream.QueryAsync(sheetName: "Sheet2"); var q = (await stream.QueryAsync(sheetName: "Sheet2")).Cast<IDictionary<string, object>>();
var rows = q.ToList(); var rows = q.ToList();
Assert.Equal(12, rows.Count); Assert.Equal(12, rows.Count);
Assert.Equal(1d, rows[0]["A"]); Assert.Equal(1d, rows[0]["A"]);
Assert.Equal(1d, rows[0]["B"]); Assert.Equal(1d, rows[0]["B"]);
} }
{ {
var q = await stream.QueryAsync(sheetName: "Sheet1"); var q = (await stream.QueryAsync(sheetName: "Sheet1")).Cast<IDictionary<string, object>>();
var rows = q.ToList(); var rows = q.ToList();
Assert.Equal(12, rows.Count); Assert.Equal(12, rows.Count);
Assert.Equal(2d, rows[0]["A"]); Assert.Equal(2d, rows[0]["A"]);
Assert.Equal(2d, rows[0]["B"]); Assert.Equal(2d, rows[0]["B"]);
} }
{ {
var q = await stream.QueryAsync(sheetName: "Sheet1"); var q = (await stream.QueryAsync(sheetName: "Sheet1")).Cast<IDictionary<string, object>>();
var rows = q.ToList(); var rows = q.ToList();
Assert.Equal(12, rows.Count); Assert.Equal(12, rows.Count);
Assert.Equal(2d, rows[0]["A"]); Assert.Equal(2d, rows[0]["A"]);