public void DeleteTest() { string email = ""; var result = (ViewResult)controller.Delete(email) as ViewResult; Assert.IsNotNull(result); }
public async void Delete_Errors() { TeacherControllerMockFacade mock = new TeacherControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); TeacherController controller = new TeacherController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Delete(default(int)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>())); }
public void ShouldDeleteCorrectly() { Mock <IGenericService <Teacher> > teacherServiceMock = new Mock <IGenericService <Teacher> >(); Mock <IActivityLoggerService> loggerMock = new Mock <IActivityLoggerService>(); Teacher teacher = new Teacher() { Id = 100, FirstName = "Robin", LastName = "Schellius" }; ClaimsPrincipal identity = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "123") })); teacherServiceMock.Setup(m => m.FindById(It.IsAny <int>(), It.IsAny <string[]>())).Returns(teacher); teacherServiceMock.Setup(m => m.Delete(It.IsAny <Teacher>())).Returns((Teacher model) => { return(1); }); loggerMock.Setup(m => m.Delete(It.IsAny <string>())); TeacherController controller = new TeacherController(teacherServiceMock.Object) { ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = identity } } }; RedirectToActionResult result = controller.Delete(teacher.Id) as RedirectToActionResult; Assert.Equal("Index", result?.ActionName); }
static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; int table = 0; int action = 0; do { table = FirstMenu(); if (table == 0) { return; } BaseController controller = null; switch (table) { case 1: action = SecondMenu("Faculty"); controller = new FacultyController(); break; case 2: action = SecondMenu("Group"); controller = new GroupController(); break; case 3: action = SecondMenu("Lectures"); controller = new LecturesPlanController(); break; case 4: action = SecondMenu("Student"); controller = new StudentController(); break; case 5: action = SecondMenu("Subject"); controller = new SubjectController(); break; case 6: action = SecondMenu("Teacher"); controller = new TeacherController(); break; } switch (action) { case 1: controller.Create(); break; case 2: controller.Read(); break; case 3: controller.Update(); break; case 4: controller.Delete(); break; case 5: controller.Find(); break; } } while (true); }
public async void DeleteWhenIdIsNull_ReturnsNotFound() { var result = await systemUnderTest.Delete(null); Assert.IsType <NotFoundResult>(result); }