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
4 changes: 4 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
{
"sdk": {
"version": "9.0.0",
"rollForward": "latestMinor"
}
}
2 changes: 1 addition & 1 deletion src/LuYao.Common/LuYao.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\build\common.props" />
<Import Project="..\..\build\configureawait.props" />
<PropertyGroup>
<TargetFrameworks>net45;net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net10.0</TargetFrameworks>
<TargetFrameworks>net45;net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net9.0</TargetFrameworks>
<RootNamespace>LuYao</RootNamespace>
<Title>LuYao.Common</Title>
<LangVersion>latest</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/LuYao.Text.Json.Jint/LuYao.Text.Json.Jint.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="..\..\build\common.props" />
<Import Project="..\..\build\configureawait.props" />
<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net10.0</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net9.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<RootNamespace>LuYao.Text.Json</RootNamespace>
Expand Down
2 changes: 1 addition & 1 deletion src/LuYao.Text.Json/LuYao.Text.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="..\..\build\common.props" />
<Import Project="..\..\build\configureawait.props" />
<PropertyGroup>
<TargetFrameworks>net45;net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net10.0</TargetFrameworks>
<TargetFrameworks>net45;net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net9.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<SignAssembly>True</SignAssembly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,23 @@ public void SplitToBatch_ListWithRemainder_ReturnsLastBatchWithFewerItems()
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void SplitToBatch_NullSource_ThrowsArgumentNullException()
{
List<int>? input = null;
_ = input.SplitToBatch(2).ToList();
Assert.ThrowsException<ArgumentNullException>(() => input.SplitToBatch(2).ToList());
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void SplitToBatch_BatchSizeZero_ThrowsArgumentOutOfRangeException()
{
var input = Enumerable.Range(1, 3);
_ = input.SplitToBatch(0).ToList();
Assert.ThrowsException<ArgumentOutOfRangeException>(() => input.SplitToBatch(0).ToList());
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void SplitToBatch_BatchSizeNegative_ThrowsArgumentOutOfRangeException()
{
var input = Enumerable.Range(1, 3);
_ = input.SplitToBatch(-1).ToList();
Assert.ThrowsException<ArgumentOutOfRangeException>(() => input.SplitToBatch(-1).ToList());
}
}
98 changes: 51 additions & 47 deletions tests/LuYao.Common.UnitTests/Collections/Generic/KeyedListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,20 @@ public void Constructor_WithValidKeySelector_CreatesInstance()
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]


public void Constructor_WithNullKeySelector_ThrowsArgumentNullException()


{
// Arrange & Act
var keyedList = new KeyedList<int, TestItem>(null!);

// Assert: 期望抛出 ArgumentNullException

// Arrange, Act & Assert


Assert.ThrowsException<ArgumentNullException>(() => new KeyedList<int, TestItem>(null!));


}

#endregion
Expand All @@ -87,13 +94,20 @@ public void Indexer_GetWithValidIndex_ReturnsCorrectItem()
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]


public void Indexer_GetWithInvalidIndex_ThrowsArgumentOutOfRangeException()


{
// Arrange & Act
var item = _keyedList[-1];

// Assert: 期望抛出 ArgumentOutOfRangeException

// Arrange, Act & Assert


Assert.ThrowsException<ArgumentOutOfRangeException>(() => _keyedList[-1]);


}

[TestMethod]
Expand All @@ -110,16 +124,27 @@ public void Indexer_SetWithValidIndex_UpdatesItem()
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]


public void Indexer_SetWithInvalidIndex_ThrowsArgumentOutOfRangeException()


{


// Arrange


var newItem = new TestItem { Id = 10, Name = "New Item" };

// Act
_keyedList[10] = newItem;

// Assert: 期望抛出 ArgumentOutOfRangeException

// Act & Assert


Assert.ThrowsException<ArgumentOutOfRangeException>(() => _keyedList[10] = newItem);


}

#endregion
Expand Down Expand Up @@ -375,39 +400,30 @@ public void CopyTo_ValidArrayWithOffset_CopiesItemsWithOffset()
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void CopyTo_NullArray_ThrowsArgumentNullException()
{
// Arrange & Act
_keyedList.CopyTo(null!, 0);

// Assert: 期望抛出 ArgumentNullException
// Arrange, Act & Assert
Assert.ThrowsException<ArgumentNullException>(() => _keyedList.CopyTo(null!, 0));
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void CopyTo_NegativeArrayIndex_ThrowsArgumentOutOfRangeException()
{
// Arrange
var array = new TestItem[_keyedList.Count];

// Act
_keyedList.CopyTo(array, -1);

// Assert: 期望抛出 ArgumentOutOfRangeException
// Act & Assert
Assert.ThrowsException<ArgumentOutOfRangeException>(() => _keyedList.CopyTo(array, -1));
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void CopyTo_InsufficientArraySpace_ThrowsArgumentException()
{
// Arrange
var array = new TestItem[_keyedList.Count - 1];

// Act
_keyedList.CopyTo(array, 0);

// Assert: 期望抛出 ArgumentException
// Act & Assert
Assert.ThrowsException<ArgumentException>(() => _keyedList.CopyTo(array, 0));
}

#endregion
Expand Down Expand Up @@ -482,29 +498,23 @@ public void Insert_ValidIndex_InsertsItemAtCorrectPosition()
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Insert_NegativeIndex_ThrowsArgumentOutOfRangeException()
{
// Arrange
var newItem = new TestItem { Id = 4, Name = "Item 4" };

// Act
_keyedList.Insert(-1, newItem);

// Assert: 期望抛出 ArgumentOutOfRangeException
// Act & Assert
Assert.ThrowsException<ArgumentOutOfRangeException>(() => _keyedList.Insert(-1, newItem));
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Insert_IndexGreaterThanCount_ThrowsArgumentOutOfRangeException()
{
// Arrange
var newItem = new TestItem { Id = 4, Name = "Item 4" };

// Act
_keyedList.Insert(_keyedList.Count + 1, newItem);

// Assert: 期望抛出 ArgumentOutOfRangeException
// Act & Assert
Assert.ThrowsException<ArgumentOutOfRangeException>(() => _keyedList.Insert(_keyedList.Count + 1, newItem));
}

#endregion
Expand Down Expand Up @@ -562,23 +572,17 @@ public void RemoveAt_ValidIndex_RemovesItemAtIndex()
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void RemoveAt_NegativeIndex_ThrowsArgumentOutOfRangeException()
{
// Act
_keyedList.RemoveAt(-1);

// Assert: 期望抛出 ArgumentOutOfRangeException
// Act & Assert
Assert.ThrowsException<ArgumentOutOfRangeException>(() => _keyedList.RemoveAt(-1));
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void RemoveAt_IndexEqualToCount_ThrowsArgumentOutOfRangeException()
{
// Act
_keyedList.RemoveAt(_keyedList.Count);

// Assert: 期望抛出 ArgumentOutOfRangeException
// Act & Assert
Assert.ThrowsException<ArgumentOutOfRangeException>(() => _keyedList.RemoveAt(_keyedList.Count));
}

#endregion
Expand Down
15 changes: 6 additions & 9 deletions tests/LuYao.Common.UnitTests/Data/RecordObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@ public void Add_ValidObject_ShouldCreateColumnsAndAddRow()
/// 测试 Add 方法传入 null 对象时抛出异常
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void Add_NullObject_ShouldThrowArgumentNullException()
{
// Arrange
var record = new Record();

// Act
record.Add<TestModel>(null!);
// Act & Assert
Assert.ThrowsException<ArgumentNullException>(() => record.Add<TestModel>(null!));
}

/// <summary>
Expand Down Expand Up @@ -154,11 +153,10 @@ public void From_SingleObject_ShouldCreateRecordWithData()
/// 测试 From 方法传入 null 对象时抛出异常
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void From_SingleObject_Null_ShouldThrowArgumentNullException()
{
// Act
Record.From<TestModel>((TestModel)null!);
// Act & Assert
Assert.ThrowsException<ArgumentNullException>(() => Record.From<TestModel>((TestModel)null!));
}

/// <summary>
Expand Down Expand Up @@ -297,11 +295,10 @@ public void From_CollectionWithNulls_ShouldSkipNullItems()
/// 测试 From 方法传入 null 集合时抛出异常
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void From_NullCollection_ShouldThrowArgumentNullException()
{
// Act
Record.FromList<TestModel>((TestModel[])null!);
// Act & Assert
Assert.ThrowsException<ArgumentNullException>(() => Record.FromList<TestModel>((TestModel[])null!));
}

#endregion
Expand Down
6 changes: 2 additions & 4 deletions tests/LuYao.Common.UnitTests/Data/RecordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,27 +1007,25 @@ public void BoundaryCheck_EmptyTable_IndexGreaterThanZeroThrowsException()
}

[TestMethod]
[ExpectedException(typeof(DuplicateNameException))]
public void Columns_AddDuplicateName_ThrowsException()
{
// Arrange
var table = new Record();
table.Columns.Add<String>("TestColumn");

// Act & Assert
table.Columns.Add<String>("TestColumn"); // 应该抛出异常
Assert.ThrowsException<DuplicateNameException>(() => table.Columns.Add<String>("TestColumn")); // 应该抛出异常
}

[TestMethod]
[ExpectedException(typeof(DuplicateNameException))]
public void Columns_AddDuplicateNameDifferentType_ThrowsException()
{
// Arrange
var table = new Record();
table.Columns.Add<String>("TestColumn");

// Act & Assert
table.Columns.Add<Int32>("TestColumn"); // 应该抛出异常
Assert.ThrowsException<DuplicateNameException>(() => table.Columns.Add<Int32>("TestColumn")); // 应该抛出异常
}

public class Student
Expand Down
6 changes: 2 additions & 4 deletions tests/LuYao.Common.UnitTests/Encoders/Base16Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,17 @@ public void FromBase16_EmptyString_ReturnsEmptyArray()
}

[TestMethod]
[ExpectedException(typeof(FormatException))]
public void FromBase16_InvalidHex_ThrowsFormatException()
{
string input = "ZZ";
Base16.FromBase16(input);
Assert.ThrowsException<FormatException>(() => Base16.FromBase16(input));
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void FromBase16_OddLength_ThrowsArgumentOutOfRangeException()
{
string input = "ABC";
Base16.FromBase16(input);
Assert.ThrowsException<ArgumentOutOfRangeException>(() => Base16.FromBase16(input));
}
}
}
3 changes: 1 addition & 2 deletions tests/LuYao.Common.UnitTests/Encoders/Base32Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ public void FromBase32_SampleString_ReturnsExpectedBytes()
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void FromBase32_InvalidCharacter_ThrowsArgumentException()
{
Base32.FromBase32("INVALID*");
Assert.ThrowsException<ArgumentException>(() => Base32.FromBase32("INVALID*"));
}

[TestMethod]
Expand Down
Loading