Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 15, 2025

The course creation feature lacked test coverage despite having full implementation in place (entities, DTOs, services, validators, and API endpoints).

Changes

Test Infrastructure

  • Added CourseRegistration.Application.Tests with xUnit, Moq, FluentAssertions
  • Added CourseRegistration.API.Tests with Microsoft.AspNetCore.Mvc.Testing
  • Made Program class accessible via partial declaration for integration testing

Unit Tests (11 tests)

CourseService.CreateCourseAsync (6 tests)

  • Valid creation flow with mapper and repository mocks
  • Date validation: start date future constraint, end date ordering
  • Edge cases: equal dates, optional fields, GUID generation

CreateCourseDtoValidator (5 tests)

  • FluentValidation rules: required fields, length constraints, date logic
  • Course duration constraints (7-365 days)

Integration Tests (4 tests)

POST /api/courses

  • Happy path returns 201 with location header
  • Invalid dates return 400 via service-layer validation
  • Response format validation with JSON deserialization

Example

[Fact]
public async Task CreateCourseAsync_WithStartDateInPast_ShouldThrowInvalidOperationException()
{
    var createCourseDto = new CreateCourseDto
    {
        StartDate = DateTime.UtcNow.AddDays(-5), // Past date
        EndDate = DateTime.UtcNow.AddDays(30),
        // ... other fields
    };

    var exception = await Assert.ThrowsAsync<InvalidOperationException>(
        () => _courseService.CreateCourseAsync(createCourseDto));
    
    exception.Message.Should().Contain("must be in the future");
    _mockCourseRepository.Verify(r => r.AddAsync(It.IsAny<Course>()), Times.Never);
}

All 15 tests passing. CodeQL scan clean.

Original prompt

create a new issue for add course feature

The user has attached the following file paths as relevant context:

  • .github\instructions\agents.md.instructions.md
  • .github\instructions\dotnet-dev.instructions.md

Created from VS Code via the GitHub Pull Request extension.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 15, 2025 13:38
Co-authored-by: Hemavathi15sg <224925058+Hemavathi15sg@users.noreply.github.com>
Co-authored-by: Hemavathi15sg <224925058+Hemavathi15sg@users.noreply.github.com>
Copilot AI changed the title [WIP] Add course feature to application Add comprehensive test coverage for course creation feature Nov 15, 2025
Copilot AI requested a review from Hemavathi15sg November 15, 2025 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants