Exemplo n.º 1
0
        public void OnGet_VerifyCorrectServiceMethodIsCalled()
        {
            //Arrange
            var mockService = new Mock <IListPoemsService>();

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

            //Act
            var listModel = new ListPoemsByNameModel(mockService.Object);

            listModel.OnGet();

            //Assert
            mockService.Verify(s => s.ListByName());
        }
Exemplo n.º 2
0
        public void OnGet_InvalidModelState_VerifyServiceMethodIsNotCalled()
        {
            //Arrange
            var mockService = new Mock <IListPoemsService>();

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

            //Act
            var listModel = new ListPoemsByNameModel(mockService.Object);

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

            //Assert
            mockService.Verify(s => s.ListByName(), Times.Never);
        }
Exemplo n.º 3
0
        public void OnGet_ExistingPoems_VerifyPoemListIsNotEmpty()
        {
            //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.ListByName()).Returns(poemDTOList);

            //Act
            var listModel = new ListPoemsByNameModel(mockService.Object);

            listModel.OnGet();

            //Assert

            Assert.Equal(poemDTOList.Count(), listModel.Poems.Count());
        }