Skip to content

Commit

Permalink
[Bug] Fixed QueryAsync not return dynamic type
Browse files Browse the repository at this point in the history
  • Loading branch information
shps951023 committed Mar 14, 2022
1 parent 309d649 commit 9a92d74
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 30 deletions.
4 changes: 4 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

---

### 1.24.1
- [Bug] Fiexd QueryAsync configulation not working #338
- [Bug] Fixed QueryAsync not return dynamic type

### 1.24.0
- [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
Expand Down
4 changes: 4 additions & 0 deletions docs/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

---

### 1.24.1
- [Bug] 修正 QueryAsync configulation 没有效果问题 #338
- [Bug] 修正 QueryAsync 无法使用 dynamic 类别

### 1.24.0
- [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
Expand Down
6 changes: 6 additions & 0 deletions docs/README.zh-Hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@

---


### 1.24.1
- [Bug] 修正 QueryAsync configulation 沒有效果問題 #338
- [Bug] 修正 QueryAsync 無法使用 dynamic 類別

### 1.24.0

- [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] SaveAsByTemplate 預設忽略 template 缺少參數 key 錯誤, OpenXmlConfiguration.IgnoreTemplateParameterMissing 可以開關此卡控. #I4WXFB
Expand Down
2 changes: 1 addition & 1 deletion tests/MiniExcelTests/MiniExcelIssueAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ public async Task Issue215()
using (var stream = new MemoryStream())
{
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();
Assert.Equal("test1", rows[0]["V"]);
Assert.Equal("test2", rows[1]["V"]);
Expand Down
50 changes: 25 additions & 25 deletions tests/MiniExcelTests/MiniExcelOpenXmlAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public async Task CenterEmptyRowsQueryTest()
var path = @"../../../../../samples/xlsx/TestCenterEmptyRow/TestCenterEmptyRow.xlsx";
using (var stream = File.OpenRead(path))
{
var d = await stream.QueryAsync();
var d = (await stream.QueryAsync()).Cast<IDictionary<string,object>>();
var rows = d.ToList();
Assert.Equal("a", rows[0]["A"]);
Assert.Equal("b", rows[0]["B"]);
Expand Down Expand Up @@ -185,7 +185,7 @@ public async Task CenterEmptyRowsQueryTest()

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();
Assert.Equal(1d, rows[0]["a"]);
Assert.Null(rows[0]["b"]);
Expand Down Expand Up @@ -220,7 +220,7 @@ public async Task TestDynamicQueryBasic_WithoutHead()
var path = @"../../../../../samples/xlsx/TestDynamicQueryBasic_WithoutHead.xlsx";
using (var stream = File.OpenRead(path))
{
var d= await stream.QueryAsync();
var d= (await stream.QueryAsync()).Cast<IDictionary<string, object>>();
var rows = d.ToList();
Assert.Equal("MiniExcel", rows[0]["A"]);
Assert.Equal(1d, rows[0]["B"]);
Expand All @@ -235,7 +235,7 @@ public async Task TestDynamicQueryBasic_useHeaderRow()
var path = @"../../../../../samples/xlsx/TestDynamicQueryBasic.xlsx";
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();
Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]);
Expand Down Expand Up @@ -329,7 +329,7 @@ public async Task TestDatetimeSpanFormat_ClosedXml()
var path = @"../../../../../samples/xlsx/TestDatetimeSpanFormat_ClosedXml.xlsx";
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 a = row["A"];
var b = row["B"];
Expand Down Expand Up @@ -399,7 +399,7 @@ public async Task QuerySheetWithoutRAttribute()
var path = @"../../../../../samples/xlsx/TestWihoutRAttribute.xlsx";
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 keys = (rows.First() as IDictionary<string, object>).Keys;

Expand Down Expand Up @@ -455,7 +455,7 @@ public async Task SaveAsFileWithDimensionByICollection()
{
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();
Assert.Equal(3, rows.Count);
Assert.Equal("A", rows[0]["A"]);
Expand All @@ -464,7 +464,7 @@ public async Task SaveAsFileWithDimensionByICollection()
}
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();
Assert.Equal(2, rows.Count);
Assert.Equal("A", rows[0]["A"]);
Expand Down Expand Up @@ -524,7 +524,7 @@ public async Task SaveAsFileWithDimensionByICollection()
{
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();
Assert.Equal(3, rows.Count);
Assert.Equal("A", rows[0]["A"]);
Expand All @@ -533,7 +533,7 @@ public async Task SaveAsFileWithDimensionByICollection()
}
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();
Assert.Equal(2, rows.Count);
Assert.Equal("A", rows[0]["A"]);
Expand Down Expand Up @@ -598,7 +598,7 @@ public async Task SaveAsFileWithDimension()
{
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();
Assert.Equal(2, rows.Count);
Assert.Equal(@"""<>+-*//}{\\n", rows[0]["a"]);
Expand All @@ -609,7 +609,7 @@ public async Task SaveAsFileWithDimension()

using (var stream = File.OpenRead(path))
{
var d= await stream.QueryAsync();
var d= (await stream.QueryAsync()).Cast<IDictionary<string, object>>();
var rows = d.ToList();
Assert.Equal(3, rows.Count);
Assert.Equal("a", rows[0]["A"]);
Expand Down Expand Up @@ -706,13 +706,13 @@ public async Task QueryByLINQExtensionsVoidTaskLargeFileOOMTest()

using (var stream = File.OpenRead(path))
{
var d = await stream.QueryAsync();
var d = (await stream.QueryAsync()).Cast<IDictionary<string, object>>();
var row = d.First();
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);
Assert.Equal(10, rows.Count());
}
Expand Down Expand Up @@ -752,7 +752,7 @@ public async Task SaveAsByIEnumerableIDictionary()

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();
Assert.Equal("Column1", rows[0]["A"]);
Assert.Equal("Column2", rows[0]["B"]);
Expand All @@ -764,7 +764,7 @@ public async Task SaveAsByIEnumerableIDictionary()

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();
Assert.Equal(2, rows.Count);
Assert.Equal("MiniExcel", rows[0]["Column1"]);
Expand Down Expand Up @@ -814,7 +814,7 @@ public async Task SaveAsByDapperRows()

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();
Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]);
Expand Down Expand Up @@ -860,7 +860,7 @@ public async Task SaveAsByDapperRows()

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();
Assert.Equal("Column1", rows[0]["A"]);
Assert.Equal("Column2", rows[0]["B"]);
Expand All @@ -872,7 +872,7 @@ public async Task SaveAsByDapperRows()

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();
Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]);
Expand Down Expand Up @@ -903,7 +903,7 @@ public async Task QueryByStrongTypeParameterTest()

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();
Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]);
Expand All @@ -929,7 +929,7 @@ public async Task QueryByDictionaryStringAndObjectParameterTest()

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();
Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]);
Expand Down Expand Up @@ -959,7 +959,7 @@ public async Task SQLiteInsertTest()
using (var transaction = connection.BeginTransaction())
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)
connection.Execute("insert into T (A,B) values (@A,@B)", new { A = row["A"],B = row["B"] }, transaction: transaction);
transaction.Commit();
Expand All @@ -986,7 +986,7 @@ await MiniExcel.SaveAsAsync(path, new[] {

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();
Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]);
Expand Down Expand Up @@ -1015,7 +1015,7 @@ public async Task SaveAsBasicStreamTest()

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();
Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]);
Expand All @@ -1041,7 +1041,7 @@ public async Task SaveAsBasicStreamTest()

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();
Assert.Equal("MiniExcel", rows[0]["Column1"]);
Assert.Equal(1d, rows[0]["Column2"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.IO;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace MiniExcelLibs.Tests
{
Expand Down Expand Up @@ -43,28 +44,28 @@ await Assert.ThrowsAsync<InvalidOperationException>(async() => {
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();
Assert.Equal(5, rows.Count);
Assert.Equal(3d, rows[0]["A"]);
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();
Assert.Equal(12, rows.Count);
Assert.Equal(1d, rows[0]["A"]);
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();
Assert.Equal(12, rows.Count);
Assert.Equal(2d, rows[0]["A"]);
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();
Assert.Equal(12, rows.Count);
Assert.Equal(2d, rows[0]["A"]);
Expand Down

0 comments on commit 9a92d74

Please sign in to comment.