Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nuke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
run: dotnet restore

- name: Run Nuke Build Test
run: ./build.cmd Test || ./build.sh Test
run: ./build.sh Test
58 changes: 29 additions & 29 deletions tests/LuYao.Common.UnitTests/Data/RecordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void AddRowAndSetColumnValue_WorksCorrectly()
{
// Arrange
var table = new Record();
var colId = table.Columns.Add<int>("Id"); // Ìæ»» Add<Int32> Ϊ Add<int>
var colName = table.Columns.Add<string>("Name"); // Ìæ»» Add<String> Ϊ Add<string>
var colId = table.Columns.Add<int>("Id"); // 替换 Add<Int32> 为 Add<int>
var colName = table.Columns.Add<string>("Name"); // 替换 Add<String> 为 Add<string>

// Act
var row = table.AddRow();
Expand All @@ -38,8 +38,8 @@ public void AddRowAndSetColumnValue_WorksCorrectly()
// Assert
Assert.AreEqual(1, table.Count);
Assert.AreEqual(2, table.Columns.Count);
Assert.AreEqual(1, colId.Get<int>(row.Row)); // Ìæ»» GetValue Ϊ Get<T>
Assert.AreEqual("Test", colName.Get<string>(row.Row)); // Ìæ»» GetValue Ϊ Get<T>
Assert.AreEqual(1, colId.Get<int>(row.Row)); // 替换 GetValue 为 Get<T>
Assert.AreEqual("Test", colName.Get<string>(row.Row)); // 替换 GetValue 为 Get<T>
}

[TestMethod]
Expand All @@ -60,9 +60,9 @@ public void AddMultipleRowsAndColumns_WorksCorrectly()
{
// Arrange
var table = new Record();
var colId = table.Columns.Add<int>("Id"); // Ìæ»» Add<Int32> Ϊ Add<int>
var colName = table.Columns.Add<string>("Name"); // Ìæ»» Add<String> Ϊ Add<string>
var colAge = table.Columns.Add<int>("Age"); // Ìæ»» Add<Int32> Ϊ Add<int>
var colId = table.Columns.Add<int>("Id"); // 替换 Add<Int32> 为 Add<int>
var colName = table.Columns.Add<string>("Name"); // 替换 Add<String> 为 Add<string>
var colAge = table.Columns.Add<int>("Age"); // 替换 Add<Int32> 为 Add<int>

// Act
var row1 = table.AddRow();
Expand All @@ -79,13 +79,13 @@ public void AddMultipleRowsAndColumns_WorksCorrectly()
Assert.AreEqual(2, table.Count);
Assert.AreEqual(3, table.Columns.Count);

Assert.AreEqual(1, colId.Get<int>(row1.Row)); // Ìæ»» GetValue Ϊ Get<T>
Assert.AreEqual("Alice", colName.Get<string>(row1.Row)); // Ìæ»» GetValue Ϊ Get<T>
Assert.AreEqual(25, colAge.Get<int>(row1.Row)); // Ìæ»» GetValue Ϊ Get<T>
Assert.AreEqual(1, colId.Get<int>(row1.Row)); // 替换 GetValue 为 Get<T>
Assert.AreEqual("Alice", colName.Get<string>(row1.Row)); // 替换 GetValue 为 Get<T>
Assert.AreEqual(25, colAge.Get<int>(row1.Row)); // 替换 GetValue 为 Get<T>

Assert.AreEqual(2, colId.Get<int>(row2.Row)); // Ìæ»» GetValue Ϊ Get<T>
Assert.AreEqual("Bob", colName.Get<string>(row2.Row)); // Ìæ»» GetValue Ϊ Get<T>
Assert.AreEqual(30, colAge.Get<int>(row2.Row)); // Ìæ»» GetValue Ϊ Get<T>
Assert.AreEqual(2, colId.Get<int>(row2.Row)); // 替换 GetValue 为 Get<T>
Assert.AreEqual("Bob", colName.Get<string>(row2.Row)); // 替换 GetValue 为 Get<T>
Assert.AreEqual(30, colAge.Get<int>(row2.Row)); // 替换 GetValue 为 Get<T>
}

[TestMethod]
Expand Down Expand Up @@ -277,7 +277,7 @@ public void RowImplicitConversion_WorksCorrectly()
var row = rows[1];

// Act
int rowIndex = row; // Òþʽת»»
int rowIndex = row; // 隐式转换

// Assert
Assert.AreEqual(1, rowIndex);
Expand Down Expand Up @@ -681,7 +681,7 @@ public void ToString_LongStringValue_TruncatesWithEllipsis()
Assert.IsTrue(result.Contains("..") || result.Contains("LongStringTest"));
}

// ÐÂÔöµÄ±ß½ç¼ì²é²âÊÔ·½·¨
// 新增的边界检查测试方法

[TestMethod]
public void GetValue_NegativeRowIndex_ThrowsArgumentOutOfRangeException()
Expand All @@ -693,7 +693,7 @@ public void GetValue_NegativeRowIndex_ThrowsArgumentOutOfRangeException()

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => col.GetValue(-1));
Assert.IsTrue(exception.Message.Contains("ÐÐË÷Òý -1 ³¬³öÓÐЧ·¶Î§"));
Assert.IsTrue(exception.Message.Contains("行索引 -1 超出有效范围"));
}

[TestMethod]
Expand All @@ -706,7 +706,7 @@ public void GetValue_RowIndexEqualToCount_ThrowsArgumentOutOfRangeException()

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => col.GetValue(1));
Assert.IsTrue(exception.Message.Contains("ÐÐË÷Òý 1 ³¬³öÓÐЧ·¶Î§"));
Assert.IsTrue(exception.Message.Contains("行索引 1 超出有效范围"));
}

[TestMethod]
Expand All @@ -719,7 +719,7 @@ public void GetValue_RowIndexGreaterThanCount_ThrowsArgumentOutOfRangeException(

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => col.GetValue(5));
Assert.IsTrue(exception.Message.Contains("ÐÐË÷Òý 5 ³¬³öÓÐЧ·¶Î§"));
Assert.IsTrue(exception.Message.Contains("行索引 5 超出有效范围"));
}

[TestMethod]
Expand All @@ -732,7 +732,7 @@ public void SetValue_NegativeRowIndex_ThrowsArgumentOutOfRangeException()

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => col.SetValue("test", -1));
Assert.IsTrue(exception.Message.Contains("ÐÐË÷Òý -1 ³¬³öÓÐЧ·¶Î§"));
Assert.IsTrue(exception.Message.Contains("行索引 -1 超出有效范围"));
}

[TestMethod]
Expand All @@ -745,7 +745,7 @@ public void SetValue_RowIndexEqualToCount_ThrowsArgumentOutOfRangeException()

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => col.SetValue("test", 1));
Assert.IsTrue(exception.Message.Contains("ÐÐË÷Òý 1 ³¬³öÓÐЧ·¶Î§"));
Assert.IsTrue(exception.Message.Contains("行索引 1 超出有效范围"));
}

[TestMethod]
Expand All @@ -758,7 +758,7 @@ public void SetValue_RowIndexGreaterThanCount_ThrowsArgumentOutOfRangeException(

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => col.SetValue("test", 5));
Assert.IsTrue(exception.Message.Contains("ÐÐË÷Òý 5 ³¬³öÓÐЧ·¶Î§"));
Assert.IsTrue(exception.Message.Contains("行索引 5 超出有效范围"));
}

[TestMethod]
Expand All @@ -771,7 +771,7 @@ public void SetBoolean_NegativeIndex_ThrowsArgumentOutOfRangeException()

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => col.Set(true, -1));
Assert.IsTrue(exception.Message.Contains("ÐÐË÷Òý -1 ³¬³öÓÐЧ·¶Î§"));
Assert.IsTrue(exception.Message.Contains("行索引 -1 超出有效范围"));
}

[TestMethod]
Expand All @@ -784,7 +784,7 @@ public void SetBoolean_IndexEqualToCount_ThrowsArgumentOutOfRangeException()

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => col.Set(true, 1));
Assert.IsTrue(exception.Message.Contains("ÐÐË÷Òý 1 ³¬³öÓÐЧ·¶Î§"));
Assert.IsTrue(exception.Message.Contains("行索引 1 超出有效范围"));
}

[TestMethod]
Expand All @@ -797,7 +797,7 @@ public void SetInt32_IndexGreaterThanCount_ThrowsArgumentOutOfRangeException()

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => col.Set(42, 5));
Assert.IsTrue(exception.Message.Contains("ÐÐË÷Òý 5 ³¬³öÓÐЧ·¶Î§"));
Assert.IsTrue(exception.Message.Contains("行索引 5 超出有效范围"));
}

[TestMethod]
Expand All @@ -810,7 +810,7 @@ public void ToBoolean_NegativeIndex_ThrowsArgumentOutOfRangeException()

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => col.Get<Boolean>(-1));
Assert.IsTrue(exception.Message.Contains("ÐÐË÷Òý -1 ³¬³öÓÐЧ·¶Î§"));
Assert.IsTrue(exception.Message.Contains("行索引 -1 超出有效范围"));
}

[TestMethod]
Expand All @@ -823,7 +823,7 @@ public void ToInt32_IndexEqualToCount_ThrowsArgumentOutOfRangeException()

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => col.Get<Int32>(1));
Assert.IsTrue(exception.Message.Contains("ÐÐË÷Òý 1 ³¬³öÓÐЧ·¶Î§"));
Assert.IsTrue(exception.Message.Contains("行索引 1 超出有效范围"));
}

[TestMethod]
Expand All @@ -836,7 +836,7 @@ public void ToString_IndexGreaterThanCount_ThrowsArgumentOutOfRangeException()

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => col.Get<String>(10));
Assert.IsTrue(exception.Message.Contains("ÐÐË÷Òý 10 ³¬³öÓÐЧ·¶Î§"));
Assert.IsTrue(exception.Message.Contains("行索引 10 超出有效范围"));
}

[TestMethod]
Expand Down Expand Up @@ -1014,7 +1014,7 @@ public void Columns_AddDuplicateName_ThrowsException()
table.Columns.Add<String>("TestColumn");

// Act & Assert
Assert.Throws<DuplicateNameException>(() => table.Columns.Add<String>("TestColumn")); // Ó¦¸ÃÅ׳öÒì³£
Assert.Throws<DuplicateNameException>(() => table.Columns.Add<String>("TestColumn")); // 应该抛出异常
}

[TestMethod]
Expand All @@ -1025,7 +1025,7 @@ public void Columns_AddDuplicateNameDifferentType_ThrowsException()
table.Columns.Add<String>("TestColumn");

// Act & Assert
Assert.Throws<DuplicateNameException>(() => table.Columns.Add<Int32>("TestColumn")); // Ó¦¸ÃÅ׳öÒì³£
Assert.Throws<DuplicateNameException>(() => table.Columns.Add<Int32>("TestColumn")); // 应该抛出异常
}

public class Student
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ await Assert.ThrowsAsync<ArgumentNullException>(async () =>
public async Task ReadAsHtmlAsync_CharsetInHeader_UsesHeaderEncoding()
{
// Arrange
var content = new StringContent("²âÊÔÄÚÈÝ", Encoding.Unicode);
var content = new StringContent("测试内容", Encoding.Unicode);
if (content.Headers.ContentType != null)
{
content.Headers.ContentType.CharSet = "utf-16";
Expand All @@ -42,14 +42,14 @@ public async Task ReadAsHtmlAsync_CharsetInHeader_UsesHeaderEncoding()
var result = await response.ReadAsHtmlAsync();

// Assert
Assert.AreEqual("²âÊÔÄÚÈÝ", result);
Assert.AreEqual("测试内容", result);
}

[TestMethod]
public async Task ReadAsHtmlAsync_CharsetInHtml_UsesHtmlEncoding()
{
// Arrange
var html = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\"><div>ÖÐÎÄÄÚÈÝ</div>";
var html = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\"><div>中文内容</div>";
var bytes = Encoding.GetEncoding("gb2312").GetBytes(html);
var content = new ByteArrayContent(bytes);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/html");
Expand All @@ -62,14 +62,14 @@ public async Task ReadAsHtmlAsync_CharsetInHtml_UsesHtmlEncoding()
var result = await response.ReadAsHtmlAsync();

// Assert
Assert.IsTrue(result.Contains("ÖÐÎÄÄÚÈÝ"));
Assert.IsTrue(result.Contains("中文内容"));
}

[TestMethod]
public async Task ReadAsHtmlAsync_NoCharset_UsesUtf8ByDefault()
{
// Arrange
var text = "ĬÈÏUTF8ÄÚÈÝ";
var text = "默认UTF8内容";
var bytes = Encoding.UTF8.GetBytes(text);
var content = new ByteArrayContent(bytes);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/plain");
Expand Down
Loading