© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
10 replies
Rhys

Unit testing not working, doesn't hit multiple test classes

The first test class runs perfectly fine, but the second one doesnt even get hit. I cant debug or set any breakpoints as nothing is hit.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VehicleInspection_Domain.Interfaces;
using Moq;
using Microsoft.AspNetCore.Mvc;
using VehicleInspection_Domain.Models.AbstractModels;
using Newtonsoft.Json;

namespace VehicleInspection_Test
{
    [TestClass]
    public class VehicleInspectionTesting
    {
        private readonly IEmailRepository _emailRepository;

        public VehicleInspectionTesting(IEmailRepository emailRepository)
        {
            _emailRepository = emailRepository;
        }

        [TestMethod]
        public async Task Insepction_ReturnOkResult_AndSendsEmailOnMajorDefect()
        {
            string jsonData = @"
            {
                *** SOME DATA ***
            }";

            // Mock dependencies
            var emailRepositoryMock = new Mock<IEmailRepository>();
            var inspectionService = new VehicleInspectionTesting(emailRepositoryMock.Object);

            // Act
            var result = await inspectionService.ProcessInspection(jsonData);

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkResult));

            // Verify that SendCriticalDefectEmail was called when major defects exist
            emailRepositoryMock.Verify(x => x.SendCriticalDefectEmail(It.IsAny<string>(), It.IsAny<int>()), Times.Once);
        }
    }
}
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VehicleInspection_Domain.Interfaces;
using Moq;
using Microsoft.AspNetCore.Mvc;
using VehicleInspection_Domain.Models.AbstractModels;
using Newtonsoft.Json;

namespace VehicleInspection_Test
{
    [TestClass]
    public class VehicleInspectionTesting
    {
        private readonly IEmailRepository _emailRepository;

        public VehicleInspectionTesting(IEmailRepository emailRepository)
        {
            _emailRepository = emailRepository;
        }

        [TestMethod]
        public async Task Insepction_ReturnOkResult_AndSendsEmailOnMajorDefect()
        {
            string jsonData = @"
            {
                *** SOME DATA ***
            }";

            // Mock dependencies
            var emailRepositoryMock = new Mock<IEmailRepository>();
            var inspectionService = new VehicleInspectionTesting(emailRepositoryMock.Object);

            // Act
            var result = await inspectionService.ProcessInspection(jsonData);

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkResult));

            // Verify that SendCriticalDefectEmail was called when major defects exist
            emailRepositoryMock.Verify(x => x.SendCriticalDefectEmail(It.IsAny<string>(), It.IsAny<int>()), Times.Once);
        }
    }
}

https://gyazo.com/d591331eb72b053113bf56111c719a94
Gyazo
Gyazo
Gyazo
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Unit Test not working.
C#CC# / help
4y ago
✅ Unit Testing in Rider not working
C#CC# / help
17mo ago
MassTransit unit test does not hit breakpoint in consumer
C#CC# / help
2y ago
unit testing
C#CC# / help
2y ago