Posted By

joelabrahamsson on 05/21/10


Tagged

testing EPiServer


Versions (?)

Experimenting: Test utilizing a DSL


 / Published in: C#
 

A test I wrote for a component that imports RSS feeds and saves each item as a page in EPiServer CMS. While writing this test and some others I tried to build a DSL for the test project.

  1. [Fact]
  2. public void NoNewItemExists_NoNewPageIsSaved()
  3. {
  4. var root = GivenA.SyndicationFeedRoot;
  5. var rootsLocator = new FakeSyndicationRootsLocator()
  6. .ThatForSyndicationFeedRootsReturns(root);
  7.  
  8. SyndicationItem item = FixtureHelper.CreateSyndicationItem();
  9. var feedFetcher = new FakeSyndicationFeedFetcher()
  10. .ThatForUrl(root.FeedUrl)
  11. .ReturnsFeedWith(item);
  12.  
  13. SyndicationItemPage existingPage = new SyndicationItemPage();
  14. existingPage.ItemPublishedDate = item.PublishDate.DateTime.ToLocalTime();
  15.  
  16. var pageRepository = new FakePageRepository()
  17. .ThatForPageReference(root.PageLink)
  18. .ReturnsSingleChild(existingPage)
  19. .And
  20. .ThatForGetDefaultPageDataCalledWith<SyndicationItemPage>(root.PageLink)
  21. .Returns(new SyndicationItemPage());
  22.  
  23. ImporterImplementation importer = new ImporterImplementation(rootsLocator,
  24. feedFetcher, pageRepository);
  25. importer.ImportFeeds();
  26.  
  27. Assert.False(pageRepository.HasSavedAny<SyndicationItemPage>());
  28. }

Report this snippet  

You need to login to post a comment.