User1120430333 posted
You are not testing anything all you have done is set-up a mock that is incomplete. You have not set up what you are trying to mock. You are not doing the Actual/Act that executes code the that uses the mocked object. That's why you see the Return(mocked
data) from a mocked object's method, if you were doing the mock properly.
https://docs.telerik.com/devtools/justmock/basic-usage/arrange-act-assert
No matter what unit testing and mocking framework you use, you must follow the basic principles of unit testing and mocking if mocking is needed.
Arrange setup what is need to run the test, like give mocked test data that the mocked method in a mocked object should return, set up the mocked object and method being mocked so that it returns the mocked data.
Act -- Actually run a test using real code, and if the actual code being tested is supposed to execute the mocked object's method to return mocked data, then the mocked object would return the mocked data from the mocked object's method
during real/actual code execution.
Assert- verify that the test acted as expected, which would be the mocked data that returned from the Actual/Act execution of real code.
Actually, you should make the unit test fail, and then you make the unit test pass, which is called the red, green and reactor, which are already doing the red as your test has failed. :)
https://dzone.com/articles/pattern-of-the-month-red-green-refactor
[TestMethod]
public void Test1()
{
var s = new DataHelper(new Mock<ICacheHelper>().Object);
var data = s.GetDashboard("demo");
Assert.IsTrue(data.Name == "demo");
}
}