Skip to content

sarakaros/FinalLab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ§ͺ CheckerApp – HR Web Application Tester

πŸ“˜ Overview

CheckerApp is a companion test project for the main Webapp (Human Resource Management System). It verifies both Intermediary Layer (Services) and Interface Layer (Controllers + Views) to ensure correct data handling, validation, and rendering in the HR management system.

πŸ—οΈ Project Setup

1️⃣ Add the test project to your solution dotnet sln add CheckerApp/CheckerApp.csproj

2️⃣ Add reference to the Webapp project dotnet add CheckerApp reference Webapp/Webapp.csproj

3️⃣ Required packages (if not already installed) dotnet add CheckerApp package Microsoft.NET.Test.Sdk dotnet add CheckerApp package xunit dotnet add CheckerApp package xunit.runner.visualstudio dotnet add CheckerApp package Microsoft.AspNetCore.Mvc.Testing dotnet add CheckerApp package FluentAssertions

🧱 Intermediary Layer (Service)

The service layer represents the intermediary between data and presentation. In this project, we test the logic implemented inside:

File Description

  • IStaffService.cs Defines the contract for staff operations
  • StaffService.cs Implements logic for managing staff data, regex validation, and uniqueness checking
  • Methods to Test
  • Method Description
  • GetStaffList() Returns all staff entries
  • GetStaffById(string id) Finds staff by ID
  • AddNewStaff(Staff staff) Adds new staff and saves to file
  • ValidateEmail(string email) Validates email format using regex
  • ValidatePhone(string phone) Validates phone format using regex
  • IsIdUnique(string id) Ensures staff ID is unique
  • IsEmailUnique(string email) Ensures email is unique
  • IsPhoneUnique(string phone) Ensures phone is unique

πŸ–₯️ Interface Layer (Controller + Views)

This layer includes user-facing pages (Views) and routing logic (Controller).

File

  • Controllers/StaffController.cs (Handles page routing, input validation, and form processing)
  • Views/Staff/Index.cshtml (Displays all staff members)
  • Views/Staff/Details.cshtml (Displays details of a selected staff)
  • Views/Staff/Add.cshtml (Form for adding a new staff member)

🧩 Test Selectors (data-testid attributes)

These attributes are used for UI testing in integration tests:

Index.cshtml (/)

Element Selector Staff card data-testid="staff-card-{id}" Details button data-testid="view-details-button-{id}" Details.cshtml (/StaffDetail/{id})

Element Selector Card container data-testid="staff-details-card" Photo data-testid="staff-photo" Staff ID data-testid="staff-id-display" Name data-testid="staff-name-display" Email data-testid="staff-email-display" Phone data-testid="staff-phone-display" Start Date data-testid="staff-startdate-display" Back button data-testid="back-to-list-button" Add.cshtml (/AddStaff)

Element Selector Staff ID input data-testid="staff-id-input" Name input data-testid="staff-name-input" Email input data-testid="email-input" Phone input data-testid="phone-input" Start date data-testid="start-date-input" Photo URL input data-testid="photo-url-input" Submit button data-testid="submit-button"

πŸ” Regex Validation Test Cases

βœ… ValidateEmail

Pattern:

^[^\s@]+@[^\s@.]+(.[^\s@.]+)+$

Good Cases

test@example.com john.doe@company.co.uk user123@my-server.net test@subdomain.domain.com

Bad Cases

test@gmail test@.com test@@gmail.com test @gmail.com

βœ… ValidatePhone

Pattern:

^(+?[1-9]\d{0,3}[-\s]?)?\d{3}[-\s]?\d{3}[-\s]?\d{4}$

Good Cases

123-456-7890 123 456 7890 1234567890 +1 123 456 7890 +1-123-456-7890 +44 123 456 7890

Bad Cases

(123) 456-7890 1-800-ACBDEF 123-456-789 123 456 78901 +01 123 456 7890

πŸ§ͺ How to Run the Tests

From the project root:

dotnet test

Visual Studio:

Open Test Explorer

Select Run All Tests

πŸ“‚ Project Structure Example MCFinalLab.sln β”‚ β”œβ”€β”€ Webapp/ β”‚ β”œβ”€β”€ Controllers/ β”‚ β”‚ └── StaffController.cs β”‚ β”œβ”€β”€ Models/ β”‚ β”œβ”€β”€ Services/ β”‚ └── Views/ β”‚ └── CheckerApp/ β”œβ”€β”€ Tests/ β”‚ β”œβ”€β”€ ServiceLayerTests.cs β”‚ └── InterfaceLayerTests.cs β”œβ”€β”€ CheckerApp.csproj └── README.md

πŸ’¬ Notes

The CheckerApp ensures that the HR Webapp behaves as expected:

Validates all business logic inside the StaffService

Confirms UI elements render correctly in the Views

Tests both correct and incorrect input cases

About

A test automation project for validating the service and interface layers of an ASP.NET Core Human Resource Management System, covering business logic, input validation, controller actions, and UI rendering through unit and integration tests.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors