// Summary: // Generates the poem schema. Parses the syntax rules from the file // and uses the repository objects to access the database and retrieve // the schema by id. // // Parameters: // schemaId: // The id by which to find the poem schema. // Returns: // The string containing the generated poem. public string GeneratePoem(int schemaId) { IPoemSyntaxRuleDocument doc = parser.Parse(config.SyntaxConfigFile); PoemSchema schema = poemRepository.GetSchemaById(schemaId); string generatedPoem = poemGenerator.GeneratePoem(schema, doc); return(generatedPoem); }
public void PoemSchemaGetLinesUnrecognizableSeparatorTest() { string separator = "?"; PoemSchema poemSchema = new PoemSchema(); string testSchema = String.Format("x--x-{0}-x--x{0}-x-", separator); poemSchema.Value = testSchema; string[] expectedLines = new string[] { "x--x-?-x--x?-x-" }; string[] actualLines = poemSchema.GetLines(); CollectionAssert.AreEqual(expectedLines, actualLines); }
// Summary: // Main method to generate a poem text by the poem schema and syntax rules. // // Parameters: // schema: // The schema object by which the poem should be constructed. // document: // The object which represents the syntax rules to build a poem. // Returns: // The string containing the generated poem text. The line // breaks separated by '\n' character. // Exceptions: // System.ArgumentNullException: // document is null. public string GeneratePoem(PoemSchema schema, IPoemSyntaxRuleDocument document) { if (document == null) { throw new ArgumentNullException("document", "Argument cannot be null."); } List <string> poemLines = new List <string>(); foreach (string line in schema.GetLines()) { string generatedLine = this.GeneratePoemLine(line, document); poemLines.Add(generatedLine); } return(string.Join("\n", poemLines)); }