void ListPoemsByTitle_RepositoryReturnsPoemList_ExpectPoemDTOList() { //Arrange var poemList = new PoemBuilder().Default().BuildCollection(size: 3); var mockRepository = new Mock <IEntityRepository <Poem> >(); mockRepository.Setup(r => r.List(It.IsAny <ListPoemsByTitleSpec>())) .Returns(poemList); //Act var service = new ListPoemsService(mockRepository.Object); var testResult = service.ListPoemsByTitle(); //Assert var expectResult = poemList.Select(p => PoemDTO.CreateDTOFromEntity(p)); Assert.Equal(expectResult.Count(), testResult.Count()); }
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()); }
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.ListByConceivedDate()).Returns(poemDTOList); //Act var listModel = new ListPoemsByConceivedDateModel(mockService.Object); listModel.OnGet(); //Assert Assert.Equal(poemDTOList.Count(), listModel.Poems.Count()); }