{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "edc14eea-d9ee-40db-8cc6-e0c866c96176",
   "metadata": {},
   "source": [
    "# Preview Questions\n",
    "\n",
    "Complete these questions **before** class to prepare for the chapter.\n",
    "Use the dropdowns to check your answers.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67d6379a-33c1-4e19-b71c-4e03d74d2a0d",
   "metadata": {},
   "source": [
    "## True or False\n",
    "\n",
    "**1.** A `try` block must always be paired with a `catch` block.\n",
    "\n",
    "```{dropdown} Answer\n",
    "**False** — `try` can be paired with `finally` alone, without `catch`.\n",
    "```\n",
    "\n",
    "**2.** A `finally` block executes only when an exception is thrown.\n",
    "\n",
    "```{dropdown} Answer\n",
    "**False** — `finally` always runs — whether an exception occurred or not.\n",
    "```\n",
    "\n",
    "**3.** Catching `Exception` (the base type) is best practice for all error handling.\n",
    "\n",
    "```{dropdown} Answer\n",
    "**False** — Catching specific exception types gives more control and clearer intent.\n",
    "```\n",
    "\n",
    "**4.** A `NullReferenceException` occurs when you access a member on a null reference.\n",
    "\n",
    "```{dropdown} Answer\n",
    "**True** — Calling a method or property on a null object throws this exception.\n",
    "```\n",
    "\n",
    "**5.** Breakpoints pause program execution at a specific line during debugging.\n",
    "\n",
    "```{dropdown} Answer\n",
    "**True** — Breakpoints let you inspect program state at exact points in the code.\n",
    "```\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ade3b0e5-c0cc-4732-b4ed-61606497b379",
   "metadata": {},
   "source": [
    "## Multiple Choice\n",
    "\n",
    "**1.** Which keyword manually throws an exception in C#?\n",
    "\n",
    "a) raise  \n",
    "b) error  \n",
    "c) throw  \n",
    "d) except\n",
    "\n",
    "```{dropdown} Answer\n",
    "**c) throw** — `throw new ExceptionType()` raises an exception programmatically.\n",
    "```\n",
    "\n",
    "**2.** Which block always executes regardless of whether an exception was thrown?\n",
    "\n",
    "a) try  \n",
    "b) catch  \n",
    "c) finally  \n",
    "d) else\n",
    "\n",
    "```{dropdown} Answer\n",
    "**c) finally** — `finally` is guaranteed to run — ideal for cleanup code.\n",
    "```\n",
    "\n",
    "**3.** What exception is thrown when dividing an integer by zero?\n",
    "\n",
    "a) ArithmeticException  \n",
    "b) DivideByZeroException  \n",
    "c) ZeroException  \n",
    "d) MathException\n",
    "\n",
    "```{dropdown} Answer\n",
    "**b) DivideByZeroException** — `DivideByZeroException` is thrown for integer division by zero.\n",
    "```\n",
    "\n",
    "**4.** Best practice for exception handling is to:\n",
    "\n",
    "a) Always catch `Exception` to handle everything  \n",
    "b) Avoid try/catch entirely  \n",
    "c) Catch the most specific exception type possible  \n",
    "d) Re-throw every exception\n",
    "\n",
    "```{dropdown} Answer\n",
    "**c) Catch the most specific exception type possible** — Specific catches make error handling intentional and easier to debug.\n",
    "```\n",
    "\n",
    "**5.** During debugging in VS Code, which panel shows variable values at a breakpoint?\n",
    "\n",
    "a) Terminal  \n",
    "b) Variables panel in the Run & Debug view  \n",
    "c) Source Control panel  \n",
    "d) Extensions panel\n",
    "\n",
    "```{dropdown} Answer\n",
    "**b) Variables panel in the Run & Debug view** — The Variables pane in the Run & Debug view shows current values.\n",
    "```\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0cbe9dab-23f9-40c7-b6c8-6a0400992b02",
   "metadata": {},
   "source": [
    "```{rubric} Footnotes\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49030556",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "## Unit Testing — True or False\n",
    "\n",
    "**1.** A unit test should test multiple units of code together to save time.\n",
    "\n",
    "```{dropdown} Answer\n",
    "**False** — Unit tests test one small, isolated piece of functionality.\n",
    "```\n",
    "\n",
    "**2.** `Assert.AreEqual(expected, actual)` checks whether two values are the same.\n",
    "\n",
    "```{dropdown} Answer\n",
    "**True** — If the values differ, the assertion fails and the test is marked as failed.\n",
    "```\n",
    "\n",
    "**3.** Test-Driven Development (TDD) means writing tests after the code is complete.\n",
    "\n",
    "```{dropdown} Answer\n",
    "**False** — In TDD you write the test first, then write code to make it pass.\n",
    "```\n",
    "\n",
    "**4.** An MSTest test method is marked with the `[TestMethod]` attribute.\n",
    "\n",
    "```{dropdown} Answer\n",
    "**True** — `[TestMethod]` marks a test method in MSTest; `[Fact]` is used in xUnit.\n",
    "```\n",
    "\n",
    "**5.** A test that always passes regardless of the implementation is a useful test.\n",
    "\n",
    "```{dropdown} Answer\n",
    "**False** — A test must be able to fail to be meaningful.\n",
    "```\n",
    "\n",
    "## Unit Testing — Multiple Choice\n",
    "\n",
    "**1.** What is the main purpose of a unit test?\n",
    "\n",
    "a) Test the full application end-to-end  \n",
    "b) Test one small, isolated piece of code  \n",
    "c) Test the user interface  \n",
    "d) Test network connectivity\n",
    "\n",
    "```{dropdown} Answer\n",
    "**b) Test one small, isolated piece of code** — Unit tests isolate a single method or behavior to verify correctness.\n",
    "```\n",
    "\n",
    "**2.** Which attribute marks a test method in MSTest?\n",
    "\n",
    "a) [Test]  \n",
    "b) [Fact]  \n",
    "c) [TestMethod]  \n",
    "d) [Check]\n",
    "\n",
    "```{dropdown} Answer\n",
    "**c) [TestMethod]** — `[TestMethod]` is MSTest's attribute; `[Fact]` belongs to xUnit.\n",
    "```\n",
    "\n",
    "**3.** What does a failing test indicate?\n",
    "\n",
    "a) The test framework is broken  \n",
    "b) The code does not meet the stated expectation  \n",
    "c) The test should be deleted  \n",
    "d) Nothing important\n",
    "\n",
    "```{dropdown} Answer\n",
    "**b) The code does not meet the stated expectation** — A failing test reveals a discrepancy between expected and actual behavior.\n",
    "```\n",
    "\n",
    "**4.** Which MSTest method verifies that a specific exception is thrown?\n",
    "\n",
    "a) Assert.IsTrue()  \n",
    "b) Assert.ThrowsException\\<T>()  \n",
    "c) Assert.Fails()  \n",
    "d) Assert.Catch\\<T>()\n",
    "\n",
    "```{dropdown} Answer\n",
    "**b) Assert.ThrowsException\\<T>()** — Passes only if the code block throws exception type T.\n",
    "```\n",
    "\n",
    "**5.** The Red-Green-Refactor cycle in TDD means:\n",
    "\n",
    "a) Test passes, code fails, then you refactor  \n",
    "b) Write a failing test, make it pass, then clean up the code  \n",
    "c) Write code, test it, then delete the tests  \n",
    "d) Run tests in red mode for performance\n",
    "\n",
    "```{dropdown} Answer\n",
    "**b) Write a failing test, make it pass, then clean up the code** — Red = failing test, Green = minimal code to pass, Refactor = clean up.\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
}
