Exemple #1
0
        public void NoMatchingPublishedPoem_ExpectNullReturned()
        {
            //Arrange
            var poemList = new PoemBuilder().Default().BuildCollection(size: 2);

            poemList.FirstOrDefault().PublishedRevision = poemList.FirstOrDefault().PoemRevisions.FirstOrDefault();
            poemList.Last().PublishedRevision           = poemList.Last().PoemRevisions.FirstOrDefault();

            //Act
            var testResult = ApplySpecificationToList(poemList, Guid.Empty);

            //Assert
            Assert.Null(testResult);
        }
Exemple #2
0
        public void MatchingPoemIsNotPublished_ExpectNullReturned()
        {
            //Arrange
            var poemList = new PoemBuilder().Default().BuildCollection(size: 2);

            poemList.FirstOrDefault().PublishedRevision = poemList.FirstOrDefault().PoemRevisions.FirstOrDefault();
            var poemToGet = poemList.Last();

            poemToGet.PublishedRevision = null;

            //Act
            var testResult = ApplySpecificationToList(poemList, poemToGet.Id);

            //Assert
            Assert.Null(testResult);
        }
Exemple #3
0
        public async void OnGet_DefaultPage_ReturnsPublishedPoemFromRepository()
        {
            //Arrange
            var client = _appFactory.CreateClient();
            var poems  = new PoemBuilder().Default().BuildCollection(size: 2);

            var publishedPoem     = poems.Last();
            var publishedRevision = publishedPoem.PoemRevisions.FirstOrDefault();

            publishedPoem.PublishedRevision = publishedRevision;

            var nonPublishedPoem = poems.FirstOrDefault();

            nonPublishedPoem.PublishedRevision = null;

            _appFactory.DbContext.AddRange(poems);
            _appFactory.DbContext.SaveChanges();

            //Act
            var response = await client.GetAsync("/");

            var pageContent = await ResponseHelper.GetDocumentAsync(response);

            var selectors = new SelectorHelper(pageContent, PageElements.IndexPageSelectors);

            var title = selectors.Get <IHtmlElement>((int)PageElements.IndexPageElementEnum.PoemTitle);
            var body  = selectors.Get <IHtmlElement>((int)PageElements.IndexPageElementEnum.PoemBody);

            //Assert
            Assert.NotNull(title);
            Assert.NotNull(body);
            Assert.Equal(publishedRevision.Title, title.TextContent);
            Assert.Equal(publishedRevision.Body, body.TextContent);
        }
Exemple #4
0
        public void NoPublishedPoem_ExpectEmptyListReturned()
        {
            //Arrange
            var poemList = new PoemBuilder().Default().BuildCollection(size: 2);

            poemList.FirstOrDefault().PublishedRevision = null;
            poemList.Last().PublishedRevision           = null;

            //Act
            var testResult = ApplySpecificationToList(poemList);

            //Assert
            Assert.Empty(testResult);
        }
Exemple #5
0
        public void HasPublishedPoem_ExpectPoemReturned()
        {
            //Arrange
            var poemList = new PoemBuilder().Default().BuildCollection(size: 2);

            poemList.FirstOrDefault().PublishedRevision = null;
            var publishedPoem = poemList.Last();

            publishedPoem.PublishedRevision = publishedPoem.PoemRevisions.FirstOrDefault();

            //Act
            var testResult   = ApplySpecificationToList(poemList);
            var returnedPoem = testResult.Single();

            //Assert
            Assert.Equal(publishedPoem.Id, returnedPoem.Id);
            Assert.Equal(publishedPoem.PublishedRevision.Title, returnedPoem.PublishedRevision.Title);
        }
Exemple #6
0
        public void HasPublishedPoem_ExpectPoemReturned()
        {
            //Arrange
            var poemList = new PoemBuilder().Default().BuildCollection(size: 2);

            poemList.FirstOrDefault().PublishedRevision = null;
            var matchingPoem = poemList.Last();

            matchingPoem.PublishedRevision = matchingPoem.PoemRevisions.FirstOrDefault();

            //Act
            var testResult = ApplySpecificationToList(poemList);

            //Assert
            Assert.NotNull(testResult);
            Assert.Equal(matchingPoem.Id, testResult.Id);
            Assert.Equal(matchingPoem.PublishedRevision.Id, testResult.PublishedRevision.Id);
            Assert.Equal(matchingPoem.PublishedRevision.Title, testResult.PublishedRevision.Title);
            Assert.Equal(matchingPoem.PublishedRevision.Body, testResult.PublishedRevision.Body);
        }
Exemple #7
0
        public void HasMultiplePoems_ExpectOnlyTheLatestPublishedPoemReturned()
        {
            //Arrange
            var poemList  = new PoemBuilder().Default().BuildCollection(size: 2);
            var olderPoem = poemList.FirstOrDefault();

            olderPoem.PublishedRevision   = olderPoem.PoemRevisions.FirstOrDefault();
            olderPoem.LastModifiedDateUTC = DateTime.UtcNow.AddDays(-2);

            var matchingPoem = poemList.Last();

            matchingPoem.PublishedRevision   = matchingPoem.PoemRevisions.FirstOrDefault();
            matchingPoem.LastModifiedDateUTC = olderPoem.LastModifiedDateUTC.AddDays(1);

            //Act
            var testResult = ApplySpecificationToList(poemList);

            //Assert
            Assert.NotNull(testResult);
            Assert.Equal(matchingPoem.Id, testResult.Id);
            Assert.Equal(matchingPoem.PublishedRevision.Id, testResult.PublishedRevision.Id);
            Assert.Equal(matchingPoem.PublishedRevision.Title, testResult.PublishedRevision.Title);
            Assert.Equal(matchingPoem.PublishedRevision.Body, testResult.PublishedRevision.Body);
        }