コード例 #1
0
        public void Initialize()
        {
            _pageInformationService = new Mock <IPageInformationService>();
            _pageInformationService.Setup(x => x.GetpageInformation(1)).Throws(new Exception());
            _pageInformationService.Setup(x => x.GetpageInformation(2)).Returns(new PageInformation());

            _controllerMock = new PageApiController(_pageInformationService.Object);
        }
コード例 #2
0
ファイル: PageControllerTests.cs プロジェクト: zmitry/mvc
        public void PageControllerDelete_Should_404WhenPageNotExist()
        {
            var mockRepo   = new Mock <IPageRepository>();
            var mockLogger = new Mock <ILogger <PageApiController> >();

            mockRepo.Setup(r => r.Remove(1));

            var repo       = mockRepo.Object;
            var controller = new PageApiController(repo, mockLogger.Object);

            var res   = controller.DeletePage(1).Result;
            var error = Assert.IsType <NotFoundResult>(res);

            Assert.IsType <NotFoundResult>(error);
        }
コード例 #3
0
ファイル: PageControllerTests.cs プロジェクト: zmitry/mvc
        public void PageControllerGet_Should_ReturnPageByIndex()
        {
            var mockRepo   = new Mock <IPageRepository>();
            var mockLogger = new Mock <ILogger <PageApiController> >();
            var page       = new Page()
            {
                PageId = 1, AddedDate = DateTime.Now, Content = "test"
            };

            mockRepo.Setup(repo => repo.Get(1)).Returns(page);
            var controller = new PageApiController(mockRepo.Object, mockLogger.Object);

            var res    = controller.GetPage(1, null).Result;
            var Result = new JsonResult(page);

            Assert.Equal(Result.Value, (res as JsonResult).Value);
        }
コード例 #4
0
ファイル: PageControllerTests.cs プロジェクト: zmitry/mvc
        public void PageControllerPut_Should_ReturnBadReqWhenModelNotValid()
        {
            var mockRepo   = new Mock <IPageRepository>();
            var mockLogger = new Mock <ILogger <PageApiController> >();
            var page       = new Page()
            {
                PageId = 1, AddedDate = DateTime.Now
            };

            mockRepo.Setup(r => r.Update(page));
            var repo       = mockRepo.Object;
            var controller = new PageApiController(repo, mockLogger.Object);

            controller.ModelState.AddModelError("Content", "Required");
            var res   = controller.PostPage(page).Result;
            var error = Assert.IsType <BadRequestObjectResult>(res);

            Assert.IsType <SerializableError>(error.Value);
        }
コード例 #5
0
ファイル: PageControllerTests.cs プロジェクト: zmitry/mvc
        public void PageControllerDelete_Should_OkWhenAfterDelete()
        {
            var mockRepo   = new Mock <IPageRepository>();
            var mockLogger = new Mock <ILogger <PageApiController> >();
            var page       = new Page()
            {
                PageId = 1, AddedDate = DateTime.Now, Content = "test"
            };

            mockRepo.Setup(r => r.Get(1)).Returns(page);
            mockRepo.Setup(r => r.Remove(1));

            var repo       = mockRepo.Object;
            var controller = new PageApiController(repo, mockLogger.Object);

            var res    = controller.DeletePage(1).Result;
            var error  = Assert.IsType <OkObjectResult>(res);
            var error2 = Assert.IsType <OkObjectResult>(res);

            Assert.IsType <OkObjectResult>(error);
        }
コード例 #6
0
ファイル: PageControllerTests.cs プロジェクト: zmitry/mvc
        public void PageControllerGetAll_Should_ReturnPagesWithFiltering()
        {
            var mockRepo   = new Mock <IPageRepository>();
            var mockLogger = new Mock <ILogger <PageApiController> >();
            var page       = new Page()
            {
                PageId = 1, AddedDate = DateTime.Now, Content = "test"
            };
            var page2 = new Page()
            {
                PageId = 2, AddedDate = DateTime.Now, Content = "test"
            };
            var list = new List <Page>();

            list.Add(page);
            list.Add(page2);
            mockRepo.Setup(repo => repo.SortAndTake("", "id", false, 10, 0)).Returns(list);
            var controller = new PageApiController(mockRepo.Object, mockLogger.Object);

            var res    = controller.GetPages();
            var Result = new JsonResult(list);

            Assert.Equal(Result.Value, (res as JsonResult).Value);
        }