public string InsertTa(Ta ta) { var errors = new List<string>(); var repository = new TaRepository(this.entities); var service = new TaService(repository); service.InsertTa(ta, ref errors); if (errors.Count == 0) { return "ok"; } return "error"; }
public void InsertTa() { //// Arranage var errors = new List<string>(); var mockRepository = new Mock<ITaRepository>(); var ta_Service = new TaService(mockRepository.Object); var ta_1 = new Ta { TaId = 2, TaType = "bb", FirstName = "cc", LastName = "dd" }; mockRepository.Setup(x => x.AddTa(ta_1, ref errors)); mockRepository.Setup(x => x.IsNotDuplicateTa(ta_1, ref errors)).Returns(true); //// Act ta_Service.InsertTa(ta_1, ref errors); //// Assert mockRepository.Verify(x => x.AddTa(ta_1, ref errors), Times.Once()); }
public void InsertTaErrorTest3() { //// Arranage var errors = new List<string>(); var mockRepository = new Mock<ITaRepository>(); var teachingAssistantService = new TaService(mockRepository.Object); var ta = new Ta { FirstName = "nick", LastName = string.Empty }; //// Act teachingAssistantService.InsertTa(ta, ref errors); //// Assert last name cannot be empty Assert.AreEqual(1, errors.Count); }
public void InsertTaErrorTest1() { //// Arranage var errors = new List<string>(); var mockRepository = new Mock<ITaRepository>(); var teachingAssistantService = new TaService(mockRepository.Object); //// Act teachingAssistantService.InsertTa(null, ref errors); //// Assert cant be null instructor object Assert.AreEqual(1, errors.Count); }