public void testDeleteTeacherSuccess() { Assert.Null(serv.GetByUserName(USERNAME)); // Arrange var result = this.userManager.Create(teacherUser, "testpassword"); if (result.Succeeded) { this.userManager.AddToRole(teacherUser.Id, GlobalConstants.TeacherRoleName); } serv.Add(entity); int count = serv.All().Count(); Teacher study = serv.GetByUserName(USERNAME); Guid id = study.Id; // Act MichtavaResult res = serv.Delete(entity); var res2 = this.userManager.Delete(teacherUser); // Assert Assert.True(res2.Succeeded); Assert.True(res is MichtavaSuccess); Assert.Null(serv.GetByUserName(USERNAME)); Assert.True(serv.All().Count() == count - 1); Assert.True(serv.GetById(id).IsDeleted); Assert.True(serv.HardDelete(entity) is MichtavaSuccess); Assert.Null(serv.GetByUserName(USERNAME)); }
public IHttpActionResult DeleteTeacher(int id) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = new TeacherService(); bool isSuccess = service.Delete(id); if (!isSuccess) { return(Ok(new ResponseModel() { Result = ResponseType.Error, Description = "Entity was not deleted." })); } return(Ok(new ResponseModel() { Result = ResponseType.Success })); } catch (Exception ex) { Console.WriteLine(ex.Message); return(InternalServerError(ex)); } }
public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <ITeacherService, ITeacherRepository>(); var model = new ApiTeacherServerRequestModel(); var validatorMock = new Mock <IApiTeacherServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new TeacherService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALTeacherMapperMock, mock.DALMapperMockFactory.DALEventTeacherMapperMock, mock.DALMapperMockFactory.DALRateMapperMock, mock.DALMapperMockFactory.DALTeacherTeacherSkillMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TeacherDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public void Delete_ExistingTeacher_Successfully() { var teacherToDelete = new Entities.Models.Teacher(); var repositoryWrapper = new Mock <IWrapperRepository>(); repositoryWrapper.Setup(x => x.Teacher.Delete(teacherToDelete)); var teacherService = new TeacherService(repositoryWrapper.Object, _logger); teacherService.Delete(teacherToDelete); }
static int DeleteScript0() { Teacher model = new Teacher() { Name = "Random Teacher", PassportData = 555190 }; DateTime startTime = DateTime.Now; TeacherService.Delete(model); DateTime finishTime = DateTime.Now; return((int)(finishTime - startTime).TotalMilliseconds); }
/// <summary> /// 删除 /// </summary> /// <param name="Id"></param> /// <returns></returns> public static string DeleteTeacher(int Id) { try { using (TeacherService teacherService = new TeacherService()) { Teacher teacher = new Teacher(); teacher.Id = Id; teacher.IsDelete = true; teacherService.Delete(teacher); return("删除成功"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task DeleteTeacher_GivenTeacherId_ReturnListWithoutDeletedTeacher() { //Arrange var teachers = await teacherService.GetAll(); var teachersCount = teachers.Count; var lastTeacher = teachers[teachers.Count - 1]; //Act await teacherService.Delete(lastTeacher.Id); var newTeachers = await teacherService.GetAll(); var newTeachersCount = newTeachers.Count; //Assert Assert.AreEqual(teachersCount - 1, newTeachersCount); }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here var result = TeacherService.Delete(id); //var result = teacherlist.Where(e => e.Id == id).FirstOrDefault(); if (result == null) { return(RedirectToAction("Index", new { ErrorMsg = "用户不存在" })); } //teacherlist.Remove(result); return(RedirectToAction("Index")); } catch { return(View()); } }
public async void Delete() { var mock = new ServiceMockFacade <ITeacherRepository>(); var model = new ApiTeacherRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new TeacherService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TeacherModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTeacherMapperMock, mock.DALMapperMockFactory.DALTeacherMapperMock, mock.BOLMapperMockFactory.BOLRateMapperMock, mock.DALMapperMockFactory.DALRateMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.TeacherModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public ActionResult <object> Delete([FromBody] Model.DeleteID deleteID) { try { Init(); if (!ModelState.IsValid) { Response.StatusCode = 400; return("Teacher does not exist"); } else { if (deleteID.id == null) { Response.StatusCode = 400; return("Teacher does not exist"); } StringBuilder sbError = new StringBuilder(""); var isDeleted = _teacherService.Delete(deleteID.id, ref sbError); if (!isDeleted) { Response.StatusCode = 400; return("Teacher Delete failed"); } else { Response.StatusCode = 200; return((string)"Teacher Deleted Successfully"); } } } catch (Exception er) { return(Error(er)); } }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <ITeacherService, ITeacherRepository>(); var model = new ApiTeacherServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new TeacherService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TeacherModelValidatorMock.Object, mock.DALMapperMockFactory.DALTeacherMapperMock, mock.DALMapperMockFactory.DALEventTeacherMapperMock, mock.DALMapperMockFactory.DALRateMapperMock, mock.DALMapperMockFactory.DALTeacherTeacherSkillMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.TeacherModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TeacherDeletedNotification>(), It.IsAny <CancellationToken>())); }
public IActionResult DeleteTeacher(int id) { Result <int> result = _teacherService.Delete(id); return(this.CreateResult(result)); }
public ActionResult Delete(int id) { teacherService.Delete(id); return(RedirectToAction("Index")); }