|
2 | 2 | using Moq; |
3 | 3 |
|
4 | 4 | namespace EssentialCSharp.Chat.Tests; |
5 | | -// TODO: Move to editorconfig later, just moving quick |
6 | | -#pragma warning disable CA1707 // Identifiers should not contain underscores |
| 5 | + |
7 | 6 | public class MarkdownChunkingServiceTests |
8 | 7 | { |
9 | 8 | #region MarkdownContentToHeadersAndSection |
@@ -44,18 +43,12 @@ publicstaticvoid Main() // Method declaration |
44 | 43 | var sections = MarkdownChunkingService.MarkdownContentToHeadersAndSection(markdown); |
45 | 44 |
|
46 | 45 | await Assert.That(sections.Count).IsEqualTo(3); |
47 | | - var beginnerSection = sections.FirstOrDefault(s => s.Header == "Beginner Topic: What Is a Method?"); |
48 | | - await Assert.That(beginnerSection.Header).IsNotNull(); |
49 | | - await Assert.That(string.Join("\n", beginnerSection.Content)).Contains("Syntactically, a **method** in C# is a named block of code"); |
50 | | - |
51 | | - var mainMethodSection = sections.FirstOrDefault(s => s.Header == "Main Method"); |
52 | | - await Assert.That(mainMethodSection.Header).IsNotNull(); |
53 | | - await Assert.That(string.Join("\n", mainMethodSection.Content)).Contains("The location where C# programs begin execution is the **Main method**, which begins with `static void Main()`"); |
54 | | - await Assert.That(string.Join("\n", mainMethodSection.Content)).Contains("publicclass Program"); |
55 | | - |
56 | | - var advancedTopicSection = sections.FirstOrDefault(s => s.Header == "Main Method: Advanced Topic: Declaration of the Main Method"); |
57 | | - await Assert.That(advancedTopicSection.Header).IsNotNull(); |
58 | | - await Assert.That(string.Join("\n", advancedTopicSection.Content)).Contains("C# requires that the Main method return either `void` or `int`"); |
| 46 | + await Assert.That(sections).Contains(s => s.Header == "Beginner Topic: What Is a Method?" && string.Join("\n", s.Content).Contains("Syntactically, a **method** in C# is a named block of code")); |
| 47 | + |
| 48 | + await Assert.That(sections).Contains(s => s.Header == "Main Method" && string.Join("\n", s.Content).Contains("The location where C# programs begin execution is the **Main method**, which begins with `static void Main()`")); |
| 49 | + await Assert.That(sections).Contains(s => s.Header == "Main Method" && string.Join("\n", s.Content).Contains("publicclass Program")); |
| 50 | + |
| 51 | + await Assert.That(sections).Contains(s => s.Header == "Main Method: Advanced Topic: Declaration of the Main Method" && string.Join("\n", s.Content).Contains("C# requires that the Main method return either `void` or `int`")); |
59 | 52 | } |
60 | 53 |
|
61 | 54 | [Test] |
@@ -96,9 +89,7 @@ publicstaticvoid Main() |
96 | 89 |
|
97 | 90 | await Assert.That(sections.Count).IsEqualTo(2); |
98 | 91 | // The code listing should be appended to the Working with Variables section, not as its own section |
99 | | - var workingWithVariablesSection = sections.FirstOrDefault(s => s.Header == "Working with Variables"); |
100 | | - await Assert.That(workingWithVariablesSection.Header).IsNotNull().And.IsNotEmpty(); |
101 | | - await Assert.That(string.Join("\n", workingWithVariablesSection.Content)).Contains("publicclass MiracleMax"); |
| 92 | + await Assert.That(sections).Contains(s => s.Header == "Working with Variables" && string.Join("\n", s.Content).Contains("publicclass MiracleMax")); |
102 | 93 | await Assert.That(sections).DoesNotContain(s => s.Header == "Listing 1.12: Declaring and Assigning a Variable"); |
103 | 94 | } |
104 | 95 |
|
@@ -153,25 +144,15 @@ publicstaticvoid Main() |
153 | 144 | var sections = MarkdownChunkingService.MarkdownContentToHeadersAndSection(markdown); |
154 | 145 | await Assert.That(sections.Count).IsEqualTo(5); |
155 | 146 |
|
156 | | - var beginnerDataTypeSection = sections.FirstOrDefault(s => s.Header == "Beginner Topic: What Is a Data Type?"); |
157 | | - await Assert.That(beginnerDataTypeSection.Header).IsNotNull(); |
158 | | - await Assert.That(string.Join("\n", beginnerDataTypeSection.Content)).Contains("The type of data that a variable declaration specifies is called a **data type**"); |
| 147 | + await Assert.That(sections).Contains(s => s.Header == "Beginner Topic: What Is a Data Type?" && string.Join("\n", s.Content).Contains("The type of data that a variable declaration specifies is called a **data type**")); |
159 | 148 |
|
160 | | - var declaringSection = sections.FirstOrDefault(s => s.Header == "Declaring a Variable"); |
161 | | - await Assert.That(declaringSection.Header).IsNotNull(); |
162 | | - await Assert.That(string.Join("\n", declaringSection.Content)).Contains("In Listing 1.12, `string max` is a variable declaration"); |
| 149 | + await Assert.That(sections).Contains(s => s.Header == "Declaring a Variable" && string.Join("\n", s.Content).Contains("In Listing 1.12, `string max` is a variable declaration")); |
163 | 150 |
|
164 | | - var declaringAnotherSection = sections.FirstOrDefault(s => s.Header == "Declaring a Variable: Declaring another thing"); |
165 | | - await Assert.That(declaringAnotherSection.Header).IsNotNull(); |
166 | | - await Assert.That(string.Join("\n", declaringAnotherSection.Content)).Contains("Because a multivariable declaration statement allows developers to provide the data type only once"); |
| 151 | + await Assert.That(sections).Contains(s => s.Header == "Declaring a Variable: Declaring another thing" && string.Join("\n", s.Content).Contains("Because a multivariable declaration statement allows developers to provide the data type only once")); |
167 | 152 |
|
168 | | - var assigningSection = sections.FirstOrDefault(s => s.Header == "Assigning a Variable"); |
169 | | - await Assert.That(assigningSection.Header).IsNotNull(); |
170 | | - await Assert.That(string.Join("\n", assigningSection.Content)).Contains("After declaring a local variable, you must assign it a value before reading from it."); |
| 153 | + await Assert.That(sections).Contains(s => s.Header == "Assigning a Variable" && string.Join("\n", s.Content).Contains("After declaring a local variable, you must assign it a value before reading from it.")); |
171 | 154 |
|
172 | | - var continuedLearningSection = sections.FirstOrDefault(s => s.Header == "Assigning a Variable: Continued Learning"); |
173 | | - await Assert.That(continuedLearningSection.Header).IsNotNull(); |
174 | | - await Assert.That(string.Join("\n", continuedLearningSection.Content)).Contains("From this listing, observe that it is possible to assign a variable as part of the variable declaration"); |
| 155 | + await Assert.That(sections).Contains(s => s.Header == "Assigning a Variable: Continued Learning" && string.Join("\n", s.Content).Contains("From this listing, observe that it is possible to assign a variable as part of the variable declaration")); |
175 | 156 | } |
176 | 157 | #endregion MarkdownContentToHeadersAndSection |
177 | 158 |
|
@@ -205,10 +186,7 @@ public async Task ProcessSingleMarkdownFile_ProducesExpectedChunksAndHeaders() |
205 | 186 | await Assert.That(result.FilePath).IsEqualTo(filePath); |
206 | 187 | await Assert.That(string.Join("\n", result.Chunks)).Contains("This is the first section."); |
207 | 188 | await Assert.That(string.Join("\n", result.Chunks)).Contains("Console.WriteLine(\"Hello World\");"); |
208 | | - await Assert.That(string.Join("\n", result.Chunks)).Contains("This is the second section."); |
209 | 189 | await Assert.That(result.Chunks).Contains(c => c.Contains("This is the second section.")); |
210 | 190 | } |
211 | 191 | #endregion ProcessSingleMarkdownFile |
212 | 192 | } |
213 | | - |
214 | | -#pragma warning restore CA1707 // Identifiers should not contain underscores |
0 commit comments