-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d230dd
commit 76f8853
Showing
11 changed files
with
521 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
source/Firecrawl.Tests/FirecrawlServiceTests.GetCreditUsage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft; | ||
using Microsoft.VisualStudio; | ||
using Microsoft.VisualStudio.TestTools; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Firecrawl | ||
{ | ||
partial class FirecrawlServiceTests | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="options"></param> | ||
/// <returns></returns> | ||
[TestCategory( | ||
"FirecrawlService")] | ||
[TestCategory( | ||
"GetCreditUsage")] | ||
[TestCategory( | ||
"Result")] | ||
[TestMethod] | ||
public async Task GetCreditUsageAsync() | ||
{ | ||
var creditUsageResult = | ||
await this.firecrawl | ||
.GetCreditUsageAsync(); | ||
|
||
Assert.IsNotNull( | ||
creditUsageResult); | ||
|
||
Assert.IsTrue( | ||
creditUsageResult.Success); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
using Microsoft; | ||
using Microsoft.VisualStudio; | ||
using Microsoft.VisualStudio.TestTools; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Firecrawl | ||
{ | ||
partial class FirecrawlServiceTests | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public static IEnumerable<object[]> SearchThrowOnBadRequestTestData => | ||
[ | ||
[ | ||
new FirecrawlSearchOptions() | ||
{ | ||
Query = default | ||
} | ||
], | ||
]; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public static IEnumerable<object[]> SearchTestData => | ||
[ | ||
[ | ||
new FirecrawlSearchOptions() | ||
{ | ||
Query = "current weather san francisco" | ||
} | ||
], | ||
]; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
[TestCategory( | ||
"FirecrawlService")] | ||
[TestCategory( | ||
"Search")] | ||
[TestCategory( | ||
"Argument")] | ||
[TestMethod] | ||
public async Task SearchThrowOnArgumentNullTestAsync() | ||
{ | ||
await Assert.ThrowsExceptionAsync<ArgumentNullException>( | ||
() => this.firecrawl.SearchAsync( | ||
default)); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="options"></param> | ||
/// <returns></returns> | ||
[TestCategory( | ||
"FirecrawlService")] | ||
[TestCategory( | ||
"Search")] | ||
[TestCategory( | ||
"BadRequest")] | ||
//[DataTestMethod] | ||
[DynamicData( | ||
nameof(SearchThrowOnBadRequestTestData))] | ||
public async Task SearchThrowOnBadRequestAsync( | ||
FirecrawlSearchOptions options) | ||
{ | ||
await Assert.ThrowsExceptionAsync<FirecrawlException>( | ||
() => this.firecrawl.SearchAsync( | ||
options)); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="options"></param> | ||
/// <returns></returns> | ||
[TestCategory( | ||
"FirecrawlService")] | ||
[TestCategory( | ||
"Search")] | ||
[TestCategory( | ||
"Result")] | ||
//[DataTestMethod] | ||
[DynamicData( | ||
nameof(SearchTestData))] | ||
public async Task SearchAsync( | ||
FirecrawlSearchOptions options) | ||
{ | ||
var searchResult = | ||
await this.firecrawl | ||
.SearchAsync( | ||
options); | ||
|
||
Assert.IsNotNull( | ||
searchResult); | ||
|
||
Assert.IsTrue( | ||
searchResult.Success); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Firecrawl | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class FirecrawlCreditUsageData | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"remaining_credits")] | ||
public int CreditsRemaining { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Firecrawl | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class FirecrawlCreditUsageResult : | ||
FirecrawlResult | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"success")] | ||
public bool Success { get; init; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"data")] | ||
public FirecrawlCreditUsageData Data { get; init; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Collections.Immutable; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Firecrawl | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class FirecrawlSearchData | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"url")] | ||
public Uri Url { get; init; } | ||
|
||
[JsonPropertyName( | ||
"title")] | ||
public string Title { get; init; } | ||
Check warning on line 21 in source/Firecrawl/FirecrawlSearchData.cs GitHub Actions / Build
Check warning on line 21 in source/Firecrawl/FirecrawlSearchData.cs GitHub Actions / Build
Check warning on line 21 in source/Firecrawl/FirecrawlSearchData.cs GitHub Actions / Build
|
||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"description")] | ||
public string Description { get; init; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"html")] | ||
public string Html { get; init; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"rawHtml")] | ||
public string HtmlRaw { get; init; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"markdown")] | ||
public string Markdown { get; init; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"links")] | ||
public ImmutableArray<string> Links { get; init; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"screenshot")] | ||
public string Screenshot { get; init; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"metadata")] | ||
public FirecrawlSearchDataMetadata Metadata { get; init; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace Firecrawl | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public sealed class FirecrawlSearchDataMetadata | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"title")] | ||
public string Title { get; init; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"description")] | ||
public string Description { get; init; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"sourceURL")] | ||
public string SourceUrl { get; init; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"statusCode")] | ||
public int StatusCode { get; init; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName( | ||
"error")] | ||
public string ErrorMessage { get; init; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonExtensionData] | ||
public Dictionary<string, JsonElement> ExtensionData { get; init; } | ||
} | ||
} |
Oops, something went wrong.