-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dotnet AgentId and MetaData tests (#5271)
- Loading branch information
Showing
3 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
dotnet/test/Microsoft.AutoGen.Core.Tests/AgentIdTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// AgentIdTests.cs | ||
using FluentAssertions; | ||
using Microsoft.AutoGen.Contracts; | ||
using Xunit; | ||
|
||
namespace Microsoft.AutoGen.Core.Tests; | ||
|
||
public class AgentIdTests() | ||
{ | ||
[Fact] | ||
public void AgentIdShouldInitializeCorrectlyTest() | ||
{ | ||
var agentId = new AgentId("TestType", "TestKey"); | ||
|
||
agentId.Type.Should().Be("TestType"); | ||
agentId.Key.Should().Be("TestKey"); | ||
} | ||
|
||
[Fact] | ||
public void AgentIdShouldConvertFromTupleTest() | ||
{ | ||
var agentTuple = ("TupleType", "TupleKey"); | ||
var agentId = new AgentId(agentTuple); | ||
|
||
agentId.Type.Should().Be("TupleType"); | ||
agentId.Key.Should().Be("TupleKey"); | ||
} | ||
|
||
[Fact] | ||
public void AgentIdShouldParseFromStringTest() | ||
{ | ||
var agentId = AgentId.FromStr("ParsedType/ParsedKey"); | ||
|
||
agentId.Type.Should().Be("ParsedType"); | ||
agentId.Key.Should().Be("ParsedKey"); | ||
} | ||
|
||
[Fact] | ||
public void AgentIdShouldCompareEqualityCorrectlyTest() | ||
{ | ||
var agentId1 = new AgentId("SameType", "SameKey"); | ||
var agentId2 = new AgentId("SameType", "SameKey"); | ||
var agentId3 = new AgentId("DifferentType", "DifferentKey"); | ||
|
||
agentId1.Should().Be(agentId2); | ||
agentId1.Should().NotBe(agentId3); | ||
(agentId1 == agentId2).Should().BeTrue(); | ||
(agentId1 != agentId3).Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void AgentIdShouldGenerateCorrectHashCodeTest() | ||
{ | ||
var agentId1 = new AgentId("HashType", "HashKey"); | ||
var agentId2 = new AgentId("HashType", "HashKey"); | ||
var agentId3 = new AgentId("DifferentType", "DifferentKey"); | ||
|
||
agentId1.GetHashCode().Should().Be(agentId2.GetHashCode()); | ||
agentId1.GetHashCode().Should().NotBe(agentId3.GetHashCode()); | ||
} | ||
|
||
[Fact] | ||
public void AgentIdShouldConvertExplicitlyFromStringTest() | ||
{ | ||
var agentId = (AgentId)"ConvertedType/ConvertedKey"; | ||
|
||
agentId.Type.Should().Be("ConvertedType"); | ||
agentId.Key.Should().Be("ConvertedKey"); | ||
} | ||
|
||
[Fact] | ||
public void AgentIdShouldReturnCorrectToStringTest() | ||
{ | ||
var agentId = new AgentId("ToStringType", "ToStringKey"); | ||
|
||
agentId.ToString().Should().Be("ToStringType/ToStringKey"); | ||
} | ||
|
||
[Fact] | ||
public void AgentIdShouldCompareInequalityCorrectlyTest() | ||
{ | ||
var agentId1 = new AgentId("Type1", "Key1"); | ||
var agentId2 = new AgentId("Type2", "Key2"); | ||
|
||
(agentId1 != agentId2).Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void AgentIdShouldRejectInvalidNamesTest() | ||
{ | ||
// Invalid: 'Type' cannot start with a number and must only contain a-z, 0-9, or underscores. | ||
Action invalidType = () => new AgentId("123InvalidType", "ValidKey"); | ||
invalidType.Should().Throw<ArgumentException>("Agent type cannot start with a number and must only contain alphanumeric letters or underscores."); | ||
|
||
Action invalidTypeWithSpaces = () => new AgentId("Invalid Type", "ValidKey"); | ||
invalidTypeWithSpaces.Should().Throw<ArgumentException>("Agent type cannot contain spaces."); | ||
|
||
Action invalidTypeWithSpecialChars = () => new AgentId("Invalid@Type", "ValidKey"); | ||
invalidTypeWithSpecialChars.Should().Throw<ArgumentException>("Agent type cannot contain special characters."); | ||
|
||
// Invalid: 'Key' must contain only ASCII characters 32 (space) to 126 (~). | ||
Action invalidKey = () => new AgentId("ValidType", "InvalidKey💀"); | ||
invalidKey.Should().Throw<ArgumentException>("Agent key must only contain ASCII characters between 32 (space) and 126 (~)."); | ||
|
||
Action validCase = () => new AgentId("Valid_Type", "Valid_Key_123"); | ||
validCase.Should().NotThrow("This is a correctly formatted AgentId."); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
dotnet/test/Microsoft.AutoGen.Core.Tests/AgentMetaDataTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// AgentMetaDataTests.cs | ||
using FluentAssertions; | ||
using Microsoft.AutoGen.Contracts; | ||
using Xunit; | ||
|
||
namespace Microsoft.AutoGen.Core.Tests; | ||
|
||
public class AgentMetadataTests() | ||
{ | ||
[Fact] | ||
public void AgentMetadataShouldInitializeCorrectlyTest() | ||
{ | ||
var metadata = new AgentMetadata("TestType", "TestKey", "TestDescription"); | ||
|
||
metadata.Type.Should().Be("TestType"); | ||
metadata.Key.Should().Be("TestKey"); | ||
metadata.Description.Should().Be("TestDescription"); | ||
} | ||
} |