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

            mockService.Setup(s => s.GetPoemById(Guid.Empty)).Returns(new PoemDTO());

            //Act
            var poemModel  = new PoemModel(mockService.Object);
            var testResult = poemModel.OnGet(Guid.Empty);

            //Assert
            mockService.Verify(s => s.GetPoemById(Guid.Empty));
        }
Exemple #2
0
        public void OnGet_InvalidGuid_VerifyRedirect()
        {
            //Arrange
            var mockService = new Mock <IRetrievePoemService>();
            var poemModel   = new PoemModel(mockService.Object);

            //Act
            var testResult = poemModel.OnGet(Guid.Empty);

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

            Assert.Equal(REDIRECT_PAGE_NAME_WHEN_ERROR, redirectToPage.PageName);
        }
Exemple #3
0
        public void OnGet_VerifyPageIsReturnedAndPoemDTOIsSet()
        {
            //Arrange
            var poem = new PoemDTO()
            {
                Title = "title",
                Body  = "body",
                Id    = Guid.NewGuid()
            };
            var mockService = new Mock <IRetrievePoemService>();

            mockService.Setup(s => s.GetPoemById(poem.Id)).Returns(poem);

            //Act
            var poemModel  = new PoemModel(mockService.Object);
            var testResult = poemModel.OnGet(poem.Id);

            //Assert

            Assert.IsType <PageResult>(testResult);
            Assert.Equal(poem.Title, poemModel.Poem.Title);
            Assert.Equal(poem.Body, poemModel.Poem.Body);
            Assert.Equal(poem.Id, poemModel.Poem.Id);
        }