I want to test in my MVC app if I can create an object using xUnit. The create method in my repository looks like this:
public bool Create(Patient model)
{
try {
_db.patients.Add(model);
saveChanges();
return true
} catch {
return false;
}
}
public int saveChanges() {
return db.SaveChanges();
}
My test currently looks like this:
public void CanCreatePatient() {
using(var mock = AutoMock.GetLoose())
{
mock.Mock<IPatientRepo>().Setup(x => x.Create(GetSamplePatient()));
mock.Mock<IPatientRepo>().Setup(x => x.saveChanges()),Returns(1);
var cls = mock.Mock.Create<IPatientRepo>();
var actual = cls.Create(GetSamplePatient());
Assert.True(actual);
}
}
Im fairly new to xUnit and testing in dotnet. Currently this test always fails because the actual returns false. What can I do to solve this issue?