Beispiel #1
0
        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>()));
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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());
        }