public RevisionDTO GetLatestPoemRevision(Guid poemId) { var spec = new GetLatestRevisionSpec(poemId); var revision = _revisionRepository.GetBySpec(spec); return(RevisionDTO.CreateDTOFromEntity(revision)); }
public void Handle(NewRevisionDetectedLocalMessage localMessage) { string key; if (_revisionStorage.SaveRevisionInfo(localMessage.Revision, out key)) { _logger.InfoFormat("Importing revision. Revision ID: {0}", localMessage.Revision.Id.Value); var dto = new RevisionDTO { SourceControlID = localMessage.Revision.Id.Value, Description = localMessage.Revision.Comment, CommitDate = localMessage.Revision.Time, AuthorID = _userMapper.IsAuthorMapped(localMessage.Revision) ? (int?)_userMapper.GetAuthorBy(localMessage.Revision).Id : null }; Data.RevisionEntries = localMessage.Revision.Entries; Data.SourceControlID = localMessage.Revision.Id.Value; Data.RevisionKey = key; Send(new CreateEntityCommand <RevisionDTO>(dto)); } else { //_logger.InfoFormat("Revision has already been imported. Aborting revision import. Revision ID: {0}", localMessage.Revision.Id.Value); MarkAsComplete(); } }
public async void OnPost_AllFieldsModified_ExpectChangesSavedToRepository() { //Arrange var poem = new PoemBuilder().Default().Build(); poem.PublishedRevision = null; var client = CreateClientAndTestData(poem); var form = await GetInputFormAsync(client, poem.Id); var modifiedPoemDTO = PoemDTO.CreateDTOFromEntity(poem); modifiedPoemDTO.Name = "Updated " + poem.Name; modifiedPoemDTO.Notes = poem.Notes + " and more notes"; modifiedPoemDTO.ConceivedDateLocal = poem.ConceivedDateUTC.ToLocalTime().AddDays(-1); modifiedPoemDTO.PublishedRevisionId = poem.PoemRevisions.FirstOrDefault().Id; var newRevision = new RevisionBuilder(poem).Random().Build(); var newRevisionDTO = RevisionDTO.CreateDTOFromEntity(newRevision); var inputs = CreateFormInputs(modifiedPoemDTO, newRevisionDTO); //Act var response = await PostRequestHelper.PostWithUpdateInputsAsync(client, form, inputs); //Assert var revisionList = new RevisionList(poem.PoemRevisions.Append(newRevision)); AssertEditPoemPage(response, modifiedPoemDTO, revisionList); }
public async void OnPost_PublishNewRevision_NewRevisionNotSaved_VerifyServiceMethodIsNotCalledAndErrorMessageIsSetCorrectly() { //Arrange var poem = new PoemBuilder().Default().Build(); var poemDTO = PoemDTO.CreateDTOFromEntity(poem); var revisionDTO = RevisionDTO.CreateDTOFromEntity(poem.PoemRevisions.FirstOrDefault()); revisionDTO.Id = Guid.NewGuid(); var mockReadService = new Mock <IReadPoemService>(); mockReadService.Setup(r => r.IsNameUsedByOtherPoem(poemDTO.Id, poemDTO.Name)) .Returns(false); mockReadService.Setup(r => r.GetLatestPoemRevision(poemDTO.Id)) .Returns(new RevisionDTO()); var mockWriteService = new Mock <IWritePoemService>(); mockWriteService.Setup(w => w.UpdatePoem(It.IsAny <PoemDTO>())); mockWriteService.Setup(w => w.SaveNewRevision(poemDTO.Id, It.IsAny <RevisionDTO>())); var testModel = new EditPoemModel(mockReadService.Object, mockWriteService.Object); //Act testModel.PoemToEdit = poemDTO; testModel.PoemToEdit.PublishedRevisionId = EditPoemModel.PUBLISH_NEW_REVISION; testModel.NewRevision = revisionDTO; //Assert await Assert.ThrowsAsync <ApplicationException>(() => testModel.OnPostAsync()); }
public async void OnPost_PublishNewRevision_VerifyServiceMethodIsCalledAndConfirmationMessageIsSet() { //Arrange var poem = new PoemBuilder().Default().Build(); var poemDTO = PoemDTO.CreateDTOFromEntity(poem); var revisionDTO = RevisionDTO.CreateDTOFromEntity(poem.PoemRevisions.FirstOrDefault()); revisionDTO.Id = Guid.NewGuid(); var mockReadService = new Mock <IReadPoemService>(); mockReadService.Setup(r => r.IsNameUsedByOtherPoem(poemDTO.Id, poemDTO.Name)) .Returns(false); mockReadService.Setup(r => r.GetLatestPoemRevision(poemDTO.Id)) .Returns(revisionDTO); var mockWriteService = new Mock <IWritePoemService>(); mockWriteService.Setup(w => w.UpdatePoem(It.IsAny <PoemDTO>())); mockWriteService.Setup(w => w.SaveNewRevision(poemDTO.Id, It.IsAny <RevisionDTO>())); var testModel = new EditPoemModel(mockReadService.Object, mockWriteService.Object); //Act testModel.PoemToEdit = poemDTO; testModel.PoemToEdit.PublishedRevisionId = EditPoemModel.PUBLISH_NEW_REVISION; testModel.NewRevision = revisionDTO; await testModel.OnPostAsync(); //Assert mockReadService.Verify(r => r.GetLatestPoemRevision(poemDTO.Id), Times.Once); mockWriteService.Verify(w => w.UpdatePoem(testModel.PoemToEdit), Times.Once); mockWriteService.Verify(w => w.SaveNewRevision(poemDTO.Id, revisionDTO), Times.Once); Assert.Equal(EditPoemModel.POEM_SAVED_MESSAGE, testModel.ConfirmationMessage); }
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>())); }
private bool IsEqual(RevisionDTO expectResult, RevisionDTO testResult) { if (expectResult.Id == testResult.Id && expectResult.Title == testResult.Title && expectResult.Body == testResult.Body && expectResult.CreatedDateLocal == testResult.CreatedDateLocal && expectResult.Index == testResult.Index) { return(true); } return(false); }
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); }
public void GetLatestPoemRevision_ValidId_ExpectCorrectRevisionDTO() { //Arrange var poem = new PoemBuilder().Default().Build(); var revision = poem.PoemRevisions.FirstOrDefault(); var mockPoemRepository = new Mock <IEntityRepository <Poem> >(); var mockRevisionRepository = new Mock <IEntityRepository <PoemRevision> >(); mockRevisionRepository.Setup(r => r.GetBySpec(It.IsAny <GetLatestRevisionSpec>())) .Returns(revision); //Act var testResult = new ReadPoemService(mockPoemRepository.Object, mockRevisionRepository.Object) .GetLatestPoemRevision(poem.Id); //Assert mockRevisionRepository.Verify(r => r.GetBySpec(It.IsAny <GetLatestRevisionSpec>())); var revisionDTO = RevisionDTO.CreateDTOFromEntity(revision); Assert.True(revisionDTO.IsSame(testResult)); }
private Dictionary <string, string> CreateFormInputs(PoemDTO poemDTO, RevisionDTO revisionDTO = null) { var inputs = new Dictionary <string, string>() { { "PoemToEdit.Name", poemDTO.Name }, { "PoemToEdit.Notes", poemDTO.Notes }, { "PoemToEdit.ConceivedDateLocal", poemDTO.ConceivedDateLocal.ToString("yyyy-MM-dd") } }; if (poemDTO.PublishedRevisionId != null) { inputs.Add("PoemToEdit.PublishedRevisionId", poemDTO.PublishedRevisionId.ToString()); } else { inputs.Add("PoemToEdit.PublishedRevisionId", string.Empty); } if (revisionDTO != null) { inputs.Add("NewRevision.Title", revisionDTO.Title); inputs.Add("NewRevision.Body", revisionDTO.Body); } return(inputs); }
public ActionParameterFillerVisitor(RevisionDTO dto, int?entityId = null) { _dto = dto; _entityId = entityId; }
public IEnumerable <IAction> Parse(RevisionDTO revision, int entityId) { return(GetActions(revision.Description) .Where(x => x.EntityId == entityId) .SelectMany(x => x.Children.FillChangeStatusActionComment())); }
public IEnumerable <AssignRevisionToEntityAction> ParseAssignToEntityAction(RevisionDTO revision) { return(ParseAssignToEntityAction(revision.Description)); }