コード例 #1
0
        public RevisionDTO GetLatestPoemRevision(Guid poemId)
        {
            var spec     = new GetLatestRevisionSpec(poemId);
            var revision = _revisionRepository.GetBySpec(spec);

            return(RevisionDTO.CreateDTOFromEntity(revision));
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
        }