public void CreatesExpectedGrid() { WordSearchMoreOrLess wordSearch = new WordSearchMoreOrLess(); wordSearch.RandomGeneratorSeed = 42; wordSearch.Size = 5; wordSearch.Grid = new List <string>() { "sep__", "tsas_", "erie_", "wona_", "_htt_", }; var expectedGrid = new List <string>() { "sepdd", "tsasn", "eriee", "wonag", "rhtts", }; wordSearch.FillInRemainingGrid(); Assert.AreEqual(expectedGrid, wordSearch.Grid); }
public void WithSpecialCharacter_ReturnsExpectedResult(bool includeSolution) { const string HTML_DIRECTORY = @"html\WordSearchMoreOrLess\"; string SOURCE_DIRECTORY = ConfigurationManager.AppSettings["SourceDirectory"] + "WordSearchMoreOrLess"; var puzzle = new WordSearchMoreOrLess(); puzzle.RandomGeneratorSeed = 42; puzzle.Size = 6; puzzle.SetSolution("pens"); puzzle.FillInRemainingGrid(); string generatedHtml = puzzle.FormatHtmlForGoogle(includeSolution); var actualFileName = "actualExample1.html"; if (includeSolution) { actualFileName = "actualExampleWithSolution1.html"; } File.WriteAllText(HTML_DIRECTORY + actualFileName, generatedHtml); var expectedFileName = "expectedExample1.html"; if (includeSolution) { expectedFileName = "expectedExampleWithSolution1.html"; } string[] expectedLines = new[] { " " };// need to have something to be different from generated file. if (File.Exists(HTML_DIRECTORY + expectedFileName)) { expectedLines = File.ReadAllLines(HTML_DIRECTORY + expectedFileName); } var actualLines = File.ReadAllLines(HTML_DIRECTORY + actualFileName); bool anyLinesDifferent = false; for (var index = 0; index < expectedLines.Length; index++) { string expectedLine = expectedLines[index]; string actualLine = "End of file already reached."; if (index >= 0 && actualLines.Length > index) { actualLine = actualLines[index]; } if (!expectedLine.Equals(actualLine, StringComparison.InvariantCultureIgnoreCase)) { anyLinesDifferent = true; Console.WriteLine($"Expected Line {index}:{expectedLine}"); Console.WriteLine($" Actual Line {index}:{actualLine}"); } } if (anyLinesDifferent) { Console.WriteLine("Updating source file. Will show up as a difference in source control."); File.WriteAllLines(SOURCE_DIRECTORY + $@"\{expectedFileName}", actualLines); } Assert.IsFalse(anyLinesDifferent, "Didn't expect any lines to be different."); }