public void CreateFlexiTableBlock_ThrowsOptionsExceptionIfTypeIsNotUnresponsiveAndTableHasMultipleHeaderRows(FlexiTableType dummyType,
                                                                                                                     Row[] dummyRows)
        {
            // Arrange
            const int      dummyNumColumns        = 6;
            var            dummyColumnDefinitions = new List <ColumnDefinition>();
            var            dummyAttributes        = new ReadOnlyDictionary <string, string>(new Dictionary <string, string>());
            BlockProcessor dummyBlockProcessor    = MarkdigTypesFactory.CreateBlockProcessor();
            var            dummyProxyTableBlock   = new ProxyTableBlock(null);

            foreach (Row row in dummyRows)
            {
                dummyProxyTableBlock.Rows.Add(row);
            }
            dummyProxyTableBlock.ColumnDefinitions = dummyColumnDefinitions;
            dummyProxyTableBlock.NumColumns        = dummyNumColumns;
            Mock <FlexiTableBlockFactory> mockTestSubject = CreateMockFlexiTableBlockFactory();

            mockTestSubject.CallBase = true;
            mockTestSubject.
            Setup(t => t.CreateFlexiTableRowBlock(dummyType, It.IsAny <BlockProcessor>(), dummyColumnDefinitions, dummyNumColumns, 0, dummyRows[0], dummyRows[0].IsHeaderRow)).
            Returns(new FlexiTableRowBlock(true));

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => mockTestSubject.Object.CreateFlexiTableBlock(default, dummyType, dummyAttributes, dummyProxyTableBlock, dummyBlockProcessor));
        public void ResolveLocalAbsolutePath_ThrowsOptionsExceptionIfUnableToRetrieveFilesFromLocalMediaDirectory()
        {
            // Arrange
            const string dummyLocalMediaDirectory = "file:///host/dummy/local/images"; // /dummy/local/images isn't considered absolute on windows and c:/dummy/local/images isn't considered absolute on linux
            const string dummyFileName            = "dummyFileName";
            Mock <IDummyMediaBlockExtensionOptions> mockMediaBlockExtensionOptions = _mockRepository.Create <IDummyMediaBlockExtensionOptions>();

            mockMediaBlockExtensionOptions.Setup(m => m.LocalMediaDirectory).Returns(dummyLocalMediaDirectory);
            var dummyException = new Exception();
            Mock <IDirectoryService> mockDirectoryService = _mockRepository.Create <IDirectoryService>();

            mockDirectoryService.
            Setup(d => d.GetFiles(new Uri(dummyLocalMediaDirectory).AbsolutePath, dummyFileName, SearchOption.AllDirectories)).
            Throws(dummyException);
            ExposedMediaBlockFactory testSubject = CreateExposedMediaBlockFactory(directoryService: mockDirectoryService.Object);

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => testSubject.ExposedResolveLocalAbsolutePath(true,
                                                                                                                         dummyFileName,
                                                                                                                         mockMediaBlockExtensionOptions.Object));

            _mockRepository.VerifyAll();
            Assert.Same(dummyException, result.InnerException);
            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(IDummyMediaBlockExtensionOptions.LocalMediaDirectory),
                                       string.Format(Strings.OptionsException_Shared_UnableToRetrieveFilesFromDirectory, dummyLocalMediaDirectory)),
                         result.Message);
        }
Example #3
0
        public void Constructor_ThrowsOptionsExceptionIfStartAndEndLinesAreAnInvalidCombination(int dummyStartLine, int dummyEndLine)
        {
            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => new LineRange(dummyStartLine, dummyEndLine));

            Assert.Equal(string.Format(Strings.OptionsException_LineRange_EndLineBeStartLineOrALineAfterIt, dummyStartLine, dummyEndLine), result.Message);
        }
        public void ResolveLocalAbsolutePath_ThrowsOptionsExceptionIfMultipleFilesAreFoundInLocalMediaDirectory()
        {
            // Arrange
            const string dummyLocalMediaDirectory = "file:///host/dummy/local/images"; // /dummy/local/images isn't considered absolute on windows and c:/dummy/local/images isn't considered absolute on linux
            const string dummyFileName            = "dummyFileName";
            var          dummyRetrievedFiles      = new string[] { "dummyFile1", "dummyFile2" };
            Mock <IDummyMediaBlockExtensionOptions> mockMediaBlockExtensionOptions = _mockRepository.Create <IDummyMediaBlockExtensionOptions>();

            mockMediaBlockExtensionOptions.Setup(m => m.LocalMediaDirectory).Returns(dummyLocalMediaDirectory);
            Mock <IDirectoryService> mockDirectoryService = _mockRepository.Create <IDirectoryService>();

            mockDirectoryService.
            Setup(d => d.GetFiles(new Uri(dummyLocalMediaDirectory).AbsolutePath, dummyFileName, SearchOption.AllDirectories)).
            Returns(dummyRetrievedFiles);
            ExposedMediaBlockFactory testSubject = CreateExposedMediaBlockFactory(directoryService: mockDirectoryService.Object);

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => testSubject.ExposedResolveLocalAbsolutePath(true,
                                                                                                                         dummyFileName,
                                                                                                                         mockMediaBlockExtensionOptions.Object));

            _mockRepository.VerifyAll();
            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(IDummyMediaBlockExtensionOptions.LocalMediaDirectory),
                                       string.Format(Strings.OptionsException_Shared_MultipleFilesFoundInDirectory,
                                                     dummyRetrievedFiles.Length,
                                                     dummyFileName,
                                                     dummyLocalMediaDirectory,
                                                     string.Join("\n", dummyRetrievedFiles))),
                         result.Message,
                         ignoreLineEndingDifferences: true);
        }
        public void TryOpenBlock_ThrowsBlockExceptionIfAnExceptionIsThrownWhileCreatingTheBlock()
        {
            // Arrange
            const int      dummyLineIndex      = 6;
            const int      dummyColumn         = 3;
            const int      dummyLevel          = 1;
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Line      = new StringSlice("# Dummy");
            dummyBlockProcessor.LineIndex = dummyLineIndex;
            dummyBlockProcessor.Column    = dummyColumn;
            Mock <IFlexiSectionBlockFactory> mockFlexiSectionBlockFactory = _mockRepository.Create <IFlexiSectionBlockFactory>();
            var dummyOptionsException = new OptionsException();
            Mock <ExposedFlexiSectionBlockParser> mockTestSubject = CreateMockExposedFlexiSectionBlockParser(mockFlexiSectionBlockFactory.Object);

            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.DiscardRedundantCharacters(dummyLevel, dummyBlockProcessor));
            mockFlexiSectionBlockFactory.Setup(f => f.Create(dummyLevel, dummyBlockProcessor, mockTestSubject.Object)).Throws(dummyOptionsException);

            // Act and assert
            BlockException result = Assert.Throws <BlockException>(() => mockTestSubject.Object.ExposedTryOpenBlock(dummyBlockProcessor));

            _mockRepository.VerifyAll();
            Assert.Equal(string.Format(Strings.BlockException_BlockException_InvalidBlock,
                                       nameof(FlexiSectionBlock),
                                       dummyLineIndex + 1,
                                       dummyColumn,
                                       Strings.BlockException_Shared_ExceptionOccurredWhileCreatingBlock),
                         result.Message);
            Assert.Same(dummyOptionsException, result.InnerException);
        }
        public void Constructor_ThrowsOptionsExceptionIfStartNumberIsInvalid(int startNumber)
        {
            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => new NumberedLineRange(1, 1, startNumber));

            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(NumberedLineRange.StartNumber),
                                       string.Format(Strings.OptionsException_Shared_ValueMustBeIntegerGreaterThan0, startNumber)),
                         result.Message);
        }
        public void Constructor_ThrowsOptionsExceptionIfCollapseIsNotInTheExpectedRange(float dummyCollapse)
        {
            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => new Clipping(collapse: dummyCollapse));

            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(Clipping.Collapse),
                                       string.Format(Strings.OptionsException_Shared_ValueMustBeWithinRange, dummyCollapse, "[0, 1]")),
                         result.Message,
                         ignoreLineEndingDifferences: true);
        }
Example #8
0
        public void ValidateSortedLineNumbers_ThrowsOptionsExceptionIfNumberedLineRangesOverlap(List <NumberedLineRange> dummyLineNumbers,
                                                                                                string expectedExceptionMessage)
        {
            // Arrange
            FlexiCodeBlockFactory testSubject = CreateFlexiCodeBlockFactory();

            // Act
            OptionsException result = Assert.
                                      Throws <OptionsException>(() => testSubject.ValidateSortedLineNumbers(new ReadOnlyCollection <NumberedLineRange>(dummyLineNumbers), 100));

            // Assert
            Assert.Equal(expectedExceptionMessage, result.Message);
        }
Example #9
0
        public void Constructor_ThrowsOptionsExceptionIfStartLineIs0()
        {
            // Arrange
            const int dummyStartLine = 0;

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => new LineRange(dummyStartLine));

            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(LineRange.StartLine),
                                       string.Format(Strings.OptionsException_Shared_InvalidValue,
                                                     dummyStartLine)),
                         result.Message);
        }
        public void GetPhrases_ThrowsOptionsExceptionIfIncludedMatchIndexIsOutOfRange()
        {
            const string dummyText    = "1 1 1";
            var          dummyPhrases = new List <Phrase>();
            var          testSubject  = new PhraseGroup("1", new int[] { 3 });

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => testSubject.GetPhrases(dummyText, dummyPhrases));

            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(PhraseGroup.IncludedMatches),
                                       string.Format(Strings.OptionsException_PhraseGroup_IncludedMatchIndexOutOfRange, testSubject, 3, 3)),
                         result.Message);
        }
        public void Constructor_ThrowsOptionsExceptionIfDedentIsNegative()
        {
            // Arrange
            const int dummyDedent = -1;

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => new Clipping(dedent: dummyDedent));

            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(Clipping.Dedent),
                                       string.Format(Strings.OptionsException_Shared_ValueMustNotBeNegative, dummyDedent)),
                         result.Message,
                         ignoreLineEndingDifferences: true);
        }
Example #12
0
        public void ValidateSyntaxHighlighter_ThrowsOptionsExceptionIfSyntaxHighlighterIsInvalid()
        {
            // Arrange
            FlexiCodeBlockFactory   testSubject            = CreateFlexiCodeBlockFactory();
            const SyntaxHighlighter dummySyntaxHighlighter = (SyntaxHighlighter)9;

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => testSubject.ValidateSyntaxHighlighter(dummySyntaxHighlighter));

            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(IFlexiCodeBlockOptions.SyntaxHighlighter),
                                       string.Format(Strings.OptionsException_Shared_ValueMustBeAValidEnumValue, dummySyntaxHighlighter,
                                                     nameof(SyntaxHighlighter))),
                         result.Message);
        }
Example #13
0
        internal virtual int NormalizeCiteLinkIndex(int numLinks, FlexiQuoteBlock flexiQuoteBlock)
        {
            int citeLinkIndex           = flexiQuoteBlock.CiteLink;
            int normalizedCiteLinkIndex = citeLinkIndex < 0 ? numLinks + citeLinkIndex : citeLinkIndex;

            if (normalizedCiteLinkIndex < 0 || normalizedCiteLinkIndex > numLinks - 1)
            {
                var optionsException = new OptionsException(nameof(IFlexiQuoteBlockOptions.CiteLink),
                                                            string.Format(Strings.OptionsException_FlexiQuoteBlockFactory_UnableToNormalize, citeLinkIndex, numLinks));

                throw new BlockException(flexiQuoteBlock, innerException: optionsException);
            }

            return(normalizedCiteLinkIndex);
        }
Example #14
0
        public void GetNormalizedStartAndEndLines_ThrowsOptionsExceptionIfNormalizedStartAndEndLinesAreAnInvalidCombination(int dummyStartLine,
                                                                                                                            int dummyEndLine,
                                                                                                                            int dummyNumLines,
                                                                                                                            int expectedNormalizedStartLine,
                                                                                                                            int expectedNormalizedEndLine)
        {
            // Arrange
            var testSubject = new LineRange(dummyStartLine, dummyEndLine);

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => testSubject.GetNormalizedStartAndEndLines(dummyNumLines));

            Assert.Equal(string.Format(Strings.OptionsException_LineRange_UnableToNormalize, testSubject, dummyNumLines, expectedNormalizedStartLine, expectedNormalizedEndLine),
                         result.Message);
        }
Example #15
0
        public void ValidateElement_ThrowsOptionsExceptionIfElementIsInvalid()
        {
            // Arrange
            FlexiSectionBlockFactory       testSubject  = CreateFlexiSectionBlockFactory();
            const SectioningContentElement dummyElement = (SectioningContentElement)9;

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => testSubject.ValidateElement(dummyElement));

            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(IFlexiSectionBlockOptions.Element),
                                       string.Format(Strings.OptionsException_Shared_ValueMustBeAValidEnumValue, dummyElement,
                                                     nameof(SectioningContentElement))),
                         result.Message);
        }
        public void ValidateType_ThrowsOptionsExceptionIfTypeIsInvalid()
        {
            // Arrange
            FlexiTableBlockFactory testSubject = CreateFlexiTableBlockFactory();
            const FlexiTableType   dummyType   = (FlexiTableType)9;

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => testSubject.ValidateType(dummyType));

            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(IFlexiTableBlockOptions.Type),
                                       string.Format(Strings.OptionsException_Shared_ValueMustBeAValidEnumValue, dummyType,
                                                     nameof(FlexiTableType))),
                         result.Message);
        }
        public void ValidateDefaultCardOptions_ThrowsOptionsExceptionIfDefaultCardOptionsIsNull()
        {
            // Arrange
            Mock <IFlexiCardsBlockOptions> mockFlexiCardsBlockOptions = _mockRepository.Create <IFlexiCardsBlockOptions>();

            mockFlexiCardsBlockOptions.Setup(f => f.DefaultCardOptions).Returns((IFlexiCardBlockOptions)null);
            FlexiCardsBlockFactory testSubject = CreateFlexiCardsBlockFactory();

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => testSubject.ValidateDefaultCardOptions(mockFlexiCardsBlockOptions.Object));

            _mockRepository.VerifyAll();
            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(IFlexiCardsBlockOptions.DefaultCardOptions),
                                       Strings.OptionsException_Shared_ValueMustNotBeNull),
                         result.Message);
        }
        public void ValidateSrcAndResolveFileName_ThrowsOptionsExceptionIfSrcDoesNotPointToAFile(string dummySrc)
        {
            // Arrange
            Mock <IDummyMediaBlockOptions> mockMediaBlockOptions = _mockRepository.Create <IDummyMediaBlockOptions>();

            mockMediaBlockOptions.Setup(m => m.Src).Returns(dummySrc);
            ExposedMediaBlockFactory testSubject = CreateExposedMediaBlockFactory();

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => testSubject.ExposedValidateSrcAndResolveFileName(mockMediaBlockOptions.Object));

            _mockRepository.VerifyAll();
            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(IDummyMediaBlockOptions.Src),
                                       string.Format(Strings.OptionsException_Shared_ValueMustPointToAFile, dummySrc)),
                         result.Message);
        }
        public void ResolveLocalAbsolutePath_ThrowsOptionsExceptionIfLocalMediaDirectorySchemeIsNotFile(string dummyLocalMediaDirectory, string dummyScheme)
        {
            // Arrange
            Mock <IDummyMediaBlockExtensionOptions> mockMediaBlockExtensionOptions = _mockRepository.Create <IDummyMediaBlockExtensionOptions>();

            mockMediaBlockExtensionOptions.Setup(m => m.LocalMediaDirectory).Returns(dummyLocalMediaDirectory);
            ExposedMediaBlockFactory testSubject = CreateExposedMediaBlockFactory();

            // Act and assert
            OptionsException result = Assert.Throws <OptionsException>(() => testSubject.ExposedResolveLocalAbsolutePath(true,
                                                                                                                         null,
                                                                                                                         mockMediaBlockExtensionOptions.Object));

            _mockRepository.VerifyAll();
            Assert.Equal(string.Format(Strings.OptionsException_OptionsException_InvalidOption,
                                       nameof(IDummyMediaBlockExtensionOptions.LocalMediaDirectory),
                                       string.Format(Strings.OptionsException_Shared_ValueMustBeAUriWithASupportedScheme, dummyLocalMediaDirectory, dummyScheme, "FILE")),
                         result.Message);
        }