用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/microsoft-foundry/foundry-agent-webapp --skill writing-unit-tests-csharp命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | writing-unit-tests-csharp |
| description | Guidelines and patterns for writing unit tests in C# using MSTest SDK. |
This skill covers writing unit tests for the backend using MSTest SDK. The project uses a lean, zero-config approach that leverages Microsoft's official SDK-style testing.
backend/
├── WebApp.sln
├── WebApp.Api/
│ ├── Models/ # DTOs and request/response models
│ ├── Services/ # Business logic and agent integration
│ └── Program.cs # Minimal API endpoints
└── WebApp.Api.Tests/
├── WebApp.Api.Tests.csproj
└── [TestClass].cs # Test files organized by class under test
The test project uses MSTest SDK which eliminates the need for explicit package references:
See backend/WebApp.Api.Tests/WebApp.Api.Tests.csproj for current configuration. The project uses MSTest SDK which eliminates the need for explicit package references — just set Sdk="MSTest.Sdk/{version}" in the project element.
using WebApp.Api.Models;
namespace WebApp.Api.Tests;
[TestClass]
public class ErrorResponseFactoryTests
{
[TestMethod]
public void CreateFromException_ReturnsCorrectStatusCode()
{
// Arrange
var exception = new InvalidOperationException("Test");
// Act
var result = ErrorResponseFactory.CreateFromException(exception, 500, isDevelopment: false);
// Assert
Assert.AreEqual(500, result.Status);
}
[TestMethod]
[DataRow(400, "Bad Request")]
[DataRow(401, "Unauthorized")]
[DataRow(500, "Internal Server Error")]
public void CreateFromException_MapsStatusToTitle(int status, string expectedTitle)
{
// Parameterized test using DataRow
}
}
# Run all backend tests
cd backend
dotnet test
# Run with verbose output
dotnet test --verbosity normal
# Run specific test class
dotnet test --filter "FullyQualifiedName~ErrorResponseFactoryTests"
# Run with coverage (requires coverlet)
dotnet test --collect:"XPlat Code Coverage"
| Class | What to Test |
|---|---|
ErrorResponseFactory | Status code mapping, dev vs prod mode, exception detail hiding |
ChatRequest | Validation logic if any |
StreamChunk | Serialization/deserialization |
AnnotationInfo | Property mapping |
| Class | Testing Approach |
|---|---|
AgentFrameworkService | Use validating-ui-features skill with Playwright for integration tests |
Use descriptive names following: MethodName_Scenario_ExpectedBehavior
[TestMethod]
public void CreateFromException_WhenDevelopmentMode_IncludesStackTrace() { }
[TestMethod]
public void CreateFromException_WhenProductionMode_HidesStackTrace() { }
MSTest provides these assertion methods:
// Equality
Assert.AreEqual(expected, actual);
Assert.AreNotEqual(notExpected, actual);
// Nullability
Assert.IsNull(value);
Assert.IsNotNull(value);
// Boolean
Assert.IsTrue(condition);
Assert.IsFalse(condition);
// Type
Assert.IsInstanceOfType(obj, typeof(ExpectedType));
// Collections
CollectionAssert.Contains(collection, element);
CollectionAssert.AreEqual(expected, actual);
// Exceptions
Assert.ThrowsException<InvalidOperationException>(() => MethodThatThrows());
Use the validating-ui-features skill and Playwright when:
| Command | Purpose |
|---|---|
dotnet test | Run all tests |
dotnet test --filter "Name~Test" | Run filtered tests |
dotnet build | Build without running |
dotnet test --list-tests | List all tests |