public void ManipulateSiteMapTest(bool validCategory, int numberOfItems, int expectedCount) { //Setup the fakes and dummies var fakeRepository = A.Fake <IJobProfileCategoryRepository>(); var siteMapList = GetEntries(validCategory, numberOfItems); A.CallTo(() => fakeRepository.GetJobProfileCategories()).Returns(new EnumerableQuery <JobProfileCategory>(new List <JobProfileCategory> { new JobProfileCategory { Url = nameof(JobProfileCategory.Url) } })); //Instantiate & Act var sitemapHandler = new SiteMapHandler(fakeRepository); //Act var result = sitemapHandler.ManipulateSiteMap(siteMapList); //Assert result.Count().Should().Be(expectedCount); result.Any(x => x.Location.ToUpperInvariant().EndsWith("/JOB-CATEGORIES") || x.Location.ToUpperInvariant().EndsWith("/JOB-PROFILES")).Should().BeFalse(); if (validCategory) { A.CallTo(() => fakeRepository.GetJobProfileCategories()).MustHaveHappenedOnceExactly(); result.Any(x => x.Location.Equals($"/job-categories/{nameof(JobProfileCategory.Url)}")).Should().BeTrue(); } else { A.CallTo(() => fakeRepository.GetJobProfileCategories()).MustNotHaveHappened(); } }
public SiteMapHandlerTests() { _siteMaps = new SiteMapDictionary(); _compressor = new Mock<IHttpResponseCompressor>(); _cacher = new Mock<IHttpResponseCacher>(); _urlGenerator = new Mock<IUrlGenerator>(); _httpContext = TestHelper.CreateMockedHttpContext(); _handler = new SiteMapHandler(_siteMaps, _compressor.Object, _cacher.Object, _urlGenerator.Object); }
public SiteMapHandlerTests() { _siteMaps = new SiteMapDictionary(); _compressor = new Mock <IHttpResponseCompressor>(); _cacher = new Mock <IHttpResponseCacher>(); _urlGenerator = new Mock <IUrlGenerator>(); _httpContext = TestHelper.CreateMockedHttpContext(true); _handler = new SiteMapHandler(_siteMaps, _compressor.Object, _cacher.Object, _urlGenerator.Object); }
public void Execute(XmlNode node) { bool isComplete = false; while (false == isComplete) { try { bool result = false; SiteMapHandler sitemap = new SiteMapHandler(); string message = sitemap.RebuildSiteMaps(ref result); isComplete = true; } catch { isComplete = false; Thread.Sleep(TimeSpan.FromMinutes(5)); } } }
public SiteMapHandlerFixture() { RouteTable.Routes.Clear(); new RegisterRoutes(settings.Object).Execute(); var userRepository = new Mock <IUserRepository>(); var storyRepository = new Mock <IStoryRepository>(); var categoryRepository = new Mock <ICategoryRepository>(); var tagRepository = new Mock <ITagRepository>(); List <IUser> topMovers = new List <IUser>(); for (int i = 1; i <= settings.Object.TopUsers; i++) { var user = new Mock <IUser>(); user.ExpectGet(u => u.Id).Returns(Guid.NewGuid()); user.ExpectGet(u => u.UserName).Returns("Top Mover {0}".FormatWith(i)); topMovers.Add(user.Object); } userRepository.Expect(r => r.FindTop(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <int>(), It.IsAny <int>())).Returns(new PagedResult <IUser>(topMovers, settings.Object.TopUsers)); Func <string, Mock <IStory> > createStory = name => { var category = new Mock <ICategory>(); category.ExpectGet(c => c.Name).Returns("Dummy"); var tag = new Mock <ITag>(); tag.ExpectGet(t => t.Name).Returns("Dummy"); var story = new Mock <IStory>(); story.ExpectGet(s => s.BelongsTo).Returns(category.Object); story.ExpectGet(s => s.UniqueName).Returns(name); story.ExpectGet(s => s.Tags).Returns(new List <ITag> { tag.Object }); story.ExpectGet(s => s.TagCount).Returns(1); return(story); }; List <IStory> publishedStories = new List <IStory>(); for (int i = 1; i <= 50; i++) { var story = createStory("Published Story {0}".FormatWith(i)); story.ExpectGet(s => s.PublishedAt).Returns(Constants.ProductionDate); publishedStories.Add(story.Object); } List <IStory> upcomingStories = new List <IStory>(); for (int i = 1; i <= 50; i++) { var story = createStory("Upcoming Story {0}".FormatWith(i)); upcomingStories.Add(story.Object); } storyRepository.Expect(r => r.FindPublished(It.IsAny <int>(), It.IsAny <int>())).Returns(new PagedResult <IStory>(publishedStories, 1000)); storyRepository.Expect(r => r.FindUpcoming(It.IsAny <int>(), It.IsAny <int>())).Returns(new PagedResult <IStory>(upcomingStories, 1000)); storyRepository.Expect(r => r.CountByPublished()).Returns(300); storyRepository.Expect(r => r.CountByUpcoming()).Returns(100); List <ICategory> categories = new List <ICategory>(); for (int i = 1; i <= 10; i++) { var category = new Mock <ICategory>(); category.ExpectGet(c => c.UniqueName).Returns("Category {0}".FormatWith(i)); categories.Add(category.Object); } categoryRepository.Expect(r => r.FindAll()).Returns(new ReadOnlyCollection <ICategory>(categories)); storyRepository.Expect(r => r.CountByCategory(It.IsAny <Guid>())).Returns(5); List <ITag> tags = new List <ITag>(); for (int i = 1; i <= settings.Object.TopTags; i++) { var tag = new Mock <ITag>(); tag.ExpectGet(t => t.UniqueName).Returns("Tag {0}".FormatWith(i)); tags.Add(tag.Object); } tagRepository.Expect(r => r.FindByUsage(It.IsAny <int>())).Returns(new ReadOnlyCollection <ITag>(tags)); storyRepository.Expect(r => r.CountByTag(It.IsAny <Guid>())).Returns(5); _httpContext = MvcTestHelper.GetHttpContext("/Kigg", null, null); _handler = new SiteMapHandler { Settings = settings.Object, UserRepository = userRepository.Object, CategoryRepository = categoryRepository.Object, TagRepository = tagRepository.Object, StoryRepository = storyRepository.Object, PublishedStoryMaxCount = 5, UpcomingStoryMaxCount = 5, CacheDurationInMinutes = 45, Compress = true, GenerateETag = true }; }