Hi I would really be happy if someone can help me with unit testing this business logic on Visual Studio unit test..
I've google"ed" and checked different ways of unit testing but i keep finding the unit test for controllers which i dont need.. i'd be most happy if this method can be unit tested for me. Thanks
This is my Business class
public void AddConsultation(ConsultationView cv, int patientid)
{
using (var deprepo = new ConsultationRepository())
{
if (cv.ConsultId == 0)
{
var curr = DateTime.Now;
string date = curr.ToString("d");
string time= curr.ToString("t");
var patient = da.Patients.ToList().Find(x => x.PatientId == patientid);
Consultation _consultation = new Consultation
{
ConsultId = cv.ConsultId,
ConsultDate = date,
ConsultTime = time,
illness = cv.illness,
PresribedMed = cv.PresribedMed,
Symptoms = cv.Symptoms,
U_Id = patient.PatientId,
};
deprepo.Insert(_consultation);
}
}
}
#endregion
This is my Repository Class
public class ConsultationRepository:IConsultationRepository
{
private DataContext _datacontext = null;
private readonly IRepository<Consultation> _clinicRepository;
public ConsultationRepository()
{
_datacontext = new DataContext();
_clinicRepository = new RepositoryService<Consultation>(_datacontext);
}
public Consultation GetById(int id)
{
return _clinicRepository.GetById(id);
}
public List<Consultation> GetAll()
{
return _clinicRepository.GetAll().ToList();
}
public void Insert(Consultation model)
{
_clinicRepository.Insert(model);
}
public void Update(Consultation model)
{
_clinicRepository.Update(model);
}
public void Delete(Consultation model)
{
_clinicRepository.Delete(model);
}
public IEnumerable<Consultation> Find(Func<Consultation, bool> predicate)
{
return _clinicRepository.Find(predicate).ToList();
}
public void Dispose()
{
_datacontext.Dispose();
_datacontext = null;
}
}
Aucun commentaire:
Enregistrer un commentaire