Exemple #1
0
        public void OnGet_VerifyCorrectServiceMethodIsCalled()
        {
            //Arrange
            var mockService = new Mock <IListPoemsService>();

            mockService.Setup(s => s.ListPoemsByDate()).Returns(new List <PoemDTO>());

            //Act
            var listModel  = new ListPoemsByDateModel(mockService.Object);
            var testResult = listModel.OnGet();

            //Assert
            mockService.Verify(s => s.ListPoemsByDate());
        }
Exemple #2
0
        public void OnGet_VerifyPageIsReturnedAndPoemListIsSet()
        {
            //Arrange
            var poems       = new PoemBuilder().Default().BuildCollection(size: 3);
            var poemDTOList = poems.Select(p => PoemDTO.CreateDTOFromEntity(p));

            var mockService = new Mock <IListPoemsService>();

            mockService.Setup(s => s.ListPoemsByDate()).Returns(poemDTOList);

            //Act
            var listModel  = new ListPoemsByDateModel(mockService.Object);
            var testResult = listModel.OnGet();

            //Assert

            Assert.IsType <PageResult>(testResult);
            Assert.Equal(poemDTOList.Count(), listModel.Poems.Count());
        }
Exemple #3
0
        public void OnGet_InvalidModelState_VerifyServiceMethodIsNotCalledAndRedirect()
        {
            //Arrange
            var mockService = new Mock <IListPoemsService>();

            mockService.Setup(s => s.ListPoemsByDate());

            var listModel = new ListPoemsByDateModel(mockService.Object);

            listModel.ModelState.AddModelError("test", "invalid state");

            //Act
            var testResult = listModel.OnGet();

            //Assert
            mockService.Verify(s => s.ListPoemsByDate(), Times.Never);

            Assert.IsType <RedirectToPageResult>(testResult);
            var redirectToPage = (RedirectToPageResult)testResult;

            Assert.Equal(REDIRECT_PAGE_NAME_WHEN_ERROR, redirectToPage.PageName);
        }