void ListPoemsByTitle_VerifyCorrectSpecificationIsUsed() { //Arrange var mockRepository = new Mock <IEntityRepository <Poem> >(); mockRepository.Setup(r => r.List(It.IsAny <ListPoemsByTitleSpec>())); //Act var service = new ListPoemsService(mockRepository.Object); var testResult = service.ListPoemsByTitle(); //Assert mockRepository.Verify(r => r.List(It.IsAny <ListPoemsByTitleSpec>())); }
void ListPoemsByTitle_RepositoryReturnsNull_ExpectEmptyPoemDTOList() { //Arrange var mockRepository = new Mock <IEntityRepository <Poem> >(); mockRepository.Setup(r => r.List(It.IsAny <ListPoemsByTitleSpec>())) .Returns((IEnumerable <Poem>)null); //Act var service = new ListPoemsService(mockRepository.Object); var testResult = service.ListPoemsByTitle(); //Assert var expectResult = new List <PoemDTO>(); Assert.Equal(expectResult, testResult); }
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()); }