@@ -38,6 +38,21 @@ 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+
4156 #region Snippet:ContentUnderstandingExtractMarkdownFromUrl
4257 // A PDF file has only one content element even if it contains multiple pages
4358 MediaContent ? content = null ;
@@ -59,16 +74,23 @@ public async Task AnalyzeUrlAsync()
5974 }
6075 #endregion
6176
77+ #region Assertion:ContentUnderstandingExtractMarkdown
6278 #region Assertion:ContentUnderstandingExtractMarkdown
6379 Assert . IsNotNull ( result . Contents , "Result should contain contents" ) ;
6480 Assert . IsTrue ( result . Contents ! . Count > 0 , "Result should have at least one content" ) ;
81+ Assert . AreEqual ( 1 , result . Contents . Count , "PDF file should have exactly one content element" ) ;
6582 Assert . IsNotNull ( content , "Content should not be null" ) ;
83+ Assert . IsInstanceOf < MediaContent > ( content , "Content should be of type MediaContent" ) ;
6684 if ( content is MediaContent mediaContent )
6785 {
6886 Assert . IsNotNull ( mediaContent . Markdown , "Markdown content should not be null" ) ;
6987 Assert . IsTrue ( mediaContent . Markdown . Length > 0 , "Markdown content should not be empty" ) ;
88+ Assert . IsFalse ( string . IsNullOrWhiteSpace ( mediaContent . Markdown ) ,
89+ "Markdown content should not be just whitespace" ) ;
90+ Console . WriteLine ( $ "✅ Markdown content extracted successfully ({ mediaContent . Markdown . Length } characters)") ;
7091 }
7192 #endregion
93+ #endregion
7294
7395 #region Snippet:ContentUnderstandingAccessDocumentPropertiesFromUrl
7496 // Check if this is document content to access document-specific properties
@@ -104,32 +126,102 @@ public async Task AnalyzeUrlAsync()
104126 }
105127 #endregion
106128
107- #region Assertion:ContentUnderstandingAccessDocumentProperties
129+ #region Assertion:ContentUnderstandingAccessDocumentPropertiesFromUrl
130+ Assert . IsNotNull ( content , "Content should not be null for document properties validation" ) ;
131+
108132 if ( content is DocumentContent docContent )
109133 {
134+ // Validate MIME type
110135 Assert . IsNotNull ( docContent . MimeType , "MIME type should not be null" ) ;
136+ Assert . IsFalse ( string . IsNullOrWhiteSpace ( docContent . MimeType ) , "MIME type should not be empty" ) ;
137+ Assert . AreEqual ( "application/pdf" , docContent . MimeType , "MIME type should be application/pdf" ) ;
138+ Console . WriteLine ( $ "✅ MIME type verified: { docContent . MimeType } ") ;
139+
140+ // Validate page numbers
111141 Assert . IsTrue ( docContent . StartPageNumber >= 1 , "Start page should be >= 1" ) ;
112142 Assert . IsTrue ( docContent . EndPageNumber >= docContent . StartPageNumber ,
113143 "End page should be >= start page" ) ;
144+ int totalPages = docContent . EndPageNumber - docContent . StartPageNumber + 1 ;
145+ Assert . IsTrue ( totalPages > 0 , "Total pages should be positive" ) ;
146+ Console . WriteLine ( $ "✅ Page range verified: { docContent . StartPageNumber } to { docContent . EndPageNumber } ({ totalPages } pages)") ;
114147
148+ // Validate pages collection
115149 if ( docContent . Pages != null && docContent . Pages . Count > 0 )
116150 {
151+ Assert . IsTrue ( docContent . Pages . Count > 0 , "Pages collection should not be empty when not null" ) ;
152+ Assert . AreEqual ( totalPages , docContent . Pages . Count ,
153+ "Pages collection count should match calculated total pages" ) ;
154+ Console . WriteLine ( $ "✅ Pages collection verified: { docContent . Pages . Count } pages") ;
155+
156+ // Track page numbers to ensure they're sequential and unique
157+ var pageNumbers = new System . Collections . Generic . HashSet < int > ( ) ;
158+
117159 foreach ( var page in docContent . Pages )
118160 {
161+ Assert . IsNotNull ( page , "Page object should not be null" ) ;
119162 Assert . IsTrue ( page . PageNumber >= 1 , "Page number should be >= 1" ) ;
120- Assert . IsTrue ( page . Width > 0 , "Page width should be > 0" ) ;
121- Assert . IsTrue ( page . Height > 0 , "Page height should be > 0" ) ;
163+ Assert . IsTrue ( page . PageNumber >= docContent . StartPageNumber &&
164+ page . PageNumber <= docContent . EndPageNumber ,
165+ $ "Page number { page . PageNumber } should be within document range [{ docContent . StartPageNumber } , { docContent . EndPageNumber } ]") ;
166+ Assert . IsTrue ( page . Width > 0 , $ "Page { page . PageNumber } width should be > 0, but was { page . Width } ") ;
167+ Assert . IsTrue ( page . Height > 0 , $ "Page { page . PageNumber } height should be > 0, but was { page . Height } ") ;
168+
169+ // Ensure page numbers are unique
170+ Assert . IsTrue ( pageNumbers . Add ( page . PageNumber ) ,
171+ $ "Page number { page . PageNumber } appears multiple times") ;
172+
173+ Console . WriteLine ( $ " ✅ Page { page . PageNumber } : { page . Width } x { page . Height } { docContent . Unit ? . ToString ( ) ?? "units" } ") ;
122174 }
123175 }
176+ else
177+ {
178+ Console . WriteLine ( "⚠️ No pages collection available in document content" ) ;
179+ }
124180
181+ // Validate tables collection
125182 if ( docContent . Tables != null && docContent . Tables . Count > 0 )
126183 {
184+ Assert . IsTrue ( docContent . Tables . Count > 0 , "Tables collection should not be empty when not null" ) ;
185+ Console . WriteLine ( $ "✅ Tables collection verified: { docContent . Tables . Count } tables") ;
186+
187+ int tableCounter = 1 ;
127188 foreach ( var table in docContent . Tables )
128189 {
129- Assert . IsTrue ( table . RowCount > 0 , "Table should have at least 1 row" ) ;
130- Assert . IsTrue ( table . ColumnCount > 0 , "Table should have at least 1 column" ) ;
190+ Assert . IsNotNull ( table , $ "Table { tableCounter } should not be null") ;
191+ Assert . IsTrue ( table . RowCount > 0 , $ "Table { tableCounter } should have at least 1 row, but had { table . RowCount } ") ;
192+ Assert . IsTrue ( table . ColumnCount > 0 , $ "Table { tableCounter } should have at least 1 column, but had { table . ColumnCount } ") ;
193+
194+ // Validate table cells if available
195+ if ( table . Cells != null )
196+ {
197+ Assert . IsTrue ( table . Cells . Count > 0 , $ "Table { tableCounter } cells collection should not be empty when not null") ;
198+
199+ foreach ( var cell in table . Cells )
200+ {
201+ Assert . IsNotNull ( cell , "Table cell should not be null" ) ;
202+ Assert . IsTrue ( cell . RowIndex >= 0 && cell . RowIndex < table . RowCount ,
203+ $ "Cell row index { cell . RowIndex } should be within table row count { table . RowCount } ") ;
204+ Assert . IsTrue ( cell . ColumnIndex >= 0 && cell . ColumnIndex < table . ColumnCount ,
205+ $ "Cell column index { cell . ColumnIndex } should be within table column count { table . ColumnCount } ") ;
206+ }
207+ }
208+
209+ Console . WriteLine ( $ " ✅ Table { tableCounter } : { table . RowCount } rows x { table . ColumnCount } columns" +
210+ ( table . Cells != null ? $ " ({ table . Cells . Count } cells)" : "" ) ) ;
211+ tableCounter ++ ;
131212 }
132213 }
214+ else
215+ {
216+ Console . WriteLine ( "ℹ️ No tables found in document content" ) ;
217+ }
218+
219+ Console . WriteLine ( "✅ All document properties validated successfully" ) ;
220+ }
221+ else
222+ {
223+ Console . WriteLine ( "ℹ️ Content is not DocumentContent type, skipping document-specific validations" ) ;
224+ Assert . Warn ( "Expected DocumentContent but got " + content ? . GetType ( ) . Name ) ;
133225 }
134226 #endregion
135227 }
0 commit comments