1

Note > The number of records in the Country Table: 36 records.

My code :

[TestFixture]
    public class CountriesControllerTest
    {
        Mock<IJN_CountryRepository> countryRepository;
        Mock<IUnitOfWork> unitOfWork;

        IJN_CountryService countryService;

        [SetUp]
        public void SetUp()
        {
            countryRepository = new Mock<IJN_CountryRepository>();
            unitOfWork = new Mock<IUnitOfWork>();
            countryService = new JN_CountryService(countryRepository.Object, unitOfWork.Object);
        }
        [Test]
        public void ManyDelete()
        {
            var count = countryService.GetCount();
            // Assert
            Assert.AreEqual(36, count);
        }
    }

NUnit Test Message :

enter image description here

Why? Why not read the number of records?

k.m
  • 30,794
  • 10
  • 62
  • 86
Football-Is-My-Life
  • 1,407
  • 7
  • 18
  • 35

1 Answers1

0

With these two lines

countryRepository = new Mock<IJN_CountryRepository>();
unitOfWork = new Mock<IUnitOfWork>();

you created a fake objects, objects that have no logic nor any knowledge about any databases. These are mocks. You need to instruct them what to do in order to make them work, like:

var sampleCountries = Create36SampleCountries();
countryRepository = new Mock<IJN_CountryRepository>();
countryRepository.Setup(m => m.Countries).Returns(sampleCountries);

In order for your test to work with real database you should not be using mocks but your actual repositories (note that this would then be an integration test).

k.m
  • 30,794
  • 10
  • 62
  • 86