public void SaveNewPoemWithRevision_VerifyCallToPoemRepository() { //Arrange var poemDTO = new PoemDTO() { Name = "name", Notes = "notes", ConceivedDateLocal = DateTime.Now }; var revisionDTO = new RevisionDTO() { Title = "title", Body = "body" }; var poemEntity = poemDTO.ToEntity(); poemEntity.PoemRevisions = new List <PoemRevision>() { revisionDTO.ToEntity() }; var mockPoemRepository = new Mock <IEntityRepository <Poem> >(); mockPoemRepository.Setup(p => p.Add(It.IsAny <Poem>())); var mockRevisionRepository = new Mock <IEntityRepository <PoemRevision> >(); //Act new WritePoemService( mockPoemRepository.Object, mockRevisionRepository.Object) .SaveNewPoem(poemDTO, revisionDTO); //Assert mockPoemRepository.Verify(p => p.Add(It.IsAny <Poem>())); }
public void SaveNewRevision(Guid poemId, RevisionDTO newRevision) { var poemEntity = _poemRepository.GetByGuid(poemId); if (poemEntity == null) { throw new ApplicationException(); } var revisionEntity = newRevision.ToEntity(); revisionEntity.Poem = poemEntity; revisionEntity.CreatedDateUTC = DateTime.UtcNow; _revisionRepository.Add(revisionEntity); }
public void SaveNewPoem(PoemDTO newPoem, RevisionDTO newRevision) { var poemEntity = newPoem.ToEntity(); poemEntity.CreatedDateUTC = DateTime.UtcNow; if (newRevision != null && !newRevision.IsEmpty()) { var revisionEntity = newRevision.ToEntity(); revisionEntity.CreatedDateUTC = DateTime.UtcNow; poemEntity.PoemRevisions = new List <PoemRevision>() { revisionEntity }; } _poemRepository.Add(poemEntity); }