mercredi 20 janvier 2021

TestMethod Not running in c#

I have the following test class:

using System;
using DDDSample1.Domain.DriverDuties;
using DDDSample1.Domain.Shared;
using DDDSample1.Controllers;
using System.Collections.Generic;
using Moq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace IntegrationTests
{
    public class DriverDutyControllerTest
    {
        [TestMethod]
        public async void GetByIdTest()
        {
            var repo = new Mock<IDriverDutyRepository>();
            var unitOfWork = new Mock<IUnitOfWork>();

            var service = new DriverDutyService(unitOfWork.Object, repo.Object);
            var controller = new DriverDutiesController(service);

            DriverDutyId id = new DriverDutyId("id1");
            string key = "keyDD1";
            string driver = "DriverDD";
            List<String> workblocks = new List<String>();
            workblocks.Add("wb1");
            workblocks.Add("wb2");
            workblocks.Add("wb3");

            var ddDto = new CreatingDriverDutyDto(key, driver, workblocks.ToArray());
            var dd = new DriverDuty(key, driver, workblocks);

            repo.Setup(_ => _.AddAsync(dd)).ReturnsAsync(dd);

            var actual = await controller.GetGetById(id.AsGuid());

            Console.WriteLine(actual.Value);

            Assert.IsTrue(true);
        }
    }
}

And I an running it in Visual Studio Code, but whenever I run the test GetByIdTest() I get the following output:

----- Running test method "IntegrationTests.DriverDutyControllerTest.GetByIdTest" -----

Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  DDDNetCore -> z:\Git\projeto_integrador_grupo67\mdv\bin\Debug\netcoreapp5.0\DDDNetCore.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.71


----- Test Execution Summary -----

Total tests: 0. Passed: 0. Failed: 0. Skipped: 0

Why does my test get skipped? Any ideas on how to solve it?

NOTE: I am developing IntegrationTesting between layers (in this case controllers and services) so I need to mock these layers since I don't want to hit the database.

Aucun commentaire:

Enregistrer un commentaire