{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "89b24a9e-61c9-4d4d-8b58-d65a3738439e",
   "metadata": {},
   "source": [
    "# Lab: Exceptions, Debugging & Testing\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5aea8c82-ac28-433e-98e5-25f883d51ff7",
   "metadata": {},
   "source": [
    "Practice exercises for try/catch/finally, debugging workflows, and unit testing.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aaa54721",
   "metadata": {},
   "source": [
    "## Your Tasks\n",
    "\n",
    "1. Implement this unit testing project.\n",
    "2. Add one method in the application and one corresponding test in the test project.\n",
    "3. As usual, prepare the assignment using a Word document with screenshots (code and execution with path\n",
    "   and username) and your annotations.\n",
    "\n",
    "## Preparing Project\n",
    "\n",
    "The idea of TDD is to write tests first, so that you will be focused with the requirements and not\n",
    "to be distracted by your own coding. That's why we start with simple test cases in the test project to test the\n",
    "units in the application project. After you make sure the application tests can pass, you then improve the\n",
    "units (methods, classes) in the application project.\n",
    "\n",
    "The process of creating a unit test involves several steps:\n",
    "\n",
    "1. Create a lab folder, call it `Ch13SelectedTopicsLab`, inside `[USERNAME]\\workspace\\introcscs\\`.\n",
    "\n",
    "2. Create a solution folder:\n",
    "\n",
    "   1. Inside Ch13SelectedTopicsLab, create a folder `UnitTestProject1` and run:\n",
    "\n",
    "      ```bash\n",
    "      dotnet new sln\n",
    "      ```\n",
    "\n",
    "   2. To open the solution in VS Code: `View` → `Command Palette` → `.NET: Open Solution`.\n",
    "\n",
    "3. Create an **application project** folder `MathApp`, and a **test project** folder `MathAppTest` inside UnitTestProject1.\n",
    "\n",
    "4. Initialize them:\n",
    "\n",
    "   ```bash\n",
    "   cd MathApp && dotnet new console\n",
    "   cd ../MathAppTest && dotnet new mstest\n",
    "   ```\n",
    "\n",
    "5. Add both to the solution and link them:\n",
    "\n",
    "   ```bash\n",
    "   dotnet sln add MathApp\n",
    "   dotnet sln add MathAppTest\n",
    "   dotnet add MathAppTest reference MathApp\n",
    "   ```\n",
    "\n",
    "## Preparing Code\n",
    "\n",
    "Revise `Program.cs` in MathApp with a `BasicMath` class containing 4 arithmetic methods,\n",
    "and revise `UnitTest1.cs` in MathAppTest with corresponding `[TestMethod]` test methods.\n",
    "Run `dotnet test` inside UnitTestProject1 to verify.\n",
    "\n",
    "## Run Testing in VS Code\n",
    "\n",
    "You can also run tests visually using the C# Dev Kit extension — build the test project in\n",
    "Test Explorer to make tests appear in the Activity Bar's Testing section.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0009a238-5263-433a-922a-84216123aa6c",
   "metadata": {},
   "source": [
    "```{rubric} Footnotes\n",
    "```\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".NET (C#)",
   "language": "C#",
   "name": ".net-csharp"
  },
  "language_info": {
   "name": "polyglot-notebook"
  },
  "polyglot_notebook": {
   "kernelInfo": {
    "defaultKernelName": "csharp",
    "items": [
     {
      "aliases": [],
      "name": "csharp"
     }
    ]
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
