@@ -38,16 +38,32 @@ public async Task AnalyzeUrlAsync()
3838 AnalyzeResult result = operation . Value ;
3939 #endregion
4040
41+ #region Assertion:ContentUnderstandingAnalyzeUrlAsync
42+ Assert . IsNotNull ( uriSource , "URI source should not be null" ) ;
43+ Assert . IsTrue ( uriSource . IsAbsoluteUri , "URI should be absolute" ) ;
44+ Assert . IsNotNull ( operation , "Analysis operation should not be null" ) ;
45+ Assert . IsTrue ( operation . HasCompleted , "Operation should be completed" ) ;
46+ Assert . IsTrue ( operation . HasValue , "Operation should have a value" ) ;
47+ Assert . IsNotNull ( operation . GetRawResponse ( ) , "Analysis operation should have a raw response" ) ;
48+ Assert . IsTrue ( operation . GetRawResponse ( ) . Status >= 200 && operation . GetRawResponse ( ) . Status < 300 ,
49+ $ "Response status should be successful, but was { operation . GetRawResponse ( ) . Status } ") ;
50+ Console . WriteLine ( "✅ Analysis operation properties verified" ) ;
51+ Assert . IsNotNull ( result , "Analysis result should not be null" ) ;
52+ Assert . IsNotNull ( result . Contents , "Result contents should not be null" ) ;
53+ Console . WriteLine ( $ "✅ Analysis result contains { result . Contents ? . Count ?? 0 } content(s)") ;
54+ #endregion
55+
56+ #region Snippet:ContentUnderstandingExtractMarkdownFromUrl
4157 // A PDF file has only one content element even if it contains multiple pages
42- MediaContent ? content = null ;
58+ MediaContent ? content = null ;
4359 if ( result . Contents == null || result . Contents . Count == 0 )
4460 {
4561 Console . WriteLine ( "(No content returned from analysis)" ) ;
4662 }
4763 else
4864 {
4965 content = result . Contents . First ( ) ;
50- if ( ! string . IsNullOrEmpty ( content . Markdown ) )
66+ if ( ! string . IsNullOrEmpty ( content . Markdown ) )
5167 {
5268 Console . WriteLine ( content . Markdown ) ;
5369 }
@@ -56,22 +72,28 @@ public async Task AnalyzeUrlAsync()
5672 Console . WriteLine ( "(No markdown content available)" ) ;
5773 }
5874 }
75+ #endregion
5976
6077 #region Assertion:ContentUnderstandingExtractMarkdown
6178 Assert . IsNotNull ( result . Contents , "Result should contain contents" ) ;
6279 Assert . IsTrue ( result . Contents ! . Count > 0 , "Result should have at least one content" ) ;
80+ Assert . AreEqual ( 1 , result . Contents . Count , "PDF file should have exactly one content element" ) ;
6381 Assert . IsNotNull ( content , "Content should not be null" ) ;
82+ Assert . IsInstanceOf < MediaContent > ( content , "Content should be of type MediaContent" ) ;
6483 if ( content is MediaContent mediaContent )
6584 {
6685 Assert . IsNotNull ( mediaContent . Markdown , "Markdown content should not be null" ) ;
6786 Assert . IsTrue ( mediaContent . Markdown . Length > 0 , "Markdown content should not be empty" ) ;
87+ Assert . IsFalse ( string . IsNullOrWhiteSpace ( mediaContent . Markdown ) ,
88+ "Markdown content should not be just whitespace" ) ;
89+ Console . WriteLine ( $ "✅ Markdown content extracted successfully ({ mediaContent . Markdown . Length } characters)") ;
6890 }
6991 #endregion
7092
7193 // Check if this is document content to access document-specific properties
7294 if ( content is DocumentContent documentContent )
7395 {
74- Console . WriteLine ( $ "Document type: { documentContent . MimeType ?? "(unknown)" } ") ;
96+ Console . WriteLine ( $ "Document type: { documentContent . MimeType ?? "(unknown)" } ") ;
7597 Console . WriteLine ( $ "Start page: { documentContent . StartPageNumber } ") ;
7698 Console . WriteLine ( $ "End page: { documentContent . EndPageNumber } ") ;
7799 Console . WriteLine ( $ "Total pages: { documentContent . EndPageNumber - documentContent . StartPageNumber + 1 } ") ;
@@ -100,34 +122,104 @@ public async Task AnalyzeUrlAsync()
100122 }
101123 }
102124
103- #region Assertion:ContentUnderstandingAccessDocumentProperties
125+ #region Assertion:ContentUnderstandingAccessDocumentPropertiesFromUrl
126+ Assert . IsNotNull ( content , "Content should not be null for document properties validation" ) ;
127+
104128 if ( content is DocumentContent docContent )
105129 {
130+ // Validate MIME type
106131 Assert . IsNotNull ( docContent . MimeType , "MIME type should not be null" ) ;
132+ Assert . IsFalse ( string . IsNullOrWhiteSpace ( docContent . MimeType ) , "MIME type should not be empty" ) ;
133+ Assert . AreEqual ( "application/pdf" , docContent . MimeType , "MIME type should be application/pdf" ) ;
134+ Console . WriteLine ( $ "✅ MIME type verified: { docContent . MimeType } ") ;
135+
136+ // Validate page numbers
107137 Assert . IsTrue ( docContent . StartPageNumber >= 1 , "Start page should be >= 1" ) ;
108138 Assert . IsTrue ( docContent . EndPageNumber >= docContent . StartPageNumber ,
109139 "End page should be >= start page" ) ;
140+ int totalPages = docContent . EndPageNumber - docContent . StartPageNumber + 1 ;
141+ Assert . IsTrue ( totalPages > 0 , "Total pages should be positive" ) ;
142+ Console . WriteLine ( $ "✅ Page range verified: { docContent . StartPageNumber } to { docContent . EndPageNumber } ({ totalPages } pages)") ;
110143
144+ // Validate pages collection
111145 if ( docContent . Pages != null && docContent . Pages . Count > 0 )
112146 {
147+ Assert . IsTrue ( docContent . Pages . Count > 0 , "Pages collection should not be empty when not null" ) ;
148+ Assert . AreEqual ( totalPages , docContent . Pages . Count ,
149+ "Pages collection count should match calculated total pages" ) ;
150+ Console . WriteLine ( $ "✅ Pages collection verified: { docContent . Pages . Count } pages") ;
151+
152+ // Track page numbers to ensure they're sequential and unique
153+ var pageNumbers = new System . Collections . Generic . HashSet < int > ( ) ;
154+
113155 foreach ( var page in docContent . Pages )
114156 {
157+ Assert . IsNotNull ( page , "Page object should not be null" ) ;
115158 Assert . IsTrue ( page . PageNumber >= 1 , "Page number should be >= 1" ) ;
116- Assert . IsTrue ( page . Width > 0 , "Page width should be > 0" ) ;
117- Assert . IsTrue ( page . Height > 0 , "Page height should be > 0" ) ;
159+ Assert . IsTrue ( page . PageNumber >= docContent . StartPageNumber &&
160+ page . PageNumber <= docContent . EndPageNumber ,
161+ $ "Page number { page . PageNumber } should be within document range [{ docContent . StartPageNumber } , { docContent . EndPageNumber } ]") ;
162+ Assert . IsTrue ( page . Width > 0 , $ "Page { page . PageNumber } width should be > 0, but was { page . Width } ") ;
163+ Assert . IsTrue ( page . Height > 0 , $ "Page { page . PageNumber } height should be > 0, but was { page . Height } ") ;
164+
165+ // Ensure page numbers are unique
166+ Assert . IsTrue ( pageNumbers . Add ( page . PageNumber ) ,
167+ $ "Page number { page . PageNumber } appears multiple times") ;
168+
169+ Console . WriteLine ( $ " ✅ Page { page . PageNumber } : { page . Width } x { page . Height } { docContent . Unit ? . ToString ( ) ?? "units" } ") ;
118170 }
119171 }
172+ else
173+ {
174+ Console . WriteLine ( "⚠️ No pages collection available in document content" ) ;
175+ }
120176
177+ // Validate tables collection
121178 if ( docContent . Tables != null && docContent . Tables . Count > 0 )
122179 {
180+ Assert . IsTrue ( docContent . Tables . Count > 0 , "Tables collection should not be empty when not null" ) ;
181+ Console . WriteLine ( $ "✅ Tables collection verified: { docContent . Tables . Count } tables") ;
182+
183+ int tableCounter = 1 ;
123184 foreach ( var table in docContent . Tables )
124185 {
125- Assert . IsTrue ( table . RowCount > 0 , "Table should have at least 1 row" ) ;
126- Assert . IsTrue ( table . ColumnCount > 0 , "Table should have at least 1 column" ) ;
186+ Assert . IsNotNull ( table , $ "Table { tableCounter } should not be null") ;
187+ Assert . IsTrue ( table . RowCount > 0 , $ "Table { tableCounter } should have at least 1 row, but had { table . RowCount } ") ;
188+ Assert . IsTrue ( table . ColumnCount > 0 , $ "Table { tableCounter } should have at least 1 column, but had { table . ColumnCount } ") ;
189+
190+ // Validate table cells if available
191+ if ( table . Cells != null )
192+ {
193+ Assert . IsTrue ( table . Cells . Count > 0 , $ "Table { tableCounter } cells collection should not be empty when not null") ;
194+
195+ foreach ( var cell in table . Cells )
196+ {
197+ Assert . IsNotNull ( cell , "Table cell should not be null" ) ;
198+ Assert . IsTrue ( cell . RowIndex >= 0 && cell . RowIndex < table . RowCount ,
199+ $ "Cell row index { cell . RowIndex } should be within table row count { table . RowCount } ") ;
200+ Assert . IsTrue ( cell . ColumnIndex >= 0 && cell . ColumnIndex < table . ColumnCount ,
201+ $ "Cell column index { cell . ColumnIndex } should be within table column count { table . ColumnCount } ") ;
202+ }
203+ }
204+
205+ Console . WriteLine ( $ " ✅ Table { tableCounter } : { table . RowCount } rows x { table . ColumnCount } columns" +
206+ ( table . Cells != null ? $ " ({ table . Cells . Count } cells)" : "" ) ) ;
207+ tableCounter ++ ;
127208 }
128209 }
210+ else
211+ {
212+ Console . WriteLine ( "⚠️ No tables found in document content" ) ;
213+ }
214+
215+ Console . WriteLine ( "✅ All document properties validated successfully" ) ;
216+ }
217+ else
218+ {
219+ Console . WriteLine ( "⚠️ Content is not DocumentContent type, skipping document-specific validations" ) ;
220+ Assert . Warn ( "Expected DocumentContent but got " + content ? . GetType ( ) . Name ) ;
129221 }
130222 #endregion
131223 }
132224 }
133- }
225+ }
0 commit comments