void ListPoemsByDate_VerifyCorrectSpecificationIsUsed() { //Arrange var mockRepository = new Mock <IEntityRepository <Poem> >(); mockRepository.Setup(r => r.List(It.IsAny <ListPoemsByDateSpec>())); //Act var service = new ListPoemsService(mockRepository.Object); var testResult = service.ListPoemsByDate(); //Assert mockRepository.Verify(r => r.List(It.IsAny <ListPoemsByDateSpec>())); }
void ListPoemsByDate_RepositoryReturnsNull_ExpectEmptyPoemDTOList() { //Arrange var mockRepository = new Mock <IEntityRepository <Poem> >(); mockRepository.Setup(r => r.List(It.IsAny <ListPoemsByDateSpec>())) .Returns((IEnumerable <Poem>)null); //Act var service = new ListPoemsService(mockRepository.Object); var testResult = service.ListPoemsByDate(); //Assert var expectResult = new List <PoemDTO>(); Assert.Equal(expectResult, testResult); }
void ListPoemsByDate_RepositoryReturnsPoemList_ExpectPoemDTOList() { //Arrange var poemList = new PoemBuilder().Default().BuildCollection(size: 3); var mockRepository = new Mock <IEntityRepository <Poem> >(); mockRepository.Setup(r => r.List(It.IsAny <ListPoemsByDateSpec>())) .Returns(poemList); //Act var service = new ListPoemsService(mockRepository.Object); var testResult = service.ListPoemsByDate(); //Assert var expectResult = poemList.Select(p => PoemDTO.CreateDTOFromEntity(p)); Assert.Equal(expectResult.Count(), testResult.Count()); }