public void OnGet_WithRevision_ExpectCorrectValuesInProperties() { //Arrange var poem = new PoemBuilder().Default().Build(); var poemDTO = PoemDTO.CreateDTOFromEntity(poem); var mockReadService = new Mock <IReadPoemService>(); mockReadService.Setup(r => r.GetPoemById(poemDTO.Id)) .Returns(poemDTO); var revisions = new RevisionBuilder(poem).Default().BuildCollection(size: 2); revisions.First().CreatedDateUTC = DateTime.UtcNow.AddDays(-2); revisions.Last().CreatedDateUTC = DateTime.UtcNow.AddDays(-1); var revisionList = new RevisionList(revisions); mockReadService.Setup(r => r.GetPoemRevisions(poemDTO.Id)) .Returns(revisionList); var mockWriteService = new Mock <IWritePoemService>(); var testModel = new EditPoemModel(mockReadService.Object, mockWriteService.Object); //Act testModel.OnGet(poemDTO.Id); //Assert Assert.Equal(poemDTO, testModel.PoemToEdit); Assert.Equal(revisionList, testModel.PastRevisions); var latestRevision = revisionList.OrderByDescending(r => r.CreatedDateLocal).First(); Assert.Equal(latestRevision, testModel.LatestRevision); }
public void OnGet_InvalidModelState_VerifyServiceMethodIsNotCalled() { var poemId = Guid.Empty; //Arrange var mockReadService = new Mock <IReadPoemService>(); mockReadService.Setup(r => r.GetPoemById(poemId)); mockReadService.Setup(r => r.GetPoemRevisions(poemId)); var mockWriteService = new Mock <IWritePoemService>(); var testModel = new EditPoemModel(mockReadService.Object, mockWriteService.Object); //Act testModel.ModelState.AddModelError("test", "invalid state"); testModel.OnGet(poemId); //Assert mockReadService.Verify((r => r.GetPoemById(poemId)), Times.Never); mockReadService.Verify(r => r.GetPoemRevisions(poemId), Times.Never); }
public void OnGet_WithoutRevision_ExpectCorrectValuesInProperties() { //Arrange var poem = new PoemBuilder().Default().Build(); var poemDTO = PoemDTO.CreateDTOFromEntity(poem); var mockReadService = new Mock <IReadPoemService>(); mockReadService.Setup(r => r.GetPoemById(poemDTO.Id)) .Returns(poemDTO); mockReadService.Setup(r => r.GetPoemRevisions(poemDTO.Id)) .Returns(new RevisionList()); var mockWriteService = new Mock <IWritePoemService>(); var testModel = new EditPoemModel(mockReadService.Object, mockWriteService.Object); //Act testModel.OnGet(poemDTO.Id); //Assert Assert.Equal(poemDTO, testModel.PoemToEdit); }