public void IntegrationTestException() { var analyzer = new BookAnalyzer(new IntegrationLoaderWithException(new Exception("message")), new IntegrationCounter(), new IntegrationPrime(), "file"); string[] expected = { "message" }; CollectionAssert.AreEqual(expected, analyzer.Analyze().ToArray()); }
public void IntegrationTest() { var analyzer = new BookAnalyzer(new IntegrationLoader(), new IntegrationCounter(), new IntegrationPrime(), ""); string[] expected = { "Word: a, Count: 2, Prime? Yes", "Word: the, Count: 3, Prime? No", "Word: and, Count: 5, Prime? No" }; CollectionAssert.AreEqual(expected, analyzer.Analyze().ToArray()); }
public void IntegrationTestNoDir() { var analyzer = new BookAnalyzer(new IntegrationLoaderWithException(new DirectoryNotFoundException()), new IntegrationCounter(), new IntegrationPrime(), "file"); string[] expected = { "could not find directory containing file: file" }; CollectionAssert.AreEqual(expected, analyzer.Analyze().ToArray()); }
/// <summary> /// We have a bunch of tests for the computedLevel /// This function drives the test from its most direct input, the html /// We have a bunch of other public functions which generate the html for various test scenarios that can call this /// to run the core test for them /// </summary> /// <param name="html"></param> /// <param name="expectedLevel"></param> private void TestBookHtmlReturnsExpectedLevel(string html, int expectedLevel) { // Final Setup var analyzer = new BookAnalyzer(html, GetMetaData()); // System under test var computedLevel = analyzer.GetBookComputedLevel(); // Verification Assert.That(computedLevel, Is.EqualTo(expectedLevel)); }
public void GetBestXMatter_DirectoryMissingXMatterCSS_PopulatesWithDefault() { using (var tempFolder = new TemporaryFolder("BookAnalyzerTests")) { // System under test var analyzer = new BookAnalyzer(GetMonoLingualHtml(), GetMetaData(), tempFolder.FolderPath); // Verification string expectedDefault = $"<XMatterPack>Device</XMatterPack>"; Assert.That(analyzer.BloomCollection.Contains(expectedDefault), Is.True, "BloomCollection did not contain default XMatter Pack. XML: " + analyzer.BloomCollection); } }
public void GetBestXMatter_DirectoryHasXMatterCSS_PopulatesCollectionXMatterSetting(string filename, string expectedXMatterName) { using (var tempFolder = new TemporaryFolder("BookAnalyzerTests")) { var filePath = Path.Combine(tempFolder.FolderPath, filename); using (File.Create(filePath)) // TemporaryFolder takes a long time to dispose if you don't dispose this first. { // System under test var analyzer = new BookAnalyzer(GetMonoLingualHtml(), GetMetaData(), tempFolder.FolderPath); // Verification string expected = $"<XMatterPack>{expectedXMatterName}</XMatterPack>"; Assert.That(analyzer.BloomCollection.Contains(expected), Is.True, "BloomCollection did not contain expected XMatter Pack. XML: " + analyzer.BloomCollection); } } }
public ActionResult Upload(FileModel fileModel) { if (!ModelState.IsValid) { return(View("Index", fileModel)); } if (Request.Files.Count < 0) { if (!String.IsNullOrEmpty(ViewBag.ErrorMessage)) { ViewBag.ErrorMessage = "Unable to fine the file, try to select a smaller file."; return(View("Index")); } } var file = Request.Files[0]; var model = new BookAnalyzerResultModel(); var analyzer = BookAnalyzer.CreateFromFileStream(file.InputStream); //Find most frequent word occured in the book var mostFrqWord = analyzer.FindMostFrequentWord(); model.MostFrqWord = new WordModel(mostFrqWord.Text, mostFrqWord.Frequency, mostFrqWord.ScrabbleScore); //Find most frequent 7 character word occured in the book mostFrqWord = analyzer.FindMostFrequentWord(7); model.MostFrq7CharWord = new WordModel(mostFrqWord.Text, mostFrqWord.Frequency, mostFrqWord.ScrabbleScore); //Get a list of highest scoring words var words = analyzer.FindHighestScoringWords(); foreach (var word in words) { model.ListOfHighestScoreWords.Add(new WordModel(word.Text, word.Frequency, word.ScrabbleScore)); } return(View(model)); }
public void OneTimeSetUp() { // Insert the appropriate contentLanguageX/bloom-content*X information for the different types of books _trilingualAnalyzer = new BookAnalyzer(GetTriLingualHtml(), GetMetaData()); _bilingualAnalyzer = new BookAnalyzer(GetBiLingualHtml(), GetMetaData()); var monoLingualHtml = GetMonoLingualHtml(); _emptyBrandingAnalyzer = new BookAnalyzer(monoLingualHtml, GetMetaData(@"""brandingProjectName"":"""",")); _silleadBrandingAnalyzer = new BookAnalyzer(monoLingualHtml, GetMetaData(@"""brandingProjectName"":""SIL-LEAD"",")); _monolingualBookInTrilingualCollectionAnalyzer = new BookAnalyzer(monoLingualHtml, GetMetaData()); var monoLingualBookInBilingualCollectionHtml = String.Format(kHtml, kContentLanguage1Xml, "").Replace("bloom-content2 ", ""); _monolingualBookInBilingualCollectionAnalyzer = new BookAnalyzer(monoLingualBookInBilingualCollectionHtml, GetMetaData()); _twoLanguageCollection = XElement.Parse(_monolingualBookInBilingualCollectionAnalyzer.BloomCollection); _threeLanguageCollection = XElement.Parse(_monolingualBookInTrilingualCollectionAnalyzer.BloomCollection); _silleadCollection = XElement.Parse(_silleadBrandingAnalyzer.BloomCollection); _epubCheckAnalyzer = new BookAnalyzer(kHtmlUnmodifiedPages, GetMetaData()); _epubCheckAnalyzer2 = new BookAnalyzer(kHtmlModifiedPage, GetMetaData()); }
public void GetWordCount_PunctuationStartEndWords_NotSeparator(string input) { Assert.That(BookAnalyzer.GetWordCount(input), Is.EqualTo(1)); }
public void GetWordCount_PunctuationBetweenWords_CountsAsSeparator(string input) { Assert.That(BookAnalyzer.GetWordCount(input), Is.EqualTo(2)); }