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