예제 #1
0
        public void DeleteTest()
        {
            string email = "";

            var result = (ViewResult)controller.Delete(email) as ViewResult;

            Assert.IsNotNull(result);
        }
예제 #2
0
        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);
        }
예제 #4
0
파일: Program.cs 프로젝트: HYMPYT/BD_ZU
        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);
        }