-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deepgram .NET SDK v3.0.0
- Loading branch information
Showing
123 changed files
with
2,700 additions
and
1,141 deletions.
There are no files selected for viewing
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
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
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
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,78 @@ | ||
using System; | ||
using Deepgram.Clients; | ||
using Deepgram.Interfaces; | ||
using Deepgram.Tests.Fakers; | ||
using Deepgram.Utilities; | ||
using Xunit; | ||
|
||
namespace Deepgram.Tests.ClientTests | ||
{ | ||
public class DeepClientTests | ||
{ | ||
[Fact] | ||
public void Should_Throw_Exception_When_No_Apikey_Present() | ||
{ | ||
//Act | ||
var ex = Assert.Throws<ArgumentException>(() => _ = new DeepgramClient()); | ||
|
||
//Assert | ||
Assert.IsAssignableFrom<ArgumentException>(ex); | ||
Assert.Equal("Deepgram API Key must be provided in constructor", ex.Message); | ||
} | ||
|
||
|
||
[Fact] | ||
public void Should_Initialize_Clients() | ||
{ | ||
|
||
//Act | ||
var result = new DeepgramClient(new CredentialsFaker().Generate()); | ||
|
||
//Assert | ||
Assert.NotNull(result); | ||
Assert.IsAssignableFrom<KeyClient>(result.Keys); | ||
Assert.IsAssignableFrom<ProjectClient>(result.Projects); | ||
Assert.IsAssignableFrom<TranscriptionClient>(result.Transcription); | ||
Assert.IsAssignableFrom<UsageClient>(result.Usage); | ||
} | ||
|
||
[Fact] | ||
public void Should_Initialize_LiveTranscriptionClient() | ||
{ | ||
//Arrange | ||
|
||
var SUT = new DeepgramClient(new CredentialsFaker().Generate()); | ||
//Act | ||
|
||
var result = SUT.CreateLiveTranscriptionClient(); | ||
|
||
//Assert | ||
Assert.NotNull(result); | ||
Assert.IsAssignableFrom<ILiveTranscriptionClient>(result); | ||
|
||
} | ||
|
||
|
||
[Theory] | ||
[InlineData(2)] | ||
[InlineData(10)] | ||
[InlineData(20)] | ||
[InlineData(30)] | ||
public void Should_Set_TimeOut_On_HttpClient(double timeSpan) | ||
{ | ||
|
||
//Arrange | ||
var SUT = new DeepgramClient(new CredentialsFaker().Generate()); | ||
|
||
//Act | ||
SUT.SetHttpClientTimeout(TimeSpan.FromSeconds(timeSpan)); | ||
var httpClient = HttpClientUtil.HttpClient; | ||
|
||
//Assert | ||
Assert.NotNull(httpClient); | ||
Assert.Equal(timeSpan, httpClient.Timeout.TotalSeconds); | ||
} | ||
|
||
|
||
} | ||
} |
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,104 @@ | ||
using System; | ||
using AutoBogus; | ||
using Bogus; | ||
using Deepgram.Models; | ||
using Deepgram.Tests.Fakers; | ||
using Deepgram.Tests.Fakes; | ||
using Xunit; | ||
|
||
namespace Deepgram.Tests.ClientTests | ||
{ | ||
public class KeyClientTests | ||
{ | ||
[Fact] | ||
public async void ListKeysAsync_Should_Return_KeyList() | ||
{ | ||
//Arrange | ||
var returnObject = new AutoFaker<KeyList>().Generate(); | ||
var SUT = GetDeepgramClient(returnObject); | ||
var projectId = Guid.NewGuid().ToString(); | ||
|
||
//Act | ||
var result = await SUT.Keys.ListKeysAsync(projectId); | ||
|
||
//Assert | ||
Assert.NotNull(result); | ||
Assert.IsAssignableFrom<KeyList>(result); | ||
Assert.Equal(returnObject, result); | ||
} | ||
|
||
[Fact] | ||
public async void GetKeyAsync_Should_Return_Key() | ||
{ | ||
//Arrange | ||
var returnObject = new AutoFaker<Key>().Generate(); | ||
var SUT = GetDeepgramClient(returnObject); | ||
|
||
var projectId = Guid.NewGuid().ToString(); | ||
var keyId = Guid.NewGuid().ToString(); | ||
|
||
//Act | ||
var result = await SUT.Keys.GetKeyAsync(projectId, keyId); | ||
|
||
//Assert | ||
Assert.NotNull(result); | ||
Assert.IsAssignableFrom<Key>(result); | ||
Assert.Equal(returnObject, result); | ||
} | ||
|
||
[Fact] | ||
public async void CreateKeyAsync_Should_Return_ApiKey() | ||
{ | ||
//Arrange | ||
var returnObject = new AutoFaker<ApiKey>().Generate(); | ||
DeepgramClient SUT = GetDeepgramClient(returnObject); | ||
|
||
var faker = new Faker(); | ||
var projectId = faker.Random.Guid().ToString(); | ||
var scopes = faker.Random.WordsArray(1, 3); | ||
var comment = faker.Lorem.Sentence(); | ||
|
||
//Act | ||
var result = await SUT.Keys.CreateKeyAsync(projectId, comment, scopes); | ||
|
||
//Assert | ||
Assert.NotNull(result); | ||
Assert.IsAssignableFrom<ApiKey>(result); | ||
Assert.Equal(returnObject, result); | ||
} | ||
|
||
[Fact] | ||
public async void DeleteKeyAsync_Should_Return_MessageResponse() | ||
{ | ||
//Arrange | ||
var returnObject = new AutoFaker<MessageResponse>().Generate(); | ||
var SUT = GetDeepgramClient(returnObject); | ||
|
||
var projectId = Guid.NewGuid().ToString(); | ||
var keyId = Guid.NewGuid().ToString(); | ||
|
||
//Act | ||
var result = await SUT.Keys.DeleteKeyAsync(projectId, keyId); | ||
|
||
//Assert | ||
Assert.NotNull(result); | ||
Assert.IsAssignableFrom<MessageResponse>(result); | ||
Assert.Equal(returnObject, result); | ||
} | ||
|
||
|
||
|
||
private static DeepgramClient GetDeepgramClient<T>(T returnObject) | ||
{ | ||
var mockIRequestMessageBuilder = MockIRequestMessageBuilder.Create(); | ||
var mockIApiRequest = MockIApiRequest.Create(returnObject); | ||
var credentials = new CredentialsFaker().Generate(); | ||
var SUT = new DeepgramClient(credentials); | ||
SUT.Keys.ApiRequest = mockIApiRequest.Object; | ||
SUT.Keys.RequestMessageBuilder = mockIRequestMessageBuilder.Object; | ||
return SUT; | ||
} | ||
|
||
|
||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
Deepgram.Tests/ClientTests/PrerecordedTranscriptionTests.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,121 @@ | ||
using AutoBogus; | ||
using Bogus; | ||
using Deepgram.Models; | ||
using Deepgram.Request; | ||
using Deepgram.Tests.Fakers; | ||
using Deepgram.Tests.Fakes; | ||
using Xunit; | ||
|
||
namespace Deepgram.Tests.ClientTests | ||
{ | ||
public class PrerecordedTranscriptionTests | ||
{ | ||
PrerecordedTranscriptionOptions _prerecordedTranscriptionOptions; | ||
UrlSource _urlSource; | ||
public PrerecordedTranscriptionTests() | ||
{ | ||
_prerecordedTranscriptionOptions = new PrerecordedTranscriptionOptionsFaker().Generate(); | ||
_urlSource = new UrlSource(new Faker().Internet.Url()); | ||
} | ||
|
||
[Fact] | ||
public async void GetTransaction_Should_Return_PrerecordedTranscription_When_UrlSource_Present() | ||
{ | ||
//Arrange | ||
var fakePrecordedTranscription = new AutoFaker<PrerecordedTranscription>().Generate(); | ||
var SUT = GetDeepgramClient(fakePrecordedTranscription); | ||
|
||
//Act | ||
var result = await SUT.Transcription.Prerecorded.GetTranscriptionAsync(_urlSource, _prerecordedTranscriptionOptions); | ||
|
||
//Assert | ||
Assert.NotNull(result); | ||
Assert.NotNull(result.Results); | ||
Assert.IsAssignableFrom<PrerecordedTranscription>(result); | ||
Assert.Equal(fakePrecordedTranscription, result); | ||
} | ||
|
||
[Fact] | ||
public async void GetTransaction_Should_Return_PrerecordedTranscription_When_StreamSource_Present() | ||
{ | ||
//Arrange | ||
var fakePrecordedTranscription = new AutoFaker<PrerecordedTranscription>().Generate(); | ||
var SUT = GetDeepgramClient(fakePrecordedTranscription); | ||
var fakeStreamSource = new StreamSourceFaker().Generate(); | ||
|
||
//Act | ||
var result = await SUT.Transcription.Prerecorded.GetTranscriptionAsync(fakeStreamSource, _prerecordedTranscriptionOptions); | ||
|
||
//Assert | ||
Assert.NotNull(result); | ||
Assert.NotNull(result.Results); | ||
Assert.IsAssignableFrom<PrerecordedTranscription>(result); | ||
Assert.Equal(fakePrecordedTranscription, result); | ||
} | ||
|
||
[Fact] | ||
public async void Should_Return_A_Summary_Short_When_Summarize_Set_To_v2() | ||
{ | ||
//Arrange | ||
var responseObject = new AutoFaker<PrerecordedTranscription>().Generate(); | ||
var SUT = GetDeepgramClient(responseObject); | ||
|
||
responseObject.Results.Summary.Short = "This is a test summary"; | ||
var client = FakeHttpMessageHandler.CreateHttpClientWithResult(responseObject); | ||
var fakeOptions = new PrerecordedTranscriptionOptions() | ||
{ | ||
Summarize = "v2" | ||
}; | ||
SUT.Transcription.Prerecorded.ApiRequest = new ApiRequest(client); | ||
|
||
//Act | ||
var result = await SUT.Transcription.Prerecorded.GetTranscriptionAsync(_urlSource, fakeOptions); | ||
|
||
//Assert | ||
Assert.NotNull(result); | ||
Assert.NotNull(result.Results.Summary.Short); | ||
|
||
} | ||
|
||
|
||
|
||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public async void Should_Return_A_Summary_Short_When_Summarize_Set_To_bool(bool value) | ||
{ | ||
//Arrange | ||
var responseObject = new AutoFaker<PrerecordedTranscription>().Generate(); | ||
var SUT = GetDeepgramClient(responseObject); | ||
responseObject.Results.Summary.Short = null; | ||
var client = FakeHttpMessageHandler.CreateHttpClientWithResult(responseObject); | ||
var fakeOptions = new PrerecordedTranscriptionOptions() | ||
{ | ||
Summarize = value | ||
}; | ||
|
||
SUT.Transcription.Prerecorded.ApiRequest = new ApiRequest(client); | ||
|
||
//Act | ||
var result = await SUT.Transcription.Prerecorded.GetTranscriptionAsync(_urlSource, fakeOptions); | ||
|
||
//Assert | ||
Assert.NotNull(result); | ||
Assert.NotNull(result.Results); | ||
Assert.Null(result.Results.Summary.Short); | ||
|
||
} | ||
|
||
|
||
private static DeepgramClient GetDeepgramClient<T>(T returnObject) | ||
{ | ||
var mockIRequestMessageBuilder = MockIRequestMessageBuilder.Create(); | ||
var mockIApiRequest = MockIApiRequest.Create(returnObject); | ||
var credentials = new CredentialsFaker().Generate(); | ||
var SUT = new DeepgramClient(credentials); | ||
SUT.Transcription.Prerecorded.ApiRequest = mockIApiRequest.Object; | ||
SUT.Transcription.Prerecorded.RequestMessageBuilder = mockIRequestMessageBuilder.Object; | ||
return SUT; | ||
} | ||
} | ||
} |
Oops, something went wrong.