public void RequestNotMatchingAnyBlog_ButWithASingleBlogInSystemWithLocalHostButNotMatchingSubfolder_ReturnsUpdatesItsHostThenRedirectsToSubfolder() { //arrange var onlyBlog = new Blog { Host = "localhost", Subfolder = "sub" }; var pagedCollection = new PagedCollection<Blog> { onlyBlog }; pagedCollection.MaxItems = 1; var repository = new Mock<ObjectRepository>(); repository.Setup(r => r.GetBlog("example.com", It.IsAny<string>())).Returns((Blog)null); repository.Setup(r => r.GetPagedBlogs(null, 0, It.IsAny<int>(), ConfigurationFlags.None)).Returns( pagedCollection); var appSettings = new NameValueCollection(); appSettings.Add("AggregateEnabled", "false"); var hostInfo = new HostInfo(appSettings); var service = new BlogLookupService(repository.Object, new LazyNotNull<HostInfo>(() => hostInfo)); var blogRequest = new BlogRequest("example.com", string.Empty, new Uri("http://example.com/foo/bar"), false); //act BlogLookupResult result = service.Lookup(blogRequest); //assert Assert.IsNull(result.Blog); Assert.IsNotNull(result.AlternateUrl); Assert.AreEqual("http://example.com/sub/foo/bar", result.AlternateUrl.ToString()); Assert.AreEqual("example.com", onlyBlog.Host); repository.Verify(r => r.UpdateBlog(It.IsAny<Blog>())); }
public void AsFlattenedEnumerable_AllowsEnumeratingAllPagesAsSingleEnumeration() { var pages = new Collection<IPagedCollection<string>>(); IPagedCollection<string> pageZero = new PagedCollection<string> { MaxItems = 8 }; pageZero.Add("zero"); pageZero.Add("one"); pageZero.Add("two"); pages.Add(pageZero); IPagedCollection<string> pageOne = new PagedCollection<string> { MaxItems = 8 }; pageOne.Add("three"); pageOne.Add("four"); pageOne.Add("five"); pages.Add(pageOne); IPagedCollection<string> pageTwo = new PagedCollection<string> { MaxItems = 8 }; pageTwo.Add("six"); pageTwo.Add("seven"); pages.Add(pageTwo); var book = new CollectionBook<string>((pageIndex, pageSize) => pages[pageIndex], 3); // act string concatenation = String.Join("", book.AsFlattenedEnumerable().ToArray()); // assert Assert.AreEqual("zeroonetwothreefourfivesixseven", concatenation); }
public void Construct_Enumeration_Contructed() { var incrementalEnumerator = new IncrementalEnumerator(0, 10); var target = new PagedCollection<IntegerAdapter>(incrementalEnumerator); var expectedCount = 10; Assert.AreEqual(expectedCount, target.Count); }
private void PrintToConsole(PagedCollection<SalesOrder> salesOrders) { Console.WriteLine("{0} sales orders found", salesOrders.TotalCount); foreach (var salesOrder in salesOrders.List) { Console.WriteLine("{0} - {1} - {2}", salesOrder.SalesOrderID, salesOrder.OrderNumber, salesOrder.Status); } }
public void PagedCollection_Unit_Constructor_Optimal() { String[] list = new String[] { "One", "Two", "Three" }; Int32 totalCount = 128; PagedCollection<String> target = new PagedCollection<String>(list, totalCount); Assert.AreEqual(totalCount, target.TotalCount); CollectionAssert.AreEquivalent(list, target); }
private void PrintToConsole(PagedCollection<Product> products) { Console.WriteLine("{0} products found", products.TotalCount); foreach (var product in products.List) { Console.WriteLine("{0} - {1} - {2}", product.ProductID, product.Code, product.Name); } }
public void Test_HtmlExtension_Pager() { var list = new PagedCollection<int>(new List<int>(), 1, 1, 2); this.Helper.HtmlHelper.Pager(list, "test"); Assert.AreEqual(331, this.Helper.ViewContext.Writer.ToString().Length); }
public void ConstructorShouldCopyProvidedSequence() { var expected = new []{ new object(), new object(), new object() }; var actual = new PagedCollection<object>( expected, 3 ); Assert.True( actual.SequenceEqual( expected ) ); actual = new PagedCollection<object>( new ObservableCollection<object>( expected ), 3 ); Assert.True( actual.SequenceEqual( expected ) ); }
public void ConstructorShouldSetTotalCount() { var expected = 3; var actual = new PagedCollection<object>( Enumerable.Empty<object>(), expected ).TotalCount; Assert.Equal( expected, actual ); actual = new PagedCollection<object>( new ObservableCollection<object>(), expected ).TotalCount; Assert.Equal( expected, actual ); }
/// <summary> /// Gets the list of calendars. /// </summary> /// <param name="offset">The offset used for paging.</param> /// <param name="limit">The limit used for paging.</param> /// <returns>An instance of <see cref="PagedCollection{Calendar}"/>.</returns> public PagedCollection<Calendar> Get(int offset = 0, int limit = 5) { PagedCollection<Calendar> result = new PagedCollection<Calendar>(); result.Items = calendars.Skip(offset).Take(limit); result.TotalCount = calendars.Count(); result.Offset = offset; result.Limit = limit; return result; }
/// <summary> /// Gets a pageable collection of log entries. /// </summary> /// <param name="pageIndex">Index of the page.</param> /// <param name="pageSize">Size of the page.</param> /// <returns></returns> public override IPagedCollection<LogEntry> GetPagedLogEntries(int pageIndex, int pageSize) { IDataReader reader = DbProvider.Instance().GetPagedLogEntries(pageIndex, pageSize); IPagedCollection<LogEntry> entries = new PagedCollection<LogEntry>(); while(reader.Read()) { entries.Add(DataHelper.LoadLogEntry(reader)); } reader.NextResult(); entries.MaxItems = DataHelper.GetMaxItems(reader); return entries; }
public void Test_HtmlExtension_Message() { var list = new PagedCollection<int>(new List<int>(), 1, 1, 2); var value = new TestValue(); value.SuccessMessage("Test"); this.Helper.HtmlHelper.Message(value); Assert.AreEqual(353, this.Helper.ViewContext.Writer.ToString().Length); }
public void CanIteratePagedCollectionsInABook() { Collection<IPagedCollection<string>> pages = new Collection<IPagedCollection<string>>(); IPagedCollection<string> pageZero = new PagedCollection<string>(); pageZero.MaxItems = 8; pageZero.Add("zero"); pageZero.Add("one"); pageZero.Add("two"); pages.Add(pageZero); IPagedCollection<string> pageOne = new PagedCollection<string>(); pageOne.MaxItems = 8; pageOne.Add("three"); pageOne.Add("four"); pageOne.Add("five"); pages.Add(pageOne); IPagedCollection<string> pageTwo = new PagedCollection<string>(); pageTwo.MaxItems = 8; pageTwo.Add("six"); pageTwo.Add("seven"); pages.Add(pageTwo); CollectionBook<string> book = new CollectionBook<string>( delegate(int pageIndex, int pageSize) { return pages[pageIndex]; }, 3); string concatenation = string.Empty; int currentPageIndex = 0; foreach(IPagedCollection<string> page in book) { concatenation += currentPageIndex; foreach(string item in page) { concatenation += item; } currentPageIndex++; } Assert.AreEqual("0zeroonetwo1threefourfive2sixseven", concatenation, "We iterated correctly."); }
public void GetBlogPosts_WithBlogHavingPosts_ReturnsAllPosts() { // arrange var blog = new Blog {Title = "Irrelevant Title", SubTitle = "Test Blog Subtitle", Author = "Charles Dickens", Host = "example.com", ModerationEnabled = true}; var posts = new PagedCollection<EntryStatsView> {new EntryStatsView { Title = "Test Post Title"}}; var context = new Mock<ISubtextContext>(); context.Setup(c => c.Blog).Returns(blog); context.Setup(c => c.UrlHelper.BlogUrl()).Returns("/"); context.Setup(c => c.Repository.GetEntriesForExport(It.IsAny<int>() /*pageIndex*/, 100 /*pageSize*/)).Returns(posts); var converter = new Mock<IBlogMLExportMapper>(); converter.Setup(c => c.ConvertEntry(It.IsAny<EntryStatsView>(), false /*embedAttachments*/)).Returns(new BlogMLPost { Title = "Test Post Title" }); var source = new BlogMLSource(context.Object, converter.Object); // act var blogMLPosts = source.GetBlogPosts(false /*embedAttachments*/); // assert Assert.AreEqual("Test Post Title", blogMLPosts.ToList().First().Title); }
public void RequestNotMatchingAnyBlog_ButWithAggregateBlogsEnabledAndActiveBlogsInTheSystem_ReturnsAggregateBlog() { //arrange var repository = new Mock<ObjectProvider>(); repository.Setup(r => r.GetBlog("example.com", It.IsAny<string>())).Returns((Blog)null); var onlyBlog = new Blog {Host = "example.com", Subfolder = "not-sub"}; var pagedCollection = new PagedCollection<Blog> {onlyBlog}; pagedCollection.MaxItems = 1; repository.Setup(r => r.GetPagedBlogs(null, 0, It.IsAny<int>(), ConfigurationFlags.None)).Returns( pagedCollection); var aggregateBlog = new Blog(); var service = new BlogLookupService(repository.Object, new HostInfo {BlogAggregationEnabled = true, AggregateBlog = aggregateBlog}); var blogRequest = new BlogRequest("example.com", string.Empty, new Uri("http://example.com/foo/bar"), false); //act BlogLookupResult result = service.Lookup(blogRequest); //assert Assert.AreSame(aggregateBlog, result.Blog); }
public void CollectionBook_WithThreePages_IteratesCorrectly() { var pages = new Collection<IPagedCollection<string>>(); IPagedCollection<string> pageZero = new PagedCollection<string> {MaxItems = 8}; pageZero.Add("zero"); pageZero.Add("one"); pageZero.Add("two"); pages.Add(pageZero); IPagedCollection<string> pageOne = new PagedCollection<string> {MaxItems = 8}; pageOne.Add("three"); pageOne.Add("four"); pageOne.Add("five"); pages.Add(pageOne); IPagedCollection<string> pageTwo = new PagedCollection<string> {MaxItems = 8}; pageTwo.Add("six"); pageTwo.Add("seven"); pages.Add(pageTwo); var book = new CollectionBook<string>((pageIndex, pageSize) => pages[pageIndex], 3); string concatenation = string.Empty; int currentPageIndex = 0; // act foreach(var page in book) { concatenation += currentPageIndex; foreach(string item in page) { concatenation += item; } currentPageIndex++; } // assert Assert.AreEqual("0zeroonetwo1threefourfive2sixseven", concatenation); }
public void GetBlogPosts_WithBlogPostHavingCategories_ReturnsPostsWithCategories() { // arrange var categories = new List<LinkCategory> { new LinkCategory(1, "Category Title"), new LinkCategory(2, "Some Other Category Title") }; var blog = new Blog { Title = "Irrelevant Title", SubTitle = "Test Blog Subtitle", Author = "Charles Dickens", Host = "example.com", ModerationEnabled = true }; var entry = new EntryStatsView {Title = "Test Post Title"}; entry.Categories.Add("Some Other Category Title"); var posts = new PagedCollection<EntryStatsView> { entry }; var context = new Mock<ISubtextContext>(); context.Setup(c => c.Blog).Returns(blog); context.Setup(c => c.UrlHelper.BlogUrl()).Returns("/"); context.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<IEntryIdentity>())).Returns("/irrelevant"); context.Setup(c => c.Repository.GetCategories(CategoryType.PostCollection, false /*activeOnly*/)).Returns(categories); context.Setup(c => c.Repository.GetEntriesForExport(It.IsAny<int>() /*pageIndex*/, 100 /*pageSize*/)).Returns(posts); var converter = new BlogMLExportMapper(context.Object); var source = new BlogMLSource(context.Object, converter); // act var blogMLPosts = source.GetBlogPosts(false /*embedAttachments*/); // assert Assert.AreEqual("2", blogMLPosts.First().Categories[0].Ref); }
/// <summary> /// Method called on Async complete /// </summary> /// <param name="statusCode"></param> /// <param name="customers"></param> /// <remarks></remarks> private void OnCustomerComplete(HttpStatusCode statusCode, PagedCollection<Customer> customers) { //Invoke the SetDataSource method on the UI thread var d = new SetCustomersCallback(SetCustomerDataSource); Invoke(d, new object[] {customers}); }
/// <summary> /// Method to set the datasource /// </summary> /// <param name="jobs">Pages collection of invoices</param> /// <remarks></remarks> private void SetJobDataSource(PagedCollection<Job> jobs) { //Fill the dropdown ColJob.DataSource = jobs.Items; ColJob.DisplayMember = "Name"; ColJob.ValueMember = "UID"; ColJob.ValueType = typeof (Guid); DoBind(); }
/// <summary> /// Method called on Async complete /// </summary> /// <param name="statusCode"></param> /// <param name="taxCodes"></param> /// <remarks></remarks> private void OnTaxCodeComplete(HttpStatusCode statusCode, PagedCollection<TaxCode> taxCodes) { //Invoke the SetDataSource method on the UI thread var d = new SetTaxCodesCallback(SetTaxCodesDataSource); Invoke(d, new object[] {taxCodes}); }
/// <summary> /// Method called on Async complete /// </summary> /// <param name="statusCode"></param> /// <param name="jobs"></param> /// <remarks></remarks> private void OnJobComplete(HttpStatusCode statusCode, PagedCollection<Job> jobs) { //Invoke the SetDataSource method on the UI thread var d = new SetJobsCallback(SetJobDataSource); Invoke(d, new object[] {jobs}); }
public void WritesProperBlogMlWithIdConversion(string firstPostConvertedId, string firstCategoryConvertedId, string firstCommentConvertedId, string firstTrackbackConvertedId, string secondPostConvertedId, string conversionType) { //Set up ids string blogId = "blah-abc-000"; string catOneId = "first-cat-id"; string catTwoId = "blah-acd"; string firstPostId = "first-post-id"; string secondPostId = "second-post-id"; string thirdPostId = "blah-blah"; string commentOneId = "first-comment-id"; string trackBackOneId = "first-trackback-id"; IdConversionStrategy conversion = IdConversionStrategy.Empty; switch(conversionType) { case "int": conversion = new IntConversionStrategy(); break; case "subtext": conversion = new SubtextConversionStrategy(); break; } int pageSize = 2; #region Create a full instance of a blog in an object hierarchy DateTime dateCreated = DateTime.Now; BlogMLBlog blog = ObjectHydrator.CreateBlogInstance("the title", "the subtitle", "http://blog.example.com/", "phil", "*****@*****.**", dateCreated); BlogMLContext context = new BlogMLContext(blogId, false); IList<BlogMLCategory> categories = new Collection<BlogMLCategory>(); categories.Add(ObjectHydrator.CreateCategoryInstance(catOneId, "category1", "Category 1 is the first", true, null, dateCreated, dateCreated)); categories.Add(ObjectHydrator.CreateCategoryInstance(catTwoId, "category2", "Category 2 is the second", true, null, dateCreated, dateCreated)); IPagedCollection<BlogMLPost> firstPage = new PagedCollection<BlogMLPost>(); firstPage.Add(ObjectHydrator.CreatePostInstance(firstPostId, "post title 1", "http://blog.example.com/post100/", true, "Nothing important 1", dateCreated, dateCreated)); firstPage[0].Categories.Add(catOneId); firstPage[0].Categories.Add(catTwoId); firstPage[0].Comments.Add(ObjectHydrator.CreateCommentInstance(commentOneId, "re: post", "http://blog.example.com/post100/#91", "You rock!", "*****@*****.**", "haacked", true, dateCreated, dateCreated)); firstPage[0].Trackbacks.Add(ObjectHydrator.CreateTrackBackInstance(trackBackOneId, "re: title", "http://another.example.com/", true, dateCreated, dateCreated)); firstPage.Add(ObjectHydrator.CreatePostInstance(secondPostId, "post title 2", "http://blog.example.com/post200/", true, "Nothing important 2", dateCreated, dateCreated)); firstPage.MaxItems = 3; IPagedCollection<BlogMLPost> secondPage = new PagedCollection<BlogMLPost>(); secondPage.Add(ObjectHydrator.CreatePostInstance(thirdPostId, "post title 3", "http://blog.example.com/post300/", true, "Nothing important 3", dateCreated, dateCreated)); secondPage.MaxItems = 3; #endregion //Now setup expectations. MockRepository mocks = new MockRepository(); IBlogMLProvider provider = (IBlogMLProvider)mocks.CreateMock(typeof(IBlogMLProvider)); Expect.Call(provider.GetBlogMlContext()).Return(context); Expect.Call(provider.IdConversion).Return(conversion); Expect.Call(provider.GetBlog(blogId)).Return(blog); Expect.Call(provider.GetAllCategories(blogId)).Return(categories); Expect.Call(provider.PageSize).Return(pageSize); Expect.Call(provider.GetBlogPosts(blogId, 0, pageSize)).Return(firstPage); Expect.Call(provider.GetBlogPosts(blogId, 1, pageSize)).Return(secondPage); mocks.ReplayAll(); //TODO: simplify when BlogML bug is fixed. StringBuilder builder = new StringBuilder(); StringWriter stringWriter = new StringWriter(builder); XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter); BlogMLWriter writer = BlogMLWriter.Create(provider); writer.Write(xmlWriter); mocks.VerifyAll(); //Verify blog. XmlDocument doc = new XmlDocument(); doc.LoadXml(builder.ToString()); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("bml", "http://www.blogml.com/2006/09/BlogML"); XmlNode firstPostNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='" + firstPostConvertedId + "']", nsmgr); Assert.IsNotNull(firstPostNode, "Could not find post node with expected converted id" + firstPostConvertedId); XmlNode secondPostNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='" + secondPostConvertedId + "']", nsmgr); Assert.IsNotNull(secondPostNode, "Could not find post node with expected converted id" + secondPostConvertedId); XmlNode firstCategoryNode = doc.SelectSingleNode("bml:blog/bml:categories/bml:category[@id='" + firstCategoryConvertedId + "']", nsmgr); Assert.IsNotNull(firstCategoryNode, "Could not find first category node with id " + firstCategoryConvertedId); XmlNode firstPostFirstCategoryNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='" + firstPostConvertedId + "']/bml:categories/bml:category[@ref='" + firstCategoryConvertedId + "']", nsmgr); Assert.IsNotNull(firstPostFirstCategoryNode, "Could not find first post category reference to first category."); XmlNode firstPostCommentsNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='" + firstPostConvertedId + "']/bml:comments/bml:comment[@id='" + firstCommentConvertedId + "']", nsmgr); Assert.IsNotNull(firstPostCommentsNode, "Could not find first comment of the first post. Expected comment to have id: " + firstCommentConvertedId); XmlNode firstPostTrackbackNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='" + firstPostConvertedId + "']/bml:trackbacks/bml:trackback[@id='" + firstTrackbackConvertedId + "']", nsmgr); Assert.IsNotNull(firstPostTrackbackNode, "Could not find trackback with id " + firstTrackbackConvertedId); }
public void WritesProperBlogMl() { //Set up ids string blogId = "8675309"; string catOneId = "1"; string catTwoId = "2"; string postOneId = "100"; string postTwoId = "200"; string postThreeId = "300"; string commentOneId = "91"; string trackBackOneId = "92"; int pageSize = 2; #region Create a full instance of a blog in an object hierarchy DateTime dateCreated = DateTime.Now; BlogMLBlog blog = ObjectHydrator.CreateBlogInstance("the title", "the subtitle", "http://blog.example.com/", "phil", "*****@*****.**", dateCreated); BlogMLContext context = new BlogMLContext(blogId, false); IList<BlogMLCategory> categories = new Collection<BlogMLCategory>(); categories.Add(ObjectHydrator.CreateCategoryInstance(catOneId, "category1", "Category 1 is the first", true, null, dateCreated, dateCreated)); categories.Add(ObjectHydrator.CreateCategoryInstance(catTwoId, "category2", "Category 2 is the second", true, null, dateCreated, dateCreated)); IPagedCollection<BlogMLPost> firstPage = new PagedCollection<BlogMLPost>(); firstPage.Add(ObjectHydrator.CreatePostInstance(postOneId, "post title 1", "http://blog.example.com/post100/", true, "Nothing important 1", dateCreated, dateCreated)); firstPage[0].Categories.Add(catOneId); firstPage[0].Categories.Add(catTwoId); firstPage[0].Comments.Add(ObjectHydrator.CreateCommentInstance(commentOneId, "re: post", "http://blog.example.com/post100/#91", "You rock!", "*****@*****.**", "haacked", true, dateCreated, dateCreated)); firstPage[0].Trackbacks.Add(ObjectHydrator.CreateTrackBackInstance(trackBackOneId, "re: title", "http://another.example.com/", true, dateCreated, dateCreated)); firstPage.Add(ObjectHydrator.CreatePostInstance(postTwoId, "post title 2", "http://blog.example.com/post200/", true, "Nothing important 2", dateCreated, dateCreated)); firstPage.MaxItems = 3; IPagedCollection<BlogMLPost> secondPage = new PagedCollection<BlogMLPost>(); secondPage.Add(ObjectHydrator.CreatePostInstance(postThreeId, "post title 3", "http://blog.example.com/post300/", true, "Nothing important 3", dateCreated, dateCreated)); secondPage.MaxItems = 3; #endregion //Now setup expectations. MockRepository mocks = new MockRepository(); IBlogMLProvider provider = (IBlogMLProvider)mocks.CreateMock(typeof(IBlogMLProvider)); Expect.Call(provider.GetBlogMlContext()).Return(context); Expect.Call(provider.IdConversion).Return(IdConversionStrategy.Empty); Expect.Call(provider.GetBlog(blogId)).Return(blog); Expect.Call(provider.GetAllCategories(blogId)).Return(categories); Expect.Call(provider.PageSize).Return(pageSize); Expect.Call(provider.GetBlogPosts(blogId, 0, pageSize)).Return(firstPage); Expect.Call(provider.GetBlogPosts(blogId, 1, pageSize)).Return(secondPage); mocks.ReplayAll(); //TODO: simplify when BlogML bug is fixed. StringBuilder builder = new StringBuilder(); StringWriter stringWriter = new StringWriter(builder); XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter); BlogMLWriter writer = BlogMLWriter.Create(provider); writer.Write(xmlWriter); mocks.VerifyAll(); //Verify blog. XmlDocument doc = new XmlDocument(); doc.LoadXml(builder.ToString()); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("bml", "http://www.blogml.com/2006/09/BlogML"); XmlNode blogNode = doc.SelectSingleNode("bml:blog", nsmgr); Assert.AreEqual("http://blog.example.com/", blogNode.Attributes["root-url"].InnerText, "The root url doesn't match."); XmlNodeList categoryNodes = doc.SelectNodes("bml:blog/bml:categories/bml:category", nsmgr); Assert.AreEqual(2, categoryNodes.Count, "Expected 2 categories"); XmlNodeList postNodes = doc.SelectNodes("bml:blog/bml:posts/bml:post", nsmgr); Assert.AreEqual(3, postNodes.Count, "Expected 3 posts"); XmlNodeList firstPostCategoryNodes = doc.SelectNodes("bml:blog/bml:posts/bml:post[@id='" + postOneId + "']/bml:categories/bml:category", nsmgr); Assert.AreEqual(2, firstPostCategoryNodes.Count, "Expected first post to have 2 categories"); XmlNodeList firstPostCommentsNodes = doc.SelectNodes("bml:blog/bml:posts/bml:post[@id='" + postOneId + "']/bml:comments/bml:comment", nsmgr); Assert.AreEqual(1, firstPostCommentsNodes.Count, "Expected first post to have 1 comment"); XmlNodeList firstPostTrackbackNodes = doc.SelectNodes("bml:blog/bml:posts/bml:post[@id='" + postOneId + "']/bml:trackbacks/bml:trackback", nsmgr); Assert.AreEqual(1, firstPostTrackbackNodes.Count, "Expected first post to have 1 trackback"); }
public void RequestWithSubfolderNotMatchingAnyBlog_ButWithAggregateBlogsEnabledAndMoreThanOneActiveBlogsInTheSystem_ReturnsNull() { //arrange var repository = new Mock<ObjectRepository>(); repository.Setup(r => r.GetBlog("example.com", It.IsAny<string>())).Returns((Blog)null); var blog1 = new Blog { Host = "example.com", Subfolder = "not-sub" }; var blog2 = new Blog { Host = "example.com", Subfolder = "not-sub-2" }; var pagedCollection = new PagedCollection<Blog> { blog1, blog2 }; pagedCollection.MaxItems = 2; repository.Setup(r => r.GetPagedBlogs(null, 0, It.IsAny<int>(), ConfigurationFlags.None)).Returns( pagedCollection); var appSettings = new NameValueCollection(); appSettings.Add("AggregateEnabled", "true"); var hostInfo = new HostInfo(appSettings); var service = new BlogLookupService(repository.Object, new LazyNotNull<HostInfo>(() => hostInfo)); var blogRequest = new BlogRequest("example.com", "blog1234", new Uri("http://example.com/foo/bar"), false); //act BlogLookupResult result = service.Lookup(blogRequest); //assert Assert.IsNull(result); }
/// <summary> /// Method to set the datasource /// </summary> /// <param name="accounts">Pages collection of invoices</param> /// <remarks></remarks> private void SetAccountDataSource(PagedCollection<Account> accounts) { //Fill the dropdown ColAccount.DataSource = accounts.Items; ColAccount.DisplayMember = "Name"; ColAccount.ValueMember = "UID"; ColAccount.ValueType = typeof (Guid); DoBind(); }
public void RequestNotMatchingAnyBlog_ButWithASingleBlogInSystemWithMatchingHostButDifferentSubfolder_RedirectsToOnlyBlog() { //arrange var onlyBlog = new Blog { Host = "example.com", Subfolder = "not-sub" }; var pagedCollection = new PagedCollection<Blog> { onlyBlog }; pagedCollection.MaxItems = 1; var repository = new Mock<ObjectRepository>(); repository.Setup(r => r.GetBlog("example.com", "sub")).Returns((Blog)null); repository.Setup(r => r.GetBlog("example.com", "not-sub")).Returns(onlyBlog); repository.Setup(r => r.GetPagedBlogs(null, 0, It.IsAny<int>(), ConfigurationFlags.None)).Returns( pagedCollection); var appSettings = new NameValueCollection(); appSettings.Add("AggregateEnabled", "false"); var hostInfo = new HostInfo(appSettings); var service = new BlogLookupService(repository.Object, new LazyNotNull<HostInfo>(() => hostInfo)); var blogRequest = new BlogRequest("example.com", "sub", new Uri("http://example.com/Subtext.Web/sub/bar"), false, RequestLocation.Blog, "/Subtext.Web"); //act BlogLookupResult result = service.Lookup(blogRequest); //assert Assert.IsNull(result.Blog); Assert.AreEqual("http://example.com/Subtext.Web/not-sub/bar", result.AlternateUrl.ToString()); }
private PagedCollection<EntryStatsView> BuildFakeCollectionNotPublished() { var coll = new PagedCollection<EntryStatsView>(); coll.Add(new EntryStatsView() { Title = "My Post Title", EntryName = "this-is-the-title", IsActive = false, Blog = new Blog() { Title = "My Blog" } }); return coll; }
public void RequestNotMatchingAnyBlog_ButWithASingleBlogInSystemWithLocalHost_ReturnsThatBlogAndUpdatesItsHost() { //arrange var onlyBlog = new Blog {Host = "localhost", Subfolder = ""}; var pagedCollection = new PagedCollection<Blog> {onlyBlog}; pagedCollection.MaxItems = 1; var repository = new Mock<ObjectProvider>(); repository.Setup(r => r.GetBlog("example.com", It.IsAny<string>())).Returns((Blog)null); repository.Setup(r => r.GetPagedBlogs(null, 0, It.IsAny<int>(), ConfigurationFlags.None)).Returns( pagedCollection); var service = new BlogLookupService(repository.Object, new HostInfo {BlogAggregationEnabled = false}); var blogRequest = new BlogRequest("example.com", string.Empty, new Uri("http://example.com/foo/bar"), false); //act BlogLookupResult result = service.Lookup(blogRequest); //assert Assert.IsNotNull(result.Blog); Assert.IsNull(result.AlternateUrl); Assert.AreEqual("example.com", result.Blog.Host); Assert.AreEqual("example.com", onlyBlog.Host); repository.Verify(r => r.UpdateBlog(It.IsAny<Blog>())); }
/// <summary> /// Method to set the datasource /// </summary> /// <param name="customers">Pages collection of invoices</param> /// <remarks></remarks> private void SetCustomerDataSource(PagedCollection<Customer> customers) { //Fill the dropdown CmboCustomer.DataSource = customers.Items; DoBind(); }
/// <summary> /// Method to set the datasource /// </summary> /// <param name="taxCodes">Pages collection of invoices</param> /// <remarks></remarks> private void SetTaxCodesDataSource(PagedCollection<TaxCode> taxCodes) { //Fill the dropdown ColTax.DataSource = taxCodes.Items; ColTax.DisplayMember = "Code"; ColTax.ValueMember = "UID"; ColJob.ValueType = typeof (Guid); DoBind(); }