Install-Package NUnit 
Install-Package NUnit3TestAdapter 
Install-Package Moq 
Install-Package Microsoft.NET.Test.Sdk 


// make a slide why?
Option A: Start with ContactRepository tests (mock DbContext)
Option B: Start with a Service layer (easier to test with mocked repositories)

I recommend Option B - Create a ContactService that uses IContactRepository, then test the service by mocking the repository.

// make a slide for common test fixtures
Core Test Attributes:
[TestFixture]
csharp[TestFixture]
public class ContactServiceTests
{
    // Test class - marks this as a test container
}
[Test]
csharp[Test]
public async Task GetAllContacts_ReturnsAllContacts()
{
    // Single test method
}
[TestCase]
csharp[TestCase("")]
[TestCase(null)]
[TestCase("   ")]
public void AddContact_InvalidEmail_ThrowsException(string email)
{
    // Parameterized test - runs once per TestCase
}
[SetUp]
csharp[SetUp]
public void SetUp()
{
    // Runs BEFORE each test
    _mockRepository = new Mock<IContactRepository>();
    _service = new ContactService(_mockRepository.Object);
}
[TearDown]
csharp[TearDown]
public void TearDown()
{
    // Runs AFTER each test
    _service?.Dispose();
}
[OneTimeSetUp]
csharp[OneTimeSetUp]
public void OneTimeSetUp()
{
    // Runs ONCE before all tests in class
}
[OneTimeTearDown]
csharp[OneTimeTearDown]
public void OneTimeTearDown()
{
    // Runs ONCE after all tests in class
}


-----------
1. ContactService.cs (Service Layer)
Location: Services/ContactService.cs
Features:

Business logic layer
Input validation
Duplicate email checking
Uses IContactRepository (easily mockable)
IDisposable implementation

Key Methods:

GetAllContactsAsync()
GetContactByIdAsync()
CreateContactAsync() - with validation
UpdateContactAsync()
DeleteContactAsync()
SearchContactsAsync()
GetFavoriteContactsAsync()
ToggleFavoriteAsync()

2. ContactServiceTests.cs (Test Project)
Location: ContactManagementSystem.Tests/ContactServiceTests.cs
Test Structure:
csharp[SetUp]  // Fresh mocks before each test
[TearDown]  // Cleanup after each test ✓
[Test]  // Individual tests
[TestCase]  // Parameterized tests
Tests Included (19 tests):

✓ GetAllContactsAsync (2 tests)
✓ GetContactByIdAsync (4 tests with TestCase)
✓ CreateContactAsync (4 tests including parameterized)
✓ UpdateContactAsync (2 tests)
✓ DeleteContactAsync (2 tests)
✓ SearchContactsAsync (2 tests with TestCase)
✓ GetFavoriteContactsAsync (1 test)
✓ ToggleFavoriteAsync (2 tests)
✓ ValidateContact (2 tests)

TearDown in action:
csharp[TearDown]
public void TearDown()
{
    _service?.Dispose();
    _mockRepository = null;
    _testContacts = null;
}
Runs after EVERY test for cleanup!

----- Run the Tests -----
Run Tests in Visual Studio:
Method 1: Test Explorer (Recommended)

Open Test Explorer:

Go to: Test → Test Explorer (or press Ctrl+E, T)


Build the solution:

Press Ctrl+Shift+B


Run tests:

Click Run All button in Test Explorer
Or right-click test → Run



Method 2: Right-Click Method

Right-click on test method or test class
Select Run Tests

Method 3: Keyboard Shortcut

Ctrl+R, A - Run all tests
Ctrl+R, T - Run tests in current context

What You Should See:
Test Explorer window shows:

✅ Green checkmark = Test passed
❌ Red X = Test failed
Total: 19 tests (if all pass)

Tests grouped by:

ContactServiceTests

GetAllContactsAsync Tests (2)
GetContactByIdAsync Tests (4)
CreateContactAsync Tests (4)
etc.

----- Project Reference add ----
You need to add a project reference from your test project to your main project.
Fix:

Right-click on ContactManagementSystem.Tests project
Select Add → Project Reference...
Check the box next to ContactManagementSystem
Click OK