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