Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ public async Task AnalyzeBinaryAsync()

#region Assertion:ContentUnderstandingAnalyzeBinaryAsync
Assert.IsTrue(File.Exists(filePath), $"Sample file not found at {filePath}");
Assert.IsTrue(fileBytes.Length > 0, "File should not be empty");
Assert.IsNotNull(binaryData, "Binary data should not be null");
Assert.IsNotNull(operation, "Analysis operation should not be null");
Assert.IsTrue(operation.HasCompleted, "Operation should be completed");
Assert.IsNotNull(operation.GetRawResponse(), "Analysis operation should have a raw response");
TestContext.WriteLine("✅ Analysis operation properties verified");
Assert.IsTrue(operation.GetRawResponse().Status >= 200 && operation.GetRawResponse().Status < 300,
$"Response status should be successful, but was {operation.GetRawResponse().Status}");
Console.WriteLine("✅ Analysis operation properties verified");
Assert.IsNotNull(result, "Analysis result should not be null");
Assert.IsNotNull(result.Contents, "Result contents should not be null");
Console.WriteLine($"✅ Analysis result contains {result.Contents?.Count ?? 0} content(s)");
#endregion

#region Snippet:ContentUnderstandingExtractMarkdown
Expand All @@ -75,11 +82,16 @@ public async Task AnalyzeBinaryAsync()
#region Assertion:ContentUnderstandingExtractMarkdown
Assert.IsNotNull(result.Contents, "Result should contain contents");
Assert.IsTrue(result.Contents!.Count > 0, "Result should have at least one content");
Assert.AreEqual(1, result.Contents.Count, "PDF file should have exactly one content element");
Assert.IsNotNull(content, "Content should not be null");
Assert.IsInstanceOf<MediaContent>(content, "Content should be of type MediaContent");
if (content is MediaContent mediaContent)
{
Assert.IsNotNull(mediaContent.Markdown, "Markdown content should not be null");
Assert.IsTrue(mediaContent.Markdown.Length > 0, "Markdown content should not be empty");
Assert.IsFalse(string.IsNullOrWhiteSpace(mediaContent.Markdown),
"Markdown content should not be just whitespace");
Console.WriteLine($"✅ Markdown content extracted successfully ({mediaContent.Markdown.Length} characters)");
}
#endregion

Expand Down Expand Up @@ -118,31 +130,103 @@ public async Task AnalyzeBinaryAsync()
#endregion

#region Assertion:ContentUnderstandingAccessDocumentProperties
Assert.IsNotNull(content, "Content should not be null for document properties validation");

if (content is DocumentContent docContent)
{
// Validate MIME type
Assert.IsNotNull(docContent.MimeType, "MIME type should not be null");
Assert.IsFalse(string.IsNullOrWhiteSpace(docContent.MimeType), "MIME type should not be empty");
Assert.AreEqual("application/pdf", docContent.MimeType, "MIME type should be application/pdf");
Console.WriteLine($"✅ MIME type verified: {docContent.MimeType}");

// Validate page numbers
Assert.IsTrue(docContent.StartPageNumber >= 1, "Start page should be >= 1");
Assert.IsTrue(docContent.EndPageNumber >= docContent.StartPageNumber,
"End page should be >= start page");
int totalPages = docContent.EndPageNumber - docContent.StartPageNumber + 1;
Assert.IsTrue(totalPages > 0, "Total pages should be positive");
Console.WriteLine($"✅ Page range verified: {docContent.StartPageNumber} to {docContent.EndPageNumber} ({totalPages} pages)");

// Validate pages collection
if (docContent.Pages != null && docContent.Pages.Count > 0)
{
Assert.IsTrue(docContent.Pages.Count > 0, "Pages collection should not be empty when not null");
Assert.AreEqual(totalPages, docContent.Pages.Count,
"Pages collection count should match calculated total pages");
Console.WriteLine($"✅ Pages collection verified: {docContent.Pages.Count} pages");

// Track page numbers to ensure they're sequential and unique
var pageNumbers = new System.Collections.Generic.HashSet<int>();

foreach (var page in docContent.Pages)
{
Assert.IsNotNull(page, "Page object should not be null");
Assert.IsTrue(page.PageNumber >= 1, "Page number should be >= 1");
Assert.IsTrue(page.Width > 0, "Page width should be > 0");
Assert.IsTrue(page.Height > 0, "Page height should be > 0");
Assert.IsTrue(page.PageNumber >= docContent.StartPageNumber &&
page.PageNumber <= docContent.EndPageNumber,
$"Page number {page.PageNumber} should be within document range [{docContent.StartPageNumber}, {docContent.EndPageNumber}]");
Assert.IsTrue(page.Width > 0, $"Page {page.PageNumber} width should be > 0, but was {page.Width}");
Assert.IsTrue(page.Height > 0, $"Page {page.PageNumber} height should be > 0, but was {page.Height}");

// Ensure page numbers are unique
Assert.IsTrue(pageNumbers.Add(page.PageNumber),
$"Page number {page.PageNumber} appears multiple times");

Console.WriteLine($" ✅ Page {page.PageNumber}: {page.Width} x {page.Height} {docContent.Unit?.ToString() ?? "units"}");
}
}
else
{
Console.WriteLine("⚠️ No pages collection available in document content");
}

// Validate tables collection
if (docContent.Tables != null && docContent.Tables.Count > 0)
{
Assert.IsTrue(docContent.Tables.Count > 0, "Tables collection should not be empty when not null");
Console.WriteLine($"✅ Tables collection verified: {docContent.Tables.Count} tables");

int tableCounter = 1;
foreach (var table in docContent.Tables)
{
Assert.IsTrue(table.RowCount > 0, "Table should have at least 1 row");
Assert.IsTrue(table.ColumnCount > 0, "Table should have at least 1 column");
Assert.IsNotNull(table, $"Table {tableCounter} should not be null");
Assert.IsTrue(table.RowCount > 0, $"Table {tableCounter} should have at least 1 row, but had {table.RowCount}");
Assert.IsTrue(table.ColumnCount > 0, $"Table {tableCounter} should have at least 1 column, but had {table.ColumnCount}");

// Validate table cells if available
if (table.Cells != null)
{
Assert.IsTrue(table.Cells.Count > 0, $"Table {tableCounter} cells collection should not be empty when not null");

foreach (var cell in table.Cells)
{
Assert.IsNotNull(cell, "Table cell should not be null");
Assert.IsTrue(cell.RowIndex >= 0 && cell.RowIndex < table.RowCount,
$"Cell row index {cell.RowIndex} should be within table row count {table.RowCount}");
Assert.IsTrue(cell.ColumnIndex >= 0 && cell.ColumnIndex < table.ColumnCount,
$"Cell column index {cell.ColumnIndex} should be within table column count {table.ColumnCount}");
Assert.IsTrue(cell.RowSpan >= 1, $"Cell row span should be >= 1, but was {cell.RowSpan}");
Assert.IsTrue(cell.ColumnSpan >= 1, $"Cell column span should be >= 1, but was {cell.ColumnSpan}");
}
}

Console.WriteLine($" ✅ Table {tableCounter}: {table.RowCount} rows x {table.ColumnCount} columns" +
(table.Cells != null ? $" ({table.Cells.Count} cells)" : ""));
tableCounter++;
}
}
else
{
Console.WriteLine("ℹ️ No tables found in document content");
}

Console.WriteLine("✅ All document properties validated successfully");
}
else
{
Console.WriteLine("ℹ️ Content is not DocumentContent type, skipping document-specific validations");
Assert.Warn("Expected DocumentContent but got " + content?.GetType().Name);
}
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,32 @@ public async Task AnalyzeUrlAsync()
AnalyzeResult result = operation.Value;
#endregion

#region Assertion:ContentUnderstandingAnalyzeUrlAsync
Assert.IsNotNull(uriSource, "URI source should not be null");
Assert.IsTrue(uriSource.IsAbsoluteUri, "URI should be absolute");
Assert.IsNotNull(operation, "Analysis operation should not be null");
Assert.IsTrue(operation.HasCompleted, "Operation should be completed");
Assert.IsTrue(operation.HasValue, "Operation should have a value");
Assert.IsNotNull(operation.GetRawResponse(), "Analysis operation should have a raw response");
Assert.IsTrue(operation.GetRawResponse().Status >= 200 && operation.GetRawResponse().Status < 300,
$"Response status should be successful, but was {operation.GetRawResponse().Status}");
Console.WriteLine("✅ Analysis operation properties verified");
Assert.IsNotNull(result, "Analysis result should not be null");
Assert.IsNotNull(result.Contents, "Result contents should not be null");
Console.WriteLine($"✅ Analysis result contains {result.Contents?.Count ?? 0} content(s)");
#endregion

#region Snippet:ContentUnderstandingExtractMarkdownFromUrl
// A PDF file has only one content element even if it contains multiple pages
MediaContent? content = null;
MediaContent? content = null;
if (result.Contents == null || result.Contents.Count == 0)
{
Console.WriteLine("(No content returned from analysis)");
}
else
{
content = result.Contents.First();
if (!string.IsNullOrEmpty(content.Markdown))
if (! string.IsNullOrEmpty(content.Markdown))
{
Console.WriteLine(content.Markdown);
}
Expand All @@ -56,22 +72,28 @@ public async Task AnalyzeUrlAsync()
Console.WriteLine("(No markdown content available)");
}
}
#endregion

#region Assertion:ContentUnderstandingExtractMarkdown
Assert.IsNotNull(result.Contents, "Result should contain contents");
Assert.IsTrue(result.Contents!.Count > 0, "Result should have at least one content");
Assert.AreEqual(1, result.Contents.Count, "PDF file should have exactly one content element");
Assert.IsNotNull(content, "Content should not be null");
Assert.IsInstanceOf<MediaContent>(content, "Content should be of type MediaContent");
if (content is MediaContent mediaContent)
{
Assert.IsNotNull(mediaContent.Markdown, "Markdown content should not be null");
Assert.IsTrue(mediaContent.Markdown.Length > 0, "Markdown content should not be empty");
Assert.IsFalse(string.IsNullOrWhiteSpace(mediaContent.Markdown),
"Markdown content should not be just whitespace");
Console.WriteLine($"✅ Markdown content extracted successfully ({mediaContent.Markdown.Length} characters)");
}
#endregion

// Check if this is document content to access document-specific properties
if (content is DocumentContent documentContent)
{
Console.WriteLine($"Document type: {documentContent.MimeType ?? "(unknown)"}");
Console.WriteLine($"Document type: {documentContent.MimeType ?? "(unknown)"}");
Console.WriteLine($"Start page: {documentContent.StartPageNumber}");
Console.WriteLine($"End page: {documentContent.EndPageNumber}");
Console.WriteLine($"Total pages: {documentContent.EndPageNumber - documentContent.StartPageNumber + 1}");
Expand Down Expand Up @@ -100,34 +122,104 @@ public async Task AnalyzeUrlAsync()
}
}

#region Assertion:ContentUnderstandingAccessDocumentProperties
#region Assertion:ContentUnderstandingAccessDocumentPropertiesFromUrl
Assert.IsNotNull(content, "Content should not be null for document properties validation");

if (content is DocumentContent docContent)
{
// Validate MIME type
Assert.IsNotNull(docContent.MimeType, "MIME type should not be null");
Assert.IsFalse(string.IsNullOrWhiteSpace(docContent.MimeType), "MIME type should not be empty");
Assert.AreEqual("application/pdf", docContent.MimeType, "MIME type should be application/pdf");
Console.WriteLine($"✅ MIME type verified: {docContent.MimeType}");

// Validate page numbers
Assert.IsTrue(docContent.StartPageNumber >= 1, "Start page should be >= 1");
Assert.IsTrue(docContent.EndPageNumber >= docContent.StartPageNumber,
"End page should be >= start page");
int totalPages = docContent.EndPageNumber - docContent.StartPageNumber + 1;
Assert.IsTrue(totalPages > 0, "Total pages should be positive");
Console.WriteLine($"✅ Page range verified: {docContent.StartPageNumber} to {docContent.EndPageNumber} ({totalPages} pages)");

// Validate pages collection
if (docContent.Pages != null && docContent.Pages.Count > 0)
{
Assert.IsTrue(docContent.Pages.Count > 0, "Pages collection should not be empty when not null");
Assert.AreEqual(totalPages, docContent.Pages.Count,
"Pages collection count should match calculated total pages");
Console.WriteLine($"✅ Pages collection verified: {docContent.Pages.Count} pages");

// Track page numbers to ensure they're sequential and unique
var pageNumbers = new System.Collections.Generic.HashSet<int>();

foreach (var page in docContent.Pages)
{
Assert.IsNotNull(page, "Page object should not be null");
Assert.IsTrue(page.PageNumber >= 1, "Page number should be >= 1");
Assert.IsTrue(page.Width > 0, "Page width should be > 0");
Assert.IsTrue(page.Height > 0, "Page height should be > 0");
Assert.IsTrue(page.PageNumber >= docContent.StartPageNumber &&
page.PageNumber <= docContent.EndPageNumber,
$"Page number {page.PageNumber} should be within document range [{docContent.StartPageNumber}, {docContent.EndPageNumber}]");
Assert.IsTrue(page.Width > 0, $"Page {page.PageNumber} width should be > 0, but was {page.Width}");
Assert.IsTrue(page.Height > 0, $"Page {page.PageNumber} height should be > 0, but was {page.Height}");

// Ensure page numbers are unique
Assert.IsTrue(pageNumbers.Add(page.PageNumber),
$"Page number {page.PageNumber} appears multiple times");

Console.WriteLine($" ✅ Page {page.PageNumber}: {page.Width} x {page.Height} {docContent.Unit?.ToString() ?? "units"}");
}
}
else
{
Console.WriteLine("⚠️ No pages collection available in document content");
}

// Validate tables collection
if (docContent.Tables != null && docContent.Tables.Count > 0)
{
Assert.IsTrue(docContent.Tables.Count > 0, "Tables collection should not be empty when not null");
Console.WriteLine($"✅ Tables collection verified: {docContent.Tables.Count} tables");

int tableCounter = 1;
foreach (var table in docContent.Tables)
{
Assert.IsTrue(table.RowCount > 0, "Table should have at least 1 row");
Assert.IsTrue(table.ColumnCount > 0, "Table should have at least 1 column");
Assert.IsNotNull(table, $"Table {tableCounter} should not be null");
Assert.IsTrue(table.RowCount > 0, $"Table {tableCounter} should have at least 1 row, but had {table.RowCount}");
Assert.IsTrue(table.ColumnCount > 0, $"Table {tableCounter} should have at least 1 column, but had {table.ColumnCount}");

// Validate table cells if available
if (table.Cells != null)
{
Assert.IsTrue(table.Cells.Count > 0, $"Table {tableCounter} cells collection should not be empty when not null");

foreach (var cell in table.Cells)
{
Assert.IsNotNull(cell, "Table cell should not be null");
Assert.IsTrue(cell.RowIndex >= 0 && cell.RowIndex < table.RowCount,
$"Cell row index {cell.RowIndex} should be within table row count {table.RowCount}");
Assert.IsTrue(cell.ColumnIndex >= 0 && cell.ColumnIndex < table.ColumnCount,
$"Cell column index {cell.ColumnIndex} should be within table column count {table.ColumnCount}");
}
}

Console.WriteLine($" ✅ Table {tableCounter}: {table.RowCount} rows x {table.ColumnCount} columns" +
(table.Cells != null ? $" ({table.Cells.Count} cells)" : ""));
tableCounter++;
}
}
else
{
Console.WriteLine("⚠️ No tables found in document content");
}

Console.WriteLine("✅ All document properties validated successfully");
}
else
{
Console.WriteLine("⚠️ Content is not DocumentContent type, skipping document-specific validations");
Assert.Warn("Expected DocumentContent but got " + content?.GetType().Name);
}
#endregion
}
}
}
}
Loading