Esempio n. 1
0
        public void GetLinksForUserTest()
        {
            /* *** Stage 1 ************************************************** */

            /* Initialization */
            UserProfile user = testUtil.CreateTestUser();

            Link link  = testUtil.CreateTestLink(user, testUtil.TestData.movie1Id);
            Link link2 = testUtil.CreateTestLinkTwo(user, testUtil.TestData.movie1Id);

            /* Use case */
            ListBlock <LinkDetails> actual = linkService.GetLinksForUser(user.userId, 0, 10);

            /* Check */
            Assert.AreEqual(2, actual.Count);
            testUtil.AssertMatch(link2, actual[0]);
            testUtil.AssertMatch(link, actual[1]);
            Assert.IsTrue(actual[0].Date.CompareTo(actual[1].Date) > 0); // First element [0] is newer than second [1], if comparison > 0

            /* *** Stage 2 ************************************************** */

            /* Initialization */
            Link link3 = testUtil.CreateTestLinkThree(user, testUtil.TestData.movie1Id);

            /* Use case */
            actual = linkService.GetLinksForUser(user.userId, 0, 2);

            /* Check */
            Assert.AreEqual(2, actual.Count);
            testUtil.AssertMatch(link3, actual[0]);
            testUtil.AssertMatch(link2, actual[1]);
            Assert.IsTrue(actual[0].Date.CompareTo(actual[1].Date) > 0); // First element [0] is newer than second [1], if [0] - [1] > 0
        }
Esempio n. 2
0
        private View Render(ListBlock block)
        {
            var views = new List <View>();

            for (int i = 0; i < block.Count(); i++)
            {
                var item = block.ElementAt(i);

                views.AddRange(Render(item));
            }

            View list;

            if (block.IsOrdered)
            {
                list = OrderedListTemplate.CreateContent() as View;
            }
            else
            {
                list = UnorderedListTemplate.CreateContent() as View;
            }

            list.BindingContext = new Templates.ListAstNode
            {
                Views = views
            };

            return(list);
        }
Esempio n. 3
0
        private OpenXmlElement[] ConvertListBlock(ListBlock listBlock, int numberingId, int nestLevel)
        {
            if (Manipulator.NumberingManager.IsOutsideOfListNumberingId(numberingId))
            {
                numberingId = Manipulator.NumberingManager.AddNumberingDefinition();
            }

            var oxmlElements = new List <OpenXmlElement>();

            foreach (ListItemBlock listItemBlock in listBlock)
            {
                if (listItemBlock.Count > 0)
                {
                    // The paragraph of the list item itself.
                    oxmlElements.Add(CreateListItemElement((ParagraphBlock)listItemBlock[0], numberingId, nestLevel, listBlock.BulletType));

                    // The nested blocks.
                    for (int i = 1; i < listItemBlock.Count; i++)
                    {
                        if (listItemBlock[i].GetType() == typeof(ListBlock))
                        {
                            oxmlElements.AddRange(ConvertBlock(listItemBlock[i], numberingId, nestLevel + 1));
                        }
                        else
                        {
                            oxmlElements.AddRange(ConvertBlock(listItemBlock[i], numberingId, nestLevel));
                        }
                    }
                }
            }

            return(oxmlElements.ToArray());
        }
Esempio n. 4
0
        public List <Paragraph> ParseList(ListBlock block, int indent = 0, int numbering = -1)
        {
            List <Paragraph> result = new List <Paragraph>();

            if (numbering == -1)
            {
                numbering = this.InsertNewNumbering();
            }

            ListBlock b = block as ListBlock;

            foreach (var item in b)
            {
                ListItemBlock li = item as ListItemBlock;

                if (li.First() is ParagraphBlock)
                {
                    Paragraph p = this.ParseParagaph(li.First() as ParagraphBlock);
                    this.ChangeToListItem(p, numbering, indent);
                    result.Add(p);

                    if (li.Count > 1 && li[1] is ListBlock)
                    {
                        result.AddRange(this.ParseList(li[1] as ListBlock, indent + 1, numbering));
                    }
                }
            }

            return(result);
        }
Esempio n. 5
0
        void Render(ListBlock block)
        {
            var listTheme = block.IsOrdered ? Theme.OrderedList : Theme.UnorderedList;

            var initialStack = stack;

            stack = new StackLayout()
            {
                Spacing = listTheme.ItemsVerticalSpacing,
                Margin  = listTheme.ListMargin,
            };

            var itemsCount = block.Count();

            for (var i = 0; i < itemsCount; i++)
            {
                var item = block.ElementAt(i);

                if (item is ListItemBlock itemBlock)
                {
                    Render(block, listTheme, i + 1, itemBlock);
                }
            }

            initialStack.Children.Add(stack);

            stack = initialStack;
        }
Esempio n. 6
0
        /// <summary>
        /// Convert a Markdown element to a Forkdown one.
        /// </summary>
        /// <param name="mdo">Markdown object to convert.</param>
        public static Element ToForkdown(IMarkdownObject mdo)
        {
            Element result = mdo switch {
                MarkdownDocument _ => new Document(),
                HeadingBlock h => new Heading(h),
                ListBlock l => new Listing(l),
                ListItemBlock li => new ListItem(li),
                ParagraphBlock p => new Paragraph(p),
                CustomContainer c => new Section(c),
                CustomContainerInline c => new ExplicitInlineContainer(c),
                CodeInline c => new Code(c),
                FencedCodeBlock c => new CodeBlock(c),
                LinkInline l => new Link(l),
                LiteralInline t => new Text(t),
                LineBreakInline _ => new LineBreak(),
                ThematicBreakBlock _ => new Separator(),
                Tables.Table t => new Table(t),
                Tables.TableRow tr => new TableRow(tr),
                Tables.TableCell tc => new TableCell(tc),
                EmphasisInline e => new Emphasis(e),
                HtmlBlock b => new Html(b),
                _ => new Placeholder(mdo),
            };

            var subs = mdo switch {
                LeafBlock b => b.Inline,
                IEnumerable <MarkdownObject> e => e,
                _ => null
            } ?? Nil.E <MarkdownObject>();
        private static void WriteList(ListBlock list, int intentLevel = 1)
        {
            int.TryParse(list.OrderedStart, out int index);
            intentLevel = Math.Max(intentLevel, 1);
            bool needNewLine = false;

            foreach (Block item in list)
            {
                if (needNewLine)
                {
                    SysConsole.WriteLine();
                }

                switch (item)
                {
                case ListItemBlock listItem:
                    MarkdownConsole.WriteListItemBullet(
                        list.IsOrdered
                                ? $"{index++}{list.OrderedDelimiter}"
                                : GetListItemBullet(intentLevel),
                        intentLevel);
                    WriteBlockContainer(listItem);
                    needNewLine = true;
                    break;

                case ListBlock childList:
                    WriteList(childList, intentLevel + 1);
                    needNewLine = true;
                    break;
                }
            }
        }
Esempio n. 8
0
        private RepositoryIndex ImportIndex(DirectoryInfo currentPath, MarkdownDocument document)
        {
            RepositoryIndex index = new RepositoryIndex();

            index.Name = currentPath.Name;

            foreach (var ii in document)
            {
                ListBlock list = ii as ListBlock;

                if (list != null)
                {
                    foreach (ListItemBlock jj in list)
                    {
                        var link = ImportIndexEntry(currentPath, jj);

                        if (link != null)
                        {
                            index.Children.Add(link);
                        }
                    }
                }
            }

            return(index);
        }
Esempio n. 9
0
        public void SetReportedLinkAsReadTest()
        {
            /* *** Stage 1 ************************************************** */

            /* Initialization */
            UserProfile user  = testUtil.CreateTestUser();
            UserProfile user2 = testUtil.CreateTestUserTwo();

            Link link  = testUtil.CreateTestLink(user, testUtil.TestData.movie1Id);
            Link link2 = testUtil.CreateTestLinkTwo(user, testUtil.TestData.movie1Id);

            testUtil.CreateTestRating(user2, link, -1);
            testUtil.CreateTestRating(user2, link2, -1);

            /* Check */
            ListBlock <Link> reportedLinks = testUtil.LinkDao.ListForUserReported(user.userId, testUtil.TestData.linkReportThreshold, 0, 10);

            Assert.AreNotEqual(true, link.reportRead);
            Assert.AreEqual(2, reportedLinks.Count);
            Assert.AreEqual(link, reportedLinks[0]);
            Assert.AreEqual(link2, reportedLinks[1]);

            /* *** Stage 2 ************************************************** */

            /* Use case */
            linkService.SetReportedLinkAsRead(user.userId, link.linkId);

            /* Check */
            reportedLinks = testUtil.LinkDao.ListForUserReported(user.userId, testUtil.TestData.linkReportThreshold, 0, 10);
            Assert.AreEqual(true, link.reportRead);
            Assert.AreEqual(1, reportedLinks.Count);
            Assert.AreEqual(link2, reportedLinks[0]);
        }
Esempio n. 10
0
        private static ListItemBlock FindArgument(ListBlock arguments, string argumentName)
        {
            foreach (var block in arguments)
            {
                if (block is not ListItemBlock listItem)
                {
                    continue;
                }

                if (listItem.Count == 0 || listItem.First() is not ParagraphBlock listItemParagraph)
                {
                    continue;
                }

                if (listItemParagraph.Inline.Count() < 1 || listItemParagraph.Inline.ElementAt(0) is not CodeInline argumentNameInline)
                {
                    continue;
                }

                if (argumentNameInline.Content.ToString() != argumentName)
                {
                    continue;
                }

                return(listItem);
            }

            throw new Exception($"GitHub wiki does not contain argument with name \"{argumentName}\"");
        }
Esempio n. 11
0
        public void GetLinksForLabelTest()
        {
            /* *** Stage 1 ************************************************** */

            /* Initialization */
            UserProfile user = testUtil.CreateTestUser();

            Link link  = testUtil.CreateTestLink(user);
            Link link2 = testUtil.CreateTestLinkTwo(user);

            /* Use case */
            ListBlock <LinkDetails> actual = linkService.GetLinksForLabel(testUtil.TestData.labelText, 0, 10);

            /* Check */
            Assert.AreEqual(0, actual.Count);

            /* *** Stage 2 ************************************************** */

            /* Initialization */
            Label label = testUtil.CreateTestLabel();

            testUtil.RegisterLabel(link, label);

            /* Use case */
            actual = linkService.GetLinksForLabel(label.text, 0, 10);

            /* Check */
            Assert.AreEqual(1, actual.Count);
            testUtil.AssertMatch(link, actual[0]);

            /* *** Stage 3 ************************************************** */

            /* Initialization */
            Link link3 = testUtil.CreateTestLinkThree(user);

            Label label2 = testUtil.CreateTestLabelTwo();

            testUtil.RegisterLabel(link, label2);
            testUtil.RegisterLabel(link3, label2);

            /* Use case */
            actual = linkService.GetLinksForLabel(label2.text, 0, 10);

            /* Check */
            Assert.AreEqual(2, actual.Count);
            testUtil.AssertMatch(link3, actual[0]);
            testUtil.AssertMatch(link, actual[1]);

            /* *** Stage 4 ************************************************** */

            /* Use case */
            actual = linkService.GetLinksForLabel(label.text, 0, 10);

            /* Check */
            Assert.AreEqual(1, actual.Count);
            testUtil.AssertMatch(link, actual[0]);
        }
Esempio n. 12
0
 public void Setup()
 {
     document = new MigraDocCore.DocumentObjectModel.Document();
     // Workaround for a quirk in the migradoc API.
     _           = document.AddSection().Elements;
     pdfBuilder  = new PdfBuilder(document, PdfOptions.Default);
     renderer    = new ListBlockRenderer();
     sampleBlock = CreateListBlock('-', "a list item");
 }
Esempio n. 13
0
        /// <summary>
        /// Renders a list element.
        /// </summary>
        private void RenderListElement(ListBlock element, UIElementCollection blockUIElementCollection, RenderContext context)
        {
            // Create a grid with two columns.
            Grid grid = new Grid
            {
                Margin = ListMargin
            };

            // The first column for the bullet (or number) and the second for the text.
            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(ListGutterWidth)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });

            for (int rowIndex = 0; rowIndex < element.Items.Count; rowIndex++)
            {
                var listItem = element.Items[rowIndex];

                // Add a row definition.
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });

                // Add the bullet or number.
                var bullet = CreateTextBlock(context);
                bullet.Margin = ParagraphMargin;
                switch (element.Style)
                {
                case ListStyle.Bulleted:
                    bullet.Text = "•";
                    break;

                case ListStyle.Numbered:
                    bullet.Text = $"{rowIndex + 1}.";
                    break;
                }

                bullet.HorizontalAlignment = HorizontalAlignment.Right;
                bullet.Margin = new Thickness(0, 0, ListBulletSpacing, 0);
                Grid.SetRow(bullet, rowIndex);
                grid.Children.Add(bullet);

                // Add the list item content.
                var content = new StackPanel();
                RenderBlocks(listItem.Blocks, content.Children, context);
                Grid.SetColumn(content, 1);
                Grid.SetRow(content, rowIndex);
                grid.Children.Add(content);
            }

            blockUIElementCollection.Add(grid);
        }
Esempio n. 14
0
        private Phrase Render(ListBlock parent, int index, ListItemBlock block)
        {
            var stack = new Phrase();

            var subv = this.Render(block.AsEnumerable());

            subv.ToList().ForEach(v => stack.Add(v));

            return(stack);
        }
Esempio n. 15
0
        public void GetReportedLinksForUserTest()
        {
            /* *** Stage 1 ************************************************** */

            /* Initialization */
            UserProfile user = testUtil.CreateTestUser();

            /* Use case */
            ListBlock <LinkDetails> actual = linkService.GetReportedLinksForUser(user.userId, testUtil.TestData.linkReportThreshold, 0, 10);

            /* Check */
            Assert.AreEqual(0, actual.Count);

            /* *** Stage 2 ************************************************** */

            /* Initialization */
            Link link  = testUtil.CreateTestLink(user, testUtil.TestData.movie1Id);
            Link link2 = testUtil.CreateTestLinkTwo(user, testUtil.TestData.movie1Id);

            /* Use case */
            actual = linkService.GetReportedLinksForUser(user.userId, testUtil.TestData.linkReportThreshold, 0, 10);

            /* Check */
            Assert.AreEqual(0, actual.Count);

            /* *** Stage 3 ************************************************** */

            /* Initialization */
            UserProfile user2 = testUtil.CreateTestUserTwo();

            testUtil.CreateTestRating(user2, link2, -1);

            /* Use case */
            actual = linkService.GetReportedLinksForUser(user.userId, testUtil.TestData.linkReportThreshold, 0, 10);

            /* Check */
            Assert.AreEqual(1, actual.Count);
            testUtil.AssertMatch(link2, actual[0]);

            /* *** Stage 4 ************************************************** */

            /* Initialization */
            Link link3 = testUtil.CreateTestLinkThree(user, testUtil.TestData.movie1Id);

            testUtil.CreateTestRating(user2, link3, -1);

            /* Use case */
            actual = linkService.GetReportedLinksForUser(user.userId, testUtil.TestData.linkReportThreshold, 0, 10);

            /* Check */
            Assert.AreEqual(2, actual.Count);
            testUtil.AssertMatch(link2, actual[0]);
            testUtil.AssertMatch(link3, actual[1]);
        }
Esempio n. 16
0
        public void TestBulletType(char bulletType)
        {
            ListBlock block = CreateListBlock(bulletType, "first item", "second item");

            renderer.Write(pdfBuilder, block);

            Assert.AreEqual(1, document.LastSection.Elements.Count);
            Paragraph paragraph = (Paragraph)document.LastSection.Elements[0];
            string    expected  = $" {bulletType} first item\n {bulletType} second item\n";

            Assert.AreEqual(expected, paragraph.GetRawText());
        }
Esempio n. 17
0
        public MarkdownList(ListBlock listBlock)
        {
            AutoSizeAxes     = Axes.Y;
            RelativeSizeAxes = Axes.X;

            Direction = FillDirection.Vertical;

            Spacing = new Vector2(10, 10);
            Padding = new MarginPadding {
                Left = 25, Right = 5
            };
        }
Esempio n. 18
0
        private IEnumerable <NavigationItem> ParseListBlock(ListBlock listBlock)
        {
            foreach (var listItemBlock in listBlock.OfType <ListItemBlock>())
            {
                var item = ParseListItemBlock(listItemBlock);

                if (item.Equals(default(NavigationItem)) == false)
                {
                    yield return(item);
                }
            }
        }
Esempio n. 19
0
        public void TestOrderedList()
        {
            ListBlock block = CreateOrderedListBlock("item1", "item2");

            renderer.Write(pdfBuilder, block);

            Assert.AreEqual(1, document.LastSection.Elements.Count);
            Paragraph paragraph = (Paragraph)document.LastSection.Elements[0];
            string    expected  = " 1. item1\n 2. item2\n";

            Assert.AreEqual(expected, paragraph.GetRawText());
        }
Esempio n. 20
0
        void Render(ListBlock parent, int index, ListItemBlock block)
        {
            var initialStack = stack;

            stack = new StackLayout()
            {
                Spacing = Theme.Margin,
            };

            Render(block.AsEnumerable());

            var horizontalStack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Margin      = new Thickness(listScope * Theme.Margin, 0, 0, 0),
            };

            View bullet;

            if (parent.IsOrdered)
            {
                bullet = new Label
                {
                    Text              = $"{index}.",
                    FontSize          = Theme.Paragraph.FontSize,
                    TextColor         = Theme.Paragraph.ForegroundColor,
                    VerticalOptions   = LayoutOptions.Start,
                    HorizontalOptions = LayoutOptions.End,
                    LineHeight        = Theme.Paragraph.LineHeight,
                };
            }
            else
            {
                bullet = new BoxView
                {
                    WidthRequest      = 4,
                    HeightRequest     = 4,
                    Margin            = new Thickness(0, 6, 0, 0),
                    BackgroundColor   = Theme.Paragraph.ForegroundColor,
                    VerticalOptions   = LayoutOptions.Start,
                    HorizontalOptions = LayoutOptions.Center,
                };
            }

            horizontalStack.Children.Add(bullet);


            horizontalStack.Children.Add(stack);
            initialStack.Children.Add(horizontalStack);

            stack = initialStack;
        }
Esempio n. 21
0
        public void Add(T value)
        {
            var blockFull = mainBlock.Add(value);

            //
            // Add another block
            //
            if (blockFull)
            {
                mainBlock            = new ListBlock(blockSize);
                blocks[blockIndex++] = mainBlock;
            }
        }
Esempio n. 22
0
        /* Function: GetListBlock
         * Returns a reference to the <ListBlock> associated with the tag type.  If there are any blocks already created for
         * the tag type it will be returned so new items can be added and they will always stay together in a single group.
         * If there aren't it will add a new block to the end of the list and return it.
         */
        public ListBlock GetListBlock(string type)
        {
            foreach (var block in blocks)
            {
                if (block.Type == type)
                {
                    return(block as ListBlock);
                }
            }

            ListBlock newBlock = new ListBlock(type);

            blocks.Add(newBlock);
            return(newBlock);
        }
        private IList <string> GetListItems([NotNull] ListBlock listBlock, [NotNull] string markdown)
        {
            IList <string> result = new List <string>();

            foreach (Block block in listBlock)
            {
                string entry = markdown.Substring(block.Span.Start, block.Span.Length)
                               .Substring(1)
                               .Trim();

                result.Add(entry);
            }

            return(result);
        }
Esempio n. 24
0
 public Listing(ListBlock mdo) : base(mdo)
 {
     if (mdo.IsOrdered)
     {
         this.Kind = ListingKind.Ordered;
     }
     else
     {
         this.Kind = mdo.BulletType switch {
             '+' => ListingKind.CheckItems,
             '-' => ListingKind.Items,
             _ => this.Kind
         }
     };
 }
Esempio n. 25
0
        void Render(ListBlock parent, ListStyle listTheme, int index, ListItemBlock block)
        {
            var initialStack = stack;

            stack = new StackLayout()
            {
                Spacing         = 0,
                VerticalOptions = listTheme.ItemVerticalOptions,
            };

            Render(block.AsEnumerable());
            Grid.SetColumn(stack, 1);

            var horizontalStack = new Grid
            {
                ColumnDefinitions = new ColumnDefinitionCollection {
                    new ColumnDefinition()
                    {
                        Width = GridLength.Auto
                    },
                    new ColumnDefinition()
                    {
                        Width = GridLength.Star
                    },
                },
                ColumnSpacing = listTheme.Spacing ?? Theme.Margin,
                RowSpacing    = 0,
                Margin        = new Thickness(block.Column * listTheme.Indentation, 0, 0, 0),
            };

            if (listTheme.BulletStyleType == ListStyleType.None)
            {
                horizontalStack.ColumnSpacing = 0;
            }

            var bullet = GetListBullet(listTheme, index, parent, block);

            if (bullet != null)
            {
                Grid.SetColumn(bullet, 0);
                horizontalStack.Children.Add(bullet);
            }

            horizontalStack.Children.Add(stack);
            initialStack.Children.Add(horizontalStack);

            stack = initialStack;
        }
Esempio n. 26
0
        private void Render(ListBlock block)
        {
            listScope++;

            for (int i = 0; i < block.Count(); i++)
            {
                var item = block.ElementAt(i);

                if (item is ListItemBlock itemBlock)
                {
                    this.Render(block, i + 1, itemBlock);
                }
            }

            listScope--;
        }
Esempio n. 27
0
        public void EnsureChildrenNotOnSameLine()
        {
            ListBlock block = CreateListBlock('-', "x0", "x1");

            renderer.Write(pdfBuilder, block);

            Assert.AreEqual(1, document.LastSection.Elements.Count);
            Paragraph paragraph = (Paragraph)document.LastSection.Elements[0];

            Assert.AreEqual(6, paragraph.Elements.Count);
            Character linefeed = (Character)paragraph.Elements[2];

            Assert.AreEqual(SymbolName.LineBreak, linefeed.SymbolName);
            linefeed = (Character)paragraph.Elements[5];
            Assert.AreEqual(SymbolName.LineBreak, linefeed.SymbolName);
        }
Esempio n. 28
0
        View GetListBullet(ListStyle listTheme, int index, ListBlock parent, ListItemBlock block)
        {
            if (listTheme.BulletStyleType == ListStyleType.None)
            {
                return(null);
            }

            if (listTheme.BulletStyleType == ListStyleType.Custom)
            {
                return(listTheme.CustomCallback?.Invoke(index, parent, block));
            }

            if (listTheme.BulletStyleType == ListStyleType.Decimal || listTheme.BulletStyleType == ListStyleType.Symbol)
            {
                return(new Label
                {
                    Text = listTheme.BulletStyleType == ListStyleType.Symbol ? listTheme.Symbol : $"{index}.",
                    FontSize = listTheme.BulletFontSize ?? Theme.Paragraph.FontSize,
                    TextColor = listTheme.BulletColor ?? Theme.Paragraph.ForegroundColor,
                    LineHeight = listTheme.BulletLineHeight ?? Theme.Paragraph.LineHeight,
                    FontAttributes = listTheme.BulletFontAttributes,
                    VerticalOptions = listTheme.BulletVerticalOptions,
                });
            }
            else if (listTheme.BulletStyleType == ListStyleType.Square || listTheme.BulletStyleType == ListStyleType.Circle)
            {
                var bullet = new Frame
                {
                    WidthRequest    = listTheme.BulletSize,
                    HeightRequest   = listTheme.BulletSize,
                    BackgroundColor = listTheme.BulletColor ?? Theme.Paragraph.ForegroundColor,
                    Padding         = 0,
                    HasShadow       = false,
                    VerticalOptions = listTheme.BulletVerticalOptions,
                    CornerRadius    = 0,
                };

                if (listTheme.BulletStyleType == ListStyleType.Circle)
                {
                    bullet.CornerRadius = listTheme.BulletSize / 2;
                }

                return(bullet);
            }

            return(null);
        }
Esempio n. 29
0
        /// <summary>
        /// Create an ordered list block with the given elements.
        /// </summary>
        /// <param name="contents">Contents - each element will be a list item.</param>
        private ListBlock CreateOrderedListBlock(params string[] contents)
        {
            BlockParser parser = new ListBlockParser();
            ListBlock   block  = new ListBlock(parser);

            block.IsOrdered = true;
            foreach (string item in contents)
            {
                ListItemBlock  listItem  = new ListItemBlock(parser);
                ParagraphBlock paragraph = new ParagraphBlock(new ParagraphBlockParser());
                paragraph.Inline = new ContainerInline().AppendChild(new LiteralInline(item));
                listItem.Add(paragraph);
                block.Add(listItem);
            }

            return(block);
        }
Esempio n. 30
0
        public void GetMostValuedLinksForMovieTest()
        {
            /* *** Stage 1 ************************************************** */

            /* Initialization */
            UserProfile user  = testUtil.CreateTestUser();
            UserProfile user2 = testUtil.CreateTestUserTwo();

            Link link  = testUtil.CreateTestLink(user, testUtil.TestData.movie1Id);
            Link link2 = testUtil.CreateTestLinkTwo(user, testUtil.TestData.movie1Id);

            testUtil.CreateTestRating(user2, link, -1);
            testUtil.CreateTestRating(user2, link2, 1);

            /* Use case */
            ListBlock <LinkDetails> actual = linkService.GetMostValuedLinksForMovie(testUtil.TestData.movie1Id, 0, 10);

            /* Check */
            Assert.AreEqual(2, actual.Count);
            testUtil.AssertMatch(link2, actual[0]);
            testUtil.AssertMatch(link, actual[1]);

            Assert.IsTrue(actual[0].Rating.CompareTo(actual[1].Rating) > 0); // First element [0] is greater than second [1], if [0] - [1] > 0

            /* *** Stage 2 ************************************************** */

            /* Initialization */
            UserProfile user3 = testUtil.CreateTestUserThree();

            Link link3 = testUtil.CreateTestLinkThree(user, testUtil.TestData.movie1Id);

            testUtil.CreateTestRating(user3, link, 1);
            testUtil.CreateTestRating(user3, link2, 1);
            testUtil.CreateTestRating(user3, link3, 1);

            /* Use case */
            actual = linkService.GetMostValuedLinksForMovie(testUtil.TestData.movie1Id, 1, 2);

            /* Check */
            Assert.AreEqual(2, actual.Count);
            testUtil.AssertMatch(link3, actual[0]);
            testUtil.AssertMatch(link, actual[1]);

            Assert.IsTrue(actual[0].Rating.CompareTo(actual[1].Rating) > 0); // First element [0] is greater than second [1], if [0] - [1] > 0
        }
        public void If_PreviousBlockWithHeader_ThenLastBlockContainsCorrectItems()
        {
            var testHeader = GetTestHeader();
            testHeader.PurchaseCode = "B";

            // ARRANGE
            // Create previous blocks
            using (var executionContext = CreateTaskExecutionContext())
            {
                var startedOk = executionContext.TryStart();
                if (startedOk)
                {
                    var values = GetPersonList(26);
                    short maxBlockSize = 15;
                    var listBlocks = executionContext.GetListBlocks<PersonDto, TestHeader>(x => x.WithPeriodicCommit(values, testHeader, maxBlockSize, BatchSize.Ten));

                    foreach (var listBlock in listBlocks)
                    {
                        listBlock.Start();
                        foreach (var itemToProcess in listBlock.GetItems(ItemStatus.Pending))
                            itemToProcess.Completed();

                        listBlock.Complete();
                    }
                }
            }

            var expectedPeople = GetPersonList(11, 15);
            var expectedLastBlock = new ListBlock<PersonDto>();
            foreach (var person in expectedPeople)
                expectedLastBlock.Items.Add(new ListBlockItem<PersonDto>() { Value = person });


            // ACT
            IListBlock<PersonDto, TestHeader> lastBlock = null;
            using (var executionContext = CreateTaskExecutionContext())
            {
                var startedOk = executionContext.TryStart();
                if (startedOk)
                {
                    lastBlock = executionContext.GetLastListBlock<PersonDto, TestHeader>();
                }
            }

            // ASSERT
            Assert.AreEqual(testHeader.PurchaseCode, lastBlock.Header.PurchaseCode);
            Assert.AreEqual(expectedLastBlock.Items.Count, lastBlock.Items.Count);
            Assert.AreEqual(expectedLastBlock.Items[0].Value.Id, lastBlock.Items[0].Value.Id);
            Assert.AreEqual(expectedLastBlock.Items[1].Value.Id, lastBlock.Items[1].Value.Id);
            Assert.AreEqual(expectedLastBlock.Items[2].Value.Id, lastBlock.Items[2].Value.Id);
            Assert.AreEqual(expectedLastBlock.Items[3].Value.Id, lastBlock.Items[3].Value.Id);
            Assert.AreEqual(expectedLastBlock.Items[4].Value.Id, lastBlock.Items[4].Value.Id);
            Assert.AreEqual(expectedLastBlock.Items[5].Value.Id, lastBlock.Items[5].Value.Id);
            Assert.AreEqual(expectedLastBlock.Items[6].Value.Id, lastBlock.Items[6].Value.Id);
            Assert.AreEqual(expectedLastBlock.Items[7].Value.Id, lastBlock.Items[7].Value.Id);
            Assert.AreEqual(expectedLastBlock.Items[8].Value.Id, lastBlock.Items[8].Value.Id);
            Assert.AreEqual(expectedLastBlock.Items[9].Value.Id, lastBlock.Items[9].Value.Id);
            Assert.AreEqual(expectedLastBlock.Items[10].Value.Id, lastBlock.Items[10].Value.Id);
        }