I am using IUmbracoDatabaseFactory for checking the database health of the application and I would like to add unit tests to it.
How do I mock the IUmbracoDatabaseFactory configuration, please?
The test example code:
public virtual SampleHealthController healthController => new SampleHealthController(Mock.Of<ILogger<SampleHealthController>>(), Mock.Of<IUmbracoDatabaseFactory>()
[Test]
public void WhenCheckDB_ThenReturnDatabaseUp()
{
var result = healthController.CheckDB();
Assert.AreEqual("Up", result);
}
var iLoggerMock = new Mock<ILogger<HealthController>>();
var databaseFactoryMock = new Mock<IUmbracoDatabaseFactory>();
//Simulates the database Up
databaseFactoryMock.Setup(x => x.CanConnect).Returns(true);
var healthController = new HealthController(iLoggerMock.Object, databaseFactoryMock.Object);
var result = healthController.CheckDB();
Assert.AreEqual("Up", result);
How to Mock IUmbracoDatabaseFactory?
Hi everyone. Hope you are doing well.
I am using IUmbracoDatabaseFactory for checking the database health of the application and I would like to add unit tests to it.
How do I mock the IUmbracoDatabaseFactory configuration, please? The test example code:
Just sharing that a solution was found:
is working on a reply...