Skip to content

Commit

Permalink
feat: Deepgram .NET SDK v3.0.0
Browse files Browse the repository at this point in the history
Deepgram .NET SDK v3.0.0
  • Loading branch information
lukeocodes authored Aug 2, 2023
2 parents 1fc43f7 + d9d2761 commit 48c8215
Show file tree
Hide file tree
Showing 123 changed files with 2,700 additions and 1,141 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ["3.1.x", "5.0.x", "6.0.x", "7.0.x"]

steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.release.target_commitish }}
- name: Setup .NET
uses: actions/setup-dotnet@v1
ref: ${{ github.event.release.target_commitish }}
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.x.x'
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install dependencies
run: dotnet restore
- name: Get the version
Expand All @@ -34,6 +38,6 @@ jobs:
uses: actions/download-artifact@v2
with:
name: dist
path: 'dist'
path: "dist"
- name: Publish packages
run: dotnet nuget push ./dist/**.nupkg --source nuget.org --api-key ${{secrets.NUGET_API_KEY}}
14 changes: 9 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ on:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ["3.1.x", "5.0.x", "6.0.x", "7.0.x"]

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.x.x'
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install dependencies
run: dotnet restore
- name: Run tests
Expand All @@ -24,8 +28,8 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.x.x'
dotnet-version: "7.x.x"
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build Deepgram.sln --configuration Release --no-restore
run: dotnet build Deepgram.sln --configuration Release --no-restore
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# coderush
.cr*

# User-specific files
*.suo
*.user
Expand Down Expand Up @@ -192,4 +195,4 @@ web.config
app.config
settings.json
appsettings.json
project.lock.json
project.lock.json
78 changes: 78 additions & 0 deletions Deepgram.Tests/ClientTests/DeepgramClientTest.cs
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);
}


}
}
104 changes: 104 additions & 0 deletions Deepgram.Tests/ClientTests/KeyClientTests.cs
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 Deepgram.Tests/ClientTests/PrerecordedTranscriptionTests.cs
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;
}
}
}
Loading

0 comments on commit 48c8215

Please sign in to comment.