void GetDefaultPoem_VerifyCorrectSpecificationIsUsed() { //Arrange var mockRepository = new Mock <IEntityRepository <Poem> >(); mockRepository.Setup(r => r.GetBySpec(It.IsAny <GetDefaultPoemSpec>())); //Act var service = new RetrievePoemService(mockRepository.Object); var testResult = service.GetDefaultPoem(); //Assert mockRepository.Verify(r => r.GetBySpec(It.IsAny <GetDefaultPoemSpec>())); }
void GetDefaultPoem_RepositoryReturnsNull_ExpectEmptyPoemDTO() { //Arrange var mockRepository = new Mock <IEntityRepository <Poem> >(); mockRepository.Setup(r => r.GetBySpec(It.IsAny <GetDefaultPoemSpec>())) .Returns((Poem)null); //Act var service = new RetrievePoemService(mockRepository.Object); var testResult = service.GetDefaultPoem(); //Assert Assert.NotNull(testResult); }
void GetDefaultPoem_RepositoryReturnsValidPoem_ExpectPoemDTOIsSetCorrectly() { //Arrange var poem = new PoemBuilder().Default().Build(); poem.PublishedRevision = poem.PoemRevisions.FirstOrDefault(); var mockRepository = new Mock <IEntityRepository <Poem> >(); mockRepository.Setup(r => r.GetBySpec(It.IsAny <GetDefaultPoemSpec>())) .Returns(poem); //Act var service = new RetrievePoemService(mockRepository.Object); var testResult = service.GetDefaultPoem(); //Assert Assert.Equal(poem.Id, testResult.Id); Assert.Equal(poem.PublishedRevision.Title, testResult.Title); Assert.Equal(poem.PublishedRevision.Body, testResult.Body); }