[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M77QPHC2F7YM2SX7QA3PXA28":3,"skill-same:01M77QPHC2F7YM2SX7QA3PXA28":46},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":6,"updatedAt":31,"install":32,"resources":45},"01M77QPHC2F7YM2SX7QA3PXA28","csharp-mstest",null,"Get best practices for MSTest 3.x\u002F4.x unit testing, including modern assertion APIs and data-driven tests","Reihantt6\u002Fsns-myagent","Reihantt6","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F219822095?v=4","01M77KK94PV8B7C2D9XWXNS8DJ","Mohamad Reihan tegar prasetya","01M77KK958QFMTHYXGXFV7KZ79",2,"MIT","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fcsharp-mstest\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\ndescription: \"Get best practices for MSTest 3.x\u002F4.x unit testing, including modern assertion APIs and data-driven tests\"\n---\n# MSTest Best Practices (MSTest 3.x\u002F4.x)\n\nYour goal is to help me write effective unit tests with modern MSTest, using current APIs and best practices.\n\n## Project Setup\n\n- Use a separate test project with naming convention `[ProjectName].Tests`\n- Reference MSTest 3.x+ NuGet packages (includes analyzers)\n- Consider using MSTest.Sdk for simplified project setup\n- Run tests with `dotnet test`\n\n## Test Class Structure\n\n- Use `[TestClass]` attribute for test classes\n- **Seal test classes by default** for performance and design clarity\n- Use `[TestMethod]` for test methods (prefer over `[DataTestMethod]`)\n- Follow Arrange-Act-Assert (AAA) pattern\n- Name tests using pattern `MethodName_Scenario_ExpectedBehavior`\n\n```csharp\n[TestClass]\npublic sealed class CalculatorTests\n{\n    [TestMethod]\n    public void Add_TwoPositiveNumbers_ReturnsSum()\n    {\n        \u002F\u002F Arrange\n        var calculator = new Calculator();\n\n        \u002F\u002F Act\n        var result = calculator.Add(2, 3);\n\n        \u002F\u002F Assert\n        Assert.AreEqual(5, result);\n    }\n}\n```\n\n## Test Lifecycle\n\n- **Prefer constructors over `[TestInitialize]`** - enables `readonly` fields and follows standard C# patterns\n- Use `[TestCleanup]` for cleanup that must run even if test fails\n- Combine constructor with async `[TestInitialize]` when async setup is needed\n\n```csharp\n[TestClass]\npublic sealed class ServiceTests\n{\n    private readonly MyService _service;  \u002F\u002F readonly enabled by constructor\n\n    public ServiceTests()\n    {\n        _service = new MyService();\n    }\n\n    [TestInitialize]\n    public async Task InitAsync()\n    {\n        \u002F\u002F Use for async initialization only\n        await _service.WarmupAsync();\n    }\n\n    [TestCleanup]\n    public void Cleanup() => _service.Reset();\n}\n```\n\n### Execution Order\n\n1. **Assembly Initialization** - `[AssemblyInitialize]` (once per test assembly)\n2. **Class Initialization** - `[ClassInitialize]` (once per test class)\n3. **Test Initialization** (for every test method):\n   1. Constructor\n   2. Set `TestContext` property\n   3. `[TestInitialize]`\n4. **Test Execution** - test method runs\n5. **Test Cleanup** (for every test method):\n   1. `[TestCleanup]`\n   2. `DisposeAsync` (if implemented)\n   3. `Dispose` (if implemented)\n6. **Class Cleanup** - `[ClassCleanup]` (once per test class)\n7. **Assembly Cleanup** - `[AssemblyCleanup]` (once per test assembly)\n\n## Modern Assertion APIs\n\nMSTest provides three assertion classes: `Assert`, `StringAssert`, and `CollectionAssert`.\n\n### Assert Class - Core Assertions\n\n```csharp\n\u002F\u002F Equality\nAssert.AreEqual(expected, actual);\nAssert.AreNotEqual(notExpected, actual);\nAssert.AreSame(expectedObject, actualObject);      \u002F\u002F Reference equality\nAssert.AreNotSame(notExpectedObject, actualObject);\n\n\u002F\u002F Null checks\nAssert.IsNull(value);\nAssert.IsNotNull(value);\n\n\u002F\u002F Boolean\nAssert.IsTrue(condition);\nAssert.IsFalse(condition);\n\n\u002F\u002F Fail\u002FInconclusive\nAssert.Fail(\"Test failed due to...\");\nAssert.Inconclusive(\"Test cannot be completed because...\");\n```\n\n### Exception Testing (Prefer over `[ExpectedException]`)\n\n```csharp\n\u002F\u002F Assert.Throws - matches TException or derived types\nvar ex = Assert.Throws\u003CArgumentException>(() => Method(null));\nAssert.AreEqual(\"Value cannot be null.\", ex.Message);\n\n\u002F\u002F Assert.ThrowsExactly - matches exact type only\nvar ex = Assert.ThrowsExactly\u003CInvalidOperationException>(() => Method());\n\n\u002F\u002F Async versions\nvar ex = await Assert.ThrowsAsync\u003CHttpRequestException>(async () => await client.GetAsync(url));\nvar ex = await Assert.ThrowsExactlyAsync\u003CInvalidOperationException>(async () => await Method());\n```\n\n### Collection Assertions (Assert class)\n\n```csharp\nAssert.Contains(expectedItem, collection);\nAssert.DoesNotContain(unexpectedItem, collection);\nAssert.ContainsSingle(collection);  \u002F\u002F exactly one element\nAssert.HasCount(5, collection);\nAssert.IsEmpty(collection);\nAssert.IsNotEmpty(collection);\n```\n\n### String Assertions (Assert class)\n\n```csharp\nAssert.Contains(\"expected\", actualString);\nAssert.StartsWith(\"prefix\", actualString);\nAssert.EndsWith(\"suffix\", actualString);\nAssert.DoesNotStartWith(\"prefix\", actualString);\nAssert.DoesNotEndWith(\"suffix\", actualString);\nAssert.MatchesRegex(@\"\\d{3}-\\d{4}\", phoneNumber);\nAssert.DoesNotMatchRegex(@\"\\d+\", textOnly);\n```\n\n### Comparison Assertions\n\n```csharp\nAssert.IsGreaterThan(lowerBound, actual);\nAssert.IsGreaterThanOrEqualTo(lowerBound, actual);\nAssert.IsLessThan(upperBound, actual);\nAssert.IsLessThanOrEqualTo(upperBound, actual);\nAssert.IsInRange(actual, low, high);\nAssert.IsPositive(number);\nAssert.IsNegative(number);\n```\n\n### Type Assertions\n\n```csharp\n\u002F\u002F MSTest 3.x - uses out parameter\nAssert.IsInstanceOfType\u003CMyClass>(obj, out var typed);\ntyped.DoSomething();\n\n\u002F\u002F MSTest 4.x - returns typed result directly\nvar typed = Assert.IsInstanceOfType\u003CMyClass>(obj);\ntyped.DoSomething();\n\nAssert.IsNotInstanceOfType\u003CWrongType>(obj);\n```\n\n### Assert.That (MSTest 4.0+)\n\n```csharp\nAssert.That(result.Count > 0);  \u002F\u002F Auto-captures expression in failure message\n```\n\n### StringAssert Class\n\n> **Note:** Prefer `Assert` class equivalents when available (e.g., `Assert.Contains(\"expected\", actual)` over `StringAssert.Contains(actual, \"expected\")`).\n\n```csharp\nStringAssert.Contains(actualString, \"expected\");\nStringAssert.StartsWith(actualString, \"prefix\");\nStringAssert.EndsWith(actualString, \"suffix\");\nStringAssert.Matches(actualString, new Regex(@\"\\d{3}-\\d{4}\"));\nStringAssert.DoesNotMatch(actualString, new Regex(@\"\\d+\"));\n```\n\n### CollectionAssert Class\n\n> **Note:** Prefer `Assert` class equivalents when available (e.g., `Assert.Contains`).\n\n```csharp\n\u002F\u002F Containment\nCollectionAssert.Contains(collection, expectedItem);\nCollectionAssert.DoesNotContain(collection, unexpectedItem);\n\n\u002F\u002F Equality (same elements, same order)\nCollectionAssert.AreEqual(expectedCollection, actualCollection);\nCollectionAssert.AreNotEqual(unexpectedCollection, actualCollection);\n\n\u002F\u002F Equivalence (same elements, any order)\nCollectionAssert.AreEquivalent(expectedCollection, actualCollection);\nCollectionAssert.AreNotEquivalent(unexpectedCollection, actualCollection);\n\n\u002F\u002F Subset checks\nCollectionAssert.IsSubsetOf(subset, superset);\nCollectionAssert.IsNotSubsetOf(notSubset, collection);\n\n\u002F\u002F Element validation\nCollectionAssert.AllItemsAreInstancesOfType(collection, typeof(MyClass));\nCollectionAssert.AllItemsAreNotNull(collection);\nCollectionAssert.AllItemsAreUnique(collection);\n```\n\n## Data-Driven Tests\n\n### DataRow\n\n```csharp\n[TestMethod]\n[DataRow(1, 2, 3)]\n[DataRow(0, 0, 0, DisplayName = \"Zeros\")]\n[DataRow(-1, 1, 0, IgnoreMessage = \"Known issue #123\")]  \u002F\u002F MSTest 3.8+\npublic void Add_ReturnsSum(int a, int b, int expected)\n{\n    Assert.AreEqual(expected, Calculator.Add(a, b));\n}\n```\n\n### DynamicData\n\nThe data source can return any of the following types:\n\n- `IEnumerable\u003C(T1, T2, ...)>` (ValueTuple) - **preferred**, provides type safety (MSTest 3.7+)\n- `IEnumerable\u003CTuple\u003CT1, T2, ...>>` - provides type safety\n- `IEnumerable\u003CTestDataRow>` - provides type safety plus control over test metadata (display name, categories)\n- `IEnumerable\u003Cobject[]>` - **least preferred**, no type safety\n\n> **Note:** When creating new test data methods, prefer `ValueTuple` or `TestDataRow` over `IEnumerable\u003Cobject[]>`. The `object[]` approach provides no compile-time type checking and can lead to runtime errors from type mismatches.\n\n```csharp\n[TestMethod]\n[DynamicData(nameof(TestData))]\npublic void DynamicTest(int a, int b, int expected)\n{\n    Assert.AreEqual(expected, Calculator.Add(a, b));\n}\n\n\u002F\u002F ValueTuple - preferred (MSTest 3.7+)\npublic static IEnumerable\u003C(int a, int b, int expected)> TestData =>\n[\n    (1, 2, 3),\n    (0, 0, 0),\n];\n\n\u002F\u002F TestDataRow - when you need custom display names or metadata\npublic static IEnumerable\u003CTestDataRow\u003C(int a, int b, int expected)>> TestDataWithMetadata =>\n[\n    new((1, 2, 3)) { DisplayName = \"Positive numbers\" },\n    new((0, 0, 0)) { DisplayName = \"Zeros\" },\n    new((-1, 1, 0)) { DisplayName = \"Mixed signs\", IgnoreMessage = \"Known issue #123\" },\n];\n\n\u002F\u002F IEnumerable\u003Cobject[]> - avoid for new code (no type safety)\npublic static IEnumerable\u003Cobject[]> LegacyTestData =>\n[\n    [1, 2, 3],\n    [0, 0, 0],\n];\n```\n\n## TestContext\n\nThe `TestContext` class provides test run information, cancellation support, and output methods.\nSee [TestContext documentation](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fcore\u002Ftesting\u002Funit-testing-mstest-writing-tests-testcontext) for complete reference.\n\n### Accessing TestContext\n\n```csharp\n\u002F\u002F Property (MSTest suppresses CS8618 - don't use nullable or = null!)\npublic TestContext TestContext { get; set; }\n\n\u002F\u002F Constructor injection (MSTest 3.6+) - preferred for immutability\n[TestClass]\npublic sealed class MyTests\n{\n    private readonly TestContext _testContext;\n\n    public MyTests(TestContext testContext)\n    {\n        _testContext = testContext;\n    }\n}\n\n\u002F\u002F Static methods receive it as parameter\n[ClassInitialize]\npublic static void ClassInit(TestContext context) { }\n\n\u002F\u002F Optional for cleanup methods (MSTest 3.6+)\n[ClassCleanup]\npublic static void ClassCleanup(TestContext context) { }\n\n[AssemblyCleanup]\npublic static void AssemblyCleanup(TestContext context) { }\n```\n\n### Cancellation Token\n\nAlways use `TestContext.CancellationToken` for cooperative cancellation with `[Timeout]`:\n\n```csharp\n[TestMethod]\n[Timeout(5000)]\npublic async Task LongRunningTest()\n{\n    await _httpClient.GetAsync(url, TestContext.CancellationToken);\n}\n```\n\n### Test Run Properties\n\n```csharp\nTestContext.TestName              \u002F\u002F Current test method name\nTestContext.TestDisplayName       \u002F\u002F Display name (3.7+)\nTestContext.CurrentTestOutcome    \u002F\u002F Pass\u002FFail\u002FInProgress\nTestContext.TestData              \u002F\u002F Parameterized test data (3.7+, in TestInitialize\u002FCleanup)\nTestContext.TestException         \u002F\u002F Exception if test failed (3.7+, in TestCleanup)\nTestContext.DeploymentDirectory   \u002F\u002F Directory with deployment items\n```\n\n### Output and Result Files\n\n```csharp\n\u002F\u002F Write to test output (useful for debugging)\nTestContext.WriteLine(\"Processing item {0}\", itemId);\n\n\u002F\u002F Attach files to test results (logs, screenshots)\nTestContext.AddResultFile(screenshotPath);\n\n\u002F\u002F Store\u002Fretrieve data across test methods\nTestContext.Properties[\"SharedKey\"] = computedValue;\n```\n\n## Advanced Features\n\n### Retry for Flaky Tests (MSTest 3.9+)\n\n```csharp\n[TestMethod]\n[Retry(3)]\npublic void FlakyTest() { }\n```\n\n### Conditional Execution (MSTest 3.10+)\n\nSkip or run tests based on OS or CI environment:\n\n```csharp\n\u002F\u002F OS-specific tests\n[TestMethod]\n[OSCondition(OperatingSystems.Windows)]\npublic void WindowsOnlyTest() { }\n\n[TestMethod]\n[OSCondition(OperatingSystems.Linux | OperatingSystems.MacOS)]\npublic void UnixOnlyTest() { }\n\n[TestMethod]\n[OSCondition(ConditionMode.Exclude, OperatingSystems.Windows)]\npublic void SkipOnWindowsTest() { }\n\n\u002F\u002F CI environment tests\n[TestMethod]\n[CICondition]  \u002F\u002F Runs only in CI (default: ConditionMode.Include)\npublic void CIOnlyTest() { }\n\n[TestMethod]\n[CICondition(ConditionMode.Exclude)]  \u002F\u002F Skips in CI, runs locally\npublic void LocalOnlyTest() { }\n```\n\n### Parallelization\n\n```csharp\n\u002F\u002F Assembly level\n[assembly: Parallelize(Workers = 4, Scope = ExecutionScope.MethodLevel)]\n\n\u002F\u002F Disable for specific class\n[TestClass]\n[DoNotParallelize]\npublic sealed class SequentialTests { }\n```\n\n### Work Item Traceability (MSTest 3.8+)\n\nLink tests to work items for traceability in test reports:\n\n```csharp\n\u002F\u002F Azure DevOps work items\n[TestMethod]\n[WorkItem(12345)]  \u002F\u002F Links to work item #12345\npublic void Feature_Scenario_ExpectedBehavior() { }\n\n\u002F\u002F Multiple work items\n[TestMethod]\n[WorkItem(12345)]\n[WorkItem(67890)]\npublic void Feature_CoversMultipleRequirements() { }\n\n\u002F\u002F GitHub issues (MSTest 3.8+)\n[TestMethod]\n[GitHubWorkItem(\"https:\u002F\u002Fgithub.com\u002Fowner\u002Frepo\u002Fissues\u002F42\")]\npublic void BugFix_Issue42_IsResolved() { }\n```\n\nWork item associations appear in test results and can be used for:\n- Tracing test coverage to requirements\n- Linking bug fixes to regression tests\n- Generating traceability reports in CI\u002FCD pipelines\n\n## Common Mistakes to Avoid\n\n```csharp\n\u002F\u002F ❌ Wrong argument order\nAssert.AreEqual(actual, expected);\n\u002F\u002F ✅ Correct\nAssert.AreEqual(expected, actual);\n\n\u002F\u002F ❌ Using ExpectedException (obsolete)\n[ExpectedException(typeof(ArgumentException))]\n\u002F\u002F ✅ Use Assert.Throws\nAssert.Throws\u003CArgumentException>(() => Method());\n\n\u002F\u002F ❌ Using LINQ Single() - unclear exception\nvar item = items.Single();\n\u002F\u002F ✅ Use ContainsSingle - better failure message\nvar item = Assert.ContainsSingle(items);\n\n\u002F\u002F ❌ Hard cast - unclear exception\nvar handler = (MyHandler)result;\n\u002F\u002F ✅ Type assertion - shows actual type on failure\nvar handler = Assert.IsInstanceOfType\u003CMyHandler>(result);\n\n\u002F\u002F ❌ Ignoring cancellation token\nawait client.GetAsync(url, CancellationToken.None);\n\u002F\u002F ✅ Flow test cancellation\nawait client.GetAsync(url, TestContext.CancellationToken);\n\n\u002F\u002F ❌ Making TestContext nullable - leads to unnecessary null checks\npublic TestContext? TestContext { get; set; }\n\u002F\u002F ❌ Using null! - MSTest already suppresses CS8618 for this property\npublic TestContext TestContext { get; set; } = null!;\n\u002F\u002F ✅ Declare without nullable or initializer - MSTest handles the warning\npublic TestContext TestContext { get; set; }\n```\n\n## Test Organization\n\n- Group tests by feature or component\n- Use `[TestCategory(\"Category\")]` for filtering\n- Use `[TestProperty(\"Name\", \"Value\")]` for custom metadata (e.g., `[TestProperty(\"Bug\", \"12345\")]`)\n- Use `[Priority(1)]` for critical tests\n- Enable relevant MSTest analyzers (MSTEST0020 for constructor preference)\n\n## Mocking and Isolation\n\n- Use Moq or NSubstitute for mocking dependencies\n- Use interfaces to facilitate mocking\n- Mock dependencies to isolate units under test\n","# MSTest Best Practices (MSTest 3.x\u002F4.x)\n\nYour goal is to help me write effective unit tests with modern MSTest, using current APIs and best practices.\n\n## Project Setup\n\n- Use a separate test project with naming convention `[ProjectName].Tests`\n- Reference MSTest 3.x+ NuGet packages (includes analyzers)\n- Consider using MSTest.Sdk for simplified project setup\n- Run tests with `dotnet test`\n\n## Test Class Structure\n\n- Use `[TestClass]` attribute for test classes\n- **Seal test classes by default** for performance and design clarity\n- Use `[TestMethod]` for test methods (prefer over `[DataTestMethod]`)\n- Follow Arrange-Act-Assert (AAA) pattern\n- Name tests using pattern `MethodName_Scenario_ExpectedBehavior`\n\n```csharp\n[TestClass]\npublic sealed class CalculatorTests\n{\n    [TestMethod]\n    public void Add_TwoPositiveNumbers_ReturnsSum()\n    {\n        \u002F\u002F Arrange\n        var calculator = new Calculator();\n\n        \u002F\u002F Act\n        var result = calculator.Add(2, 3);\n\n        \u002F\u002F Assert\n        Assert.AreEqual(5, result);\n    }\n}\n```\n\n## Test Lifecycle\n\n- **Prefer constructors over `[TestInitialize]`** - enables `readonly` fields and follows standard C# patterns\n- Use `[TestCleanup]` for cleanup that must run even if test fails\n- Combine constructor with async `[TestInitialize]` when async setup is needed\n\n```csharp\n[TestClass]\npublic sealed class ServiceTests\n{\n    private readonly MyService _service;  \u002F\u002F readonly enabled by constructor\n\n    public ServiceTests()\n    {\n        _service = new MyService();\n    }\n\n    [TestInitialize]\n    public async Task InitAsync()\n    {\n        \u002F\u002F Use for async initialization only\n        await _service.WarmupAsync();\n    }\n\n    [TestCleanup]\n    public void Cleanup() => _service.Reset();\n}\n```\n\n### Execution Order\n\n1. **Assembly Initialization** - `[AssemblyInitialize]` (once per test assembly)\n2. **Class Initialization** - `[ClassInitialize]` (once per test class)\n3. **Test Initialization** (for every test method):\n   1. Constructor\n   2. Set `TestContext` property\n   3. `[TestInitialize]`\n4. **Test Execution** - test method runs\n5. **Test Cleanup** (for every test method):\n   1. `[TestCleanup]`\n   2. `DisposeAsync` (if implemented)\n   3. `Dispose` (if implemented)\n6. **Class Cleanup** - `[ClassCleanup]` (once per test class)\n7. **Assembly Cleanup** - `[AssemblyCleanup]` (once per test assembly)\n\n## Modern Assertion APIs\n\nMSTest provides three assertion classes: `Assert`, `StringAssert`, and `CollectionAssert`.\n\n### Assert Class - Core Assertions\n\n```csharp\n\u002F\u002F Equality\nAssert.AreEqual(expected, actual);\nAssert.AreNotEqual(notExpected, actual);\nAssert.AreSame(expectedObject, actualObject);      \u002F\u002F Reference equality\nAssert.AreNotSame(notExpectedObject, actualObject);\n\n\u002F\u002F Null checks\nAssert.IsNull(value);\nAssert.IsNotNull(value);\n\n\u002F\u002F Boolean\nAssert.IsTrue(condition);\nAssert.IsFalse(condition);\n\n\u002F\u002F Fail\u002FInconclusive\nAssert.Fail(\"Test failed due to...\");\nAssert.Inconclusive(\"Test cannot be completed because...\");\n```\n\n### Exception Testing (Prefer over `[ExpectedException]`)\n\n```csharp\n\u002F\u002F Assert.Throws - matches TException or derived types\nvar ex = Assert.Throws\u003CArgumentException>(() => Method(null));\nAssert.AreEqual(\"Value cannot be null.\", ex.Message);\n\n\u002F\u002F Assert.ThrowsExactly - matches exact type only\nvar ex = Assert.ThrowsExactly\u003CInvalidOperationException>(() => Method());\n\n\u002F\u002F Async versions\nvar ex = await Assert.ThrowsAsync\u003CHttpRequestException>(async () => await client.GetAsync(url));\nvar ex = await Assert.ThrowsExactlyAsync\u003CInvalidOperationException>(async () => await Method());\n```\n\n### Collection Assertions (Assert class)\n\n```csharp\nAssert.Contains(expectedItem, collection);\nAssert.DoesNotContain(unexpectedItem, collection);\nAssert.ContainsSingle(collection);  \u002F\u002F exactly one element\nAssert.HasCount(5, collection);\nAssert.IsEmpty(collection);\nAssert.IsNotEmpty(collection);\n```\n\n### String Assertions (Assert class)\n\n```csharp\nAssert.Contains(\"expected\", actualString);\nAssert.StartsWith(\"prefix\", actualString);\nAssert.EndsWith(\"suffix\", actualString);\nAssert.DoesNotStartWith(\"prefix\", actualString);\nAssert.DoesNotEndWith(\"suffix\", actualString);\nAssert.MatchesRegex(@\"\\d{3}-\\d{4}\", phoneNumber);\nAssert.DoesNotMatchRegex(@\"\\d+\", textOnly);\n```\n\n### Comparison Assertions\n\n```csharp\nAssert.IsGreaterThan(lowerBound, actual);\nAssert.IsGreaterThanOrEqualTo(lowerBound, actual);\nAssert.IsLessThan(upperBound, actual);\nAssert.IsLessThanOrEqualTo(upperBound, actual);\nAssert.IsInRange(actual, low, high);\nAssert.IsPositive(number);\nAssert.IsNegative(number);\n```\n\n### Type Assertions\n\n```csharp\n\u002F\u002F MSTest 3.x - uses out parameter\nAssert.IsInstanceOfType\u003CMyClass>(obj, out var typed);\ntyped.DoSomething();\n\n\u002F\u002F MSTest 4.x - returns typed result directly\nvar typed = Assert.IsInstanceOfType\u003CMyClass>(obj);\ntyped.DoSomething();\n\nAssert.IsNotInstanceOfType\u003CWrongType>(obj);\n```\n\n### Assert.That (MSTest 4.0+)\n\n```csharp\nAssert.That(result.Count > 0);  \u002F\u002F Auto-captures expression in failure message\n```\n\n### StringAssert Class\n\n> **Note:** Prefer `Assert` class equivalents when available (e.g., `Assert.Contains(\"expected\", actual)` over `StringAssert.Contains(actual, \"expected\")`).\n\n```csharp\nStringAssert.Contains(actualString, \"expected\");\nStringAssert.StartsWith(actualString, \"prefix\");\nStringAssert.EndsWith(actualString, \"suffix\");\nStringAssert.Matches(actualString, new Regex(@\"\\d{3}-\\d{4}\"));\nStringAssert.DoesNotMatch(actualString, new Regex(@\"\\d+\"));\n```\n\n### CollectionAssert Class\n\n> **Note:** Prefer `Assert` class equivalents when available (e.g., `Assert.Contains`).\n\n```csharp\n\u002F\u002F Containment\nCollectionAssert.Contains(collection, expectedItem);\nCollectionAssert.DoesNotContain(collection, unexpectedItem);\n\n\u002F\u002F Equality (same elements, same order)\nCollectionAssert.AreEqual(expectedCollection, actualCollection);\nCollectionAssert.AreNotEqual(unexpectedCollection, actualCollection);\n\n\u002F\u002F Equivalence (same elements, any order)\nCollectionAssert.AreEquivalent(expectedCollection, actualCollection);\nCollectionAssert.AreNotEquivalent(unexpectedCollection, actualCollection);\n\n\u002F\u002F Subset checks\nCollectionAssert.IsSubsetOf(subset, superset);\nCollectionAssert.IsNotSubsetOf(notSubset, collection);\n\n\u002F\u002F Element validation\nCollectionAssert.AllItemsAreInstancesOfType(collection, typeof(MyClass));\nCollectionAssert.AllItemsAreNotNull(collection);\nCollectionAssert.AllItemsAreUnique(collection);\n```\n\n## Data-Driven Tests\n\n### DataRow\n\n```csharp\n[TestMethod]\n[DataRow(1, 2, 3)]\n[DataRow(0, 0, 0, DisplayName = \"Zeros\")]\n[DataRow(-1, 1, 0, IgnoreMessage = \"Known issue #123\")]  \u002F\u002F MSTest 3.8+\npublic void Add_ReturnsSum(int a, int b, int expected)\n{\n    Assert.AreEqual(expected, Calculator.Add(a, b));\n}\n```\n\n### DynamicData\n\nThe data source can return any of the following types:\n\n- `IEnumerable\u003C(T1, T2, ...)>` (ValueTuple) - **preferred**, provides type safety (MSTest 3.7+)\n- `IEnumerable\u003CTuple\u003CT1, T2, ...>>` - provides type safety\n- `IEnumerable\u003CTestDataRow>` - provides type safety plus control over test metadata (display name, categories)\n- `IEnumerable\u003Cobject[]>` - **least preferred**, no type safety\n\n> **Note:** When creating new test data methods, prefer `ValueTuple` or `TestDataRow` over `IEnumerable\u003Cobject[]>`. The `object[]` approach provides no compile-time type checking and can lead to runtime errors from type mismatches.\n\n```csharp\n[TestMethod]\n[DynamicData(nameof(TestData))]\npublic void DynamicTest(int a, int b, int expected)\n{\n    Assert.AreEqual(expected, Calculator.Add(a, b));\n}\n\n\u002F\u002F ValueTuple - preferred (MSTest 3.7+)\npublic static IEnumerable\u003C(int a, int b, int expected)> TestData =>\n[\n    (1, 2, 3),\n    (0, 0, 0),\n];\n\n\u002F\u002F TestDataRow - when you need custom display names or metadata\npublic static IEnumerable\u003CTestDataRow\u003C(int a, int b, int expected)>> TestDataWithMetadata =>\n[\n    new((1, 2, 3)) { DisplayName = \"Positive numbers\" },\n    new((0, 0, 0)) { DisplayName = \"Zeros\" },\n    new((-1, 1, 0)) { DisplayName = \"Mixed signs\", IgnoreMessage = \"Known issue #123\" },\n];\n\n\u002F\u002F IEnumerable\u003Cobject[]> - avoid for new code (no type safety)\npublic static IEnumerable\u003Cobject[]> LegacyTestData =>\n[\n    [1, 2, 3],\n    [0, 0, 0],\n];\n```\n\n## TestContext\n\nThe `TestContext` class provides test run information, cancellation support, and output methods.\nSee [TestContext documentation](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fcore\u002Ftesting\u002Funit-testing-mstest-writing-tests-testcontext) for complete reference.\n\n### Accessing TestContext\n\n```csharp\n\u002F\u002F Property (MSTest suppresses CS8618 - don't use nullable or = null!)\npublic TestContext TestContext { get; set; }\n\n\u002F\u002F Constructor injection (MSTest 3.6+) - preferred for immutability\n[TestClass]\npublic sealed class MyTests\n{\n    private readonly TestContext _testContext;\n\n    public MyTests(TestContext testContext)\n    {\n        _testContext = testContext;\n    }\n}\n\n\u002F\u002F Static methods receive it as parameter\n[ClassInitialize]\npublic static void ClassInit(TestContext context) { }\n\n\u002F\u002F Optional for cleanup methods (MSTest 3.6+)\n[ClassCleanup]\npublic static void ClassCleanup(TestContext context) { }\n\n[AssemblyCleanup]\npublic static void AssemblyCleanup(TestContext context) { }\n```\n\n### Cancellation Token\n\nAlways use `TestContext.CancellationToken` for cooperative cancellation with `[Timeout]`:\n\n```csharp\n[TestMethod]\n[Timeout(5000)]\npublic async Task LongRunningTest()\n{\n    await _httpClient.GetAsync(url, TestContext.CancellationToken);\n}\n```\n\n### Test Run Properties\n\n```csharp\nTestContext.TestName              \u002F\u002F Current test method name\nTestContext.TestDisplayName       \u002F\u002F Display name (3.7+)\nTestContext.CurrentTestOutcome    \u002F\u002F Pass\u002FFail\u002FInProgress\nTestContext.TestData              \u002F\u002F Parameterized test data (3.7+, in TestInitialize\u002FCleanup)\nTestContext.TestException         \u002F\u002F Exception if test failed (3.7+, in TestCleanup)\nTestContext.DeploymentDirectory   \u002F\u002F Directory with deployment items\n```\n\n### Output and Result Files\n\n```csharp\n\u002F\u002F Write to test output (useful for debugging)\nTestContext.WriteLine(\"Processing item {0}\", itemId);\n\n\u002F\u002F Attach files to test results (logs, screenshots)\nTestContext.AddResultFile(screenshotPath);\n\n\u002F\u002F Store\u002Fretrieve data across test methods\nTestContext.Properties[\"SharedKey\"] = computedValue;\n```\n\n## Advanced Features\n\n### Retry for Flaky Tests (MSTest 3.9+)\n\n```csharp\n[TestMethod]\n[Retry(3)]\npublic void FlakyTest() { }\n```\n\n### Conditional Execution (MSTest 3.10+)\n\nSkip or run tests based on OS or CI environment:\n\n```csharp\n\u002F\u002F OS-specific tests\n[TestMethod]\n[OSCondition(OperatingSystems.Windows)]\npublic void WindowsOnlyTest() { }\n\n[TestMethod]\n[OSCondition(OperatingSystems.Linux | OperatingSystems.MacOS)]\npublic void UnixOnlyTest() { }\n\n[TestMethod]\n[OSCondition(ConditionMode.Exclude, OperatingSystems.Windows)]\npublic void SkipOnWindowsTest() { }\n\n\u002F\u002F CI environment tests\n[TestMethod]\n[CICondition]  \u002F\u002F Runs only in CI (default: ConditionMode.Include)\npublic void CIOnlyTest() { }\n\n[TestMethod]\n[CICondition(ConditionMode.Exclude)]  \u002F\u002F Skips in CI, runs locally\npublic void LocalOnlyTest() { }\n```\n\n### Parallelization\n\n```csharp\n\u002F\u002F Assembly level\n[assembly: Parallelize(Workers = 4, Scope = ExecutionScope.MethodLevel)]\n\n\u002F\u002F Disable for specific class\n[TestClass]\n[DoNotParallelize]\npublic sealed class SequentialTests { }\n```\n\n### Work Item Traceability (MSTest 3.8+)\n\nLink tests to work items for traceability in test reports:\n\n```csharp\n\u002F\u002F Azure DevOps work items\n[TestMethod]\n[WorkItem(12345)]  \u002F\u002F Links to work item #12345\npublic void Feature_Scenario_ExpectedBehavior() { }\n\n\u002F\u002F Multiple work items\n[TestMethod]\n[WorkItem(12345)]\n[WorkItem(67890)]\npublic void Feature_CoversMultipleRequirements() { }\n\n\u002F\u002F GitHub issues (MSTest 3.8+)\n[TestMethod]\n[GitHubWorkItem(\"https:\u002F\u002Fgithub.com\u002Fowner\u002Frepo\u002Fissues\u002F42\")]\npublic void BugFix_Issue42_IsResolved() { }\n```\n\nWork item associations appear in test results and can be used for:\n- Tracing test coverage to requirements\n- Linking bug fixes to regression tests\n- Generating traceability reports in CI\u002FCD pipelines\n\n## Common Mistakes to Avoid\n\n```csharp\n\u002F\u002F ❌ Wrong argument order\nAssert.AreEqual(actual, expected);\n\u002F\u002F ✅ Correct\nAssert.AreEqual(expected, actual);\n\n\u002F\u002F ❌ Using ExpectedException (obsolete)\n[ExpectedException(typeof(ArgumentException))]\n\u002F\u002F ✅ Use Assert.Throws\nAssert.Throws\u003CArgumentException>(() => Method());\n\n\u002F\u002F ❌ Using LINQ Single() - unclear exception\nvar item = items.Single();\n\u002F\u002F ✅ Use ContainsSingle - better failure message\nvar item = Assert.ContainsSingle(items);\n\n\u002F\u002F ❌ Hard cast - unclear exception\nvar handler = (MyHandler)result;\n\u002F\u002F ✅ Type assertion - shows actual type on failure\nvar handler = Assert.IsInstanceOfType\u003CMyHandler>(result);\n\n\u002F\u002F ❌ Ignoring cancellation token\nawait client.GetAsync(url, CancellationToken.None);\n\u002F\u002F ✅ Flow test cancellation\nawait client.GetAsync(url, TestContext.CancellationToken);\n\n\u002F\u002F ❌ Making TestContext nullable - leads to unnecessary null checks\npublic TestContext? TestContext { get; set; }\n\u002F\u002F ❌ Using null! - MSTest already suppresses CS8618 for this property\npublic TestContext TestContext { get; set; } = null!;\n\u002F\u002F ✅ Declare without nullable or initializer - MSTest handles the warning\npublic TestContext TestContext { get; set; }\n```\n\n## Test Organization\n\n- Group tests by feature or component\n- Use `[TestCategory(\"Category\")]` for filtering\n- Use `[TestProperty(\"Name\", \"Value\")]` for custom metadata (e.g., `[TestProperty(\"Bug\", \"12345\")]`)\n- Use `[Priority(1)]` for critical tests\n- Enable relevant MSTest analyzers (MSTEST0020 for constructor preference)\n\n## Mocking and Isolation\n\n- Use Moq or NSubstitute for mocking dependencies\n- Use interfaces to facilitate mocking\n- Mock dependencies to isolate units under test\n",{"description":7},"main","58843b159d7a4050d6b785a98b908cce505c0b92","agent\u002Fskills\u002Fcsharp-mstest",0,"https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent","https:\u002F\u002Fgithub.com\u002FReihantt6","reihsns.web.id","2026-08-19 20:08:18",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add Reihantt6\u002Fsns-myagent --skill csharp-mstest",{"tool":38,"command":39},"bunx","bunx skills add Reihantt6\u002Fsns-myagent --skill csharp-mstest",{"tool":41,"command":42},"pnpm","pnpm dlx skills add Reihantt6\u002Fsns-myagent --skill csharp-mstest","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fcsharp-mstest\u002FSKILL.md",true,[],[47,54,61,68,75,82],{"skillNo":48,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":51,"categories":52,"keywords":53,"publishedAt":19},"01M77XDCYZ407XYMF2T4P6F7VT","youtube-transcript","Extract transcripts from YouTube videos. Use when the user asks for a transcript, subtitles, or captions of a YouTube video and provides a YouTube URL (youtube.com\u002Fwatch?v=, youtu.be\u002F, or similar). Supports output with or without timestamps.","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fyoutube-transcript\u002FSKILL.md",[],[],{"skillNo":55,"name":56,"nameZh":6,"description":57,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":19},"01M77XD7PBC98J6MXGJJ2TJ8DX","youtube-thumbnail-design","YouTube thumbnail design with specific dimensions, contrast rules, and mobile preview optimization. Covers safe zones, text placement, face expression psychology, and A\u002FB testing. Use for: YouTube thumbnails, video cover images, click-through optimization. Triggers: youtube thumbnail, thumbnail design, video thumbnail, click through rate, ctr optimization, youtube cover, video cover image, thumbnail maker, thumbnail tips, youtube design, video preview image","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fyoutube-thumbnail-design\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M77XD2541C8HXJ6RHYZP4NGJ","youtube-short-maker","Make YouTube Shorts that hold attention with Pexo — vertical 9:16, fast-paced, hook in the first 3 seconds. Describe your topic and Pexo writes the script, generates the shots, picks the models, and assembles a finished Short with music and captions. Use for YouTube Shorts: \"youtube short\", \"make a youtube short\", \"shorts video\", \"short-form video\". NOT for long-form or landscape video.","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fyoutube-short-maker\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M77XCXKVSYK7KTZ3PQBVVGFD","xcode-project-setup","Safely modifies Xcode projects (.pbxproj) to add Swift Packages and link files. Use this skill whenever an iOS project needs dependencies installed (e.g. Firebase, Alamofire).","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fxcode-project-setup\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M77XCR1DV8ZQK2NHWKVY4EWX","x402","Set up Browser Use Cloud payments with x402 — pay per request from a crypto wallet (USDC on Base mainnet), no signup or API key. Two setups it works out up front — \"just use it\" (set up a wallet so you or Claude Code can run cloud browser tasks paid from the wallet — Claude writes and runs throwaway scripts, nothing touches your codebase) or \"build it in\" (install the SDK and write the key + code into your project). Walks through wallet setup, funding, .env, and a ~$1 test run. Use when the user asks about x402, pay-per-use, USDC payments, or wants Browser Use Cloud without an API key. For the free-tier signup (reverse-CAPTCHA → API key), use `browser-use cloud signup` or the `cloud` skill instead.","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fx402\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M77XCMD3R3ZBZQQSW6E0793B","x-twitter-scraper","Build GitHub Copilot workflows with Xquik X API SDKs, REST endpoints, hosted Apify Actor runs, MCP tools, TweetClaw OpenClaw plugin installs, signed webhooks, tweet search, user lookup, follower exports, media actions, and agent automation.","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fx-twitter-scraper\u002FSKILL.md",[],[]]