Unit Testing Interfaces with Moq

joe11

New Member
I'm new to Moq and unit testing. I have been doing a unit test and this is the following code:\[code\]private Mock<IServiceAdapter> repository; [TestInitialize] public void Initialize() { repository= new Mock<IServiceAdapter>(); }[TestMethod()] public void SaveTest() { //Setup string Name = "Name1"; string Type = "1"; string parentID = null; repository.Setup(x => x.Save(Name , Type, parentID)).Returns("Success").Verifiable(); //Do var result = repository.Object.Save(Name , Type, parentID); //Assert repository.Verify(); }\[/code\]My problem is that the test will always return the string that I put in the Returns parameter, in other words, it will always return "success" or whatever I write in its place. I guess thats not right because thats not the real behavior of the service. Anyone knows how I can mirror the real behavior of the "Save" service I'm trying to test? So lets say, if the return string is different from the service method,then the test should fail.
 
Back
Top