Exemplo n.º 1
0
        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>()));
        }
Exemplo n.º 2
0
        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);
        }