Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit a422b94

Browse files
committed
SDK regeneration
1 parent 858ec62 commit a422b94

20 files changed

+399
-382
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ on: [push]
44

55
jobs:
66
compile:
7-
name: Compile
87
runs-on: ubuntu-latest
9-
env:
10-
DOTNET_NOLOGO: true
8+
119
steps:
1210
- name: Checkout repo
13-
uses: actions/checkout@v4
11+
uses: actions/checkout@v3
12+
13+
- uses: actions/checkout@master
1414

1515
- name: Setup .NET
16-
uses: actions/setup-dotnet@v4
16+
uses: actions/setup-dotnet@v1
1717
with:
1818
dotnet-version: 8.x
1919

@@ -24,54 +24,40 @@ jobs:
2424
- name: Build Release
2525
run: dotnet build src -c Release /p:ContinuousIntegrationBuild=true
2626

27-
tests:
28-
strategy:
29-
fail-fast: false
30-
matrix:
31-
framework: [net462, net6.0]
32-
os: [ubuntu-latest, windows-latest]
33-
exclude:
34-
- os: ubuntu-latest
35-
framework: net462
36-
name: Run Tests on ${{ matrix.os }} with ${{ matrix.framework }}
27+
unit-tests:
3728
runs-on: ubuntu-latest
29+
3830
steps:
3931
- name: Checkout repo
40-
uses: actions/checkout@v4
32+
uses: actions/checkout@v3
4133

4234
- uses: actions/checkout@master
4335

4436
- name: Setup .NET
45-
uses: actions/setup-dotnet@v4
37+
uses: actions/setup-dotnet@v1
4638
with:
47-
dotnet-version: |
48-
8.x
49-
6.x
39+
dotnet-version: 8.x
5040

5141
- name: Install tools
5242
run: |
5343
dotnet tool restore
5444
5545
- name: Run Tests
5646
run: |
57-
dotnet test src --framework ${{ matrix.framework }}
58-
env:
59-
ASSEMBLYAI_API_KEY: ${{ secrets.ASSEMBLYAI_API_KEY }}
60-
TEST_TRANSCRIPT_ID: ${{ secrets.TEST_TRANSCRIPT_ID }}
61-
TEST_TRANSCRIPT_IDS: ${{ secrets.TEST_TRANSCRIPT_IDS }}
47+
dotnet test src
48+
6249
6350
publish:
64-
name: Publish to NuGet
6551
needs: [compile]
6652
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
6753
runs-on: ubuntu-latest
6854

6955
steps:
7056
- name: Checkout repo
71-
uses: actions/checkout@v4
57+
uses: actions/checkout@v3
7258

7359
- name: Setup .NET
74-
uses: actions/setup-dotnet@v4
60+
uses: actions/setup-dotnet@v1
7561
with:
7662
dotnet-version: 8.x
7763

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!--
2+
Configure additional MSBuild properties for your project in this file:
3+
- Step 1: Add this file to your .fernignore file to ensure it is not overwritten.
4+
- Step 2: Modify this file to your liking.
5+
-->
6+
<Project>
7+
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
14+
<PackageReference Include="NUnit" Version="4.2.2"/>
15+
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0"/>
16+
<PackageReference Include="NUnit.Analyzers" Version="4.4.0">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
20+
<PackageReference Include="coverlet.collector" Version="6.0.2">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
24+
<PackageReference Include="WireMock.Net" Version="1.6.8" />
25+
<PackageReference Include="FluentAssertions.Json" Version="6.1.0" />
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<ProjectReference Include="..\AssemblyAI\AssemblyAI.csproj" />
30+
</ItemGroup>
31+
32+
<Import Project="AssemblyAI.Test.Custom.props" Condition="Exists('AssemblyAI.Test.Custom.props')" />
33+
</Project>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
using System.Text.Json;
4+
using System.Text.Json.Serialization;
5+
using AssemblyAI.Core;
6+
using NUnit.Framework;
7+
8+
namespace AssemblyAI.Test.Core
9+
{
10+
[TestFixture]
11+
public class StringEnumSerializerTests
12+
{
13+
private static readonly JsonSerializerOptions JsonOptions = new() { WriteIndented = true };
14+
15+
private const DummyEnum KnownEnumValue2 = DummyEnum.KnownValue2;
16+
private const string KnownEnumValue2String = "known_value2";
17+
18+
private static readonly string JsonWithKnownEnum2 = $$"""
19+
{
20+
"enum_property": "{{KnownEnumValue2String}}"
21+
}
22+
""";
23+
24+
[Test]
25+
public void ShouldParseKnownEnumValue2()
26+
{
27+
var obj = JsonSerializer.Deserialize<DummyObject>(JsonWithKnownEnum2, JsonOptions);
28+
Assert.That(obj, Is.Not.Null);
29+
Assert.That(obj.EnumProperty, Is.EqualTo(KnownEnumValue2));
30+
}
31+
32+
[Test]
33+
public void ShouldSerializeKnownEnumValue2()
34+
{
35+
var json = JsonSerializer.SerializeToElement(
36+
new DummyObject { EnumProperty = KnownEnumValue2 },
37+
JsonOptions
38+
);
39+
TestContext.Out.WriteLine("Serialized JSON: \n" + json);
40+
var enumString = json.GetProperty("enum_property").GetString();
41+
Assert.That(enumString, Is.Not.Null);
42+
Assert.That(enumString, Is.EqualTo(KnownEnumValue2String));
43+
}
44+
}
45+
46+
public class DummyObject
47+
{
48+
[JsonPropertyName("enum_property")]
49+
public DummyEnum EnumProperty { get; set; }
50+
}
51+
52+
[JsonConverter(typeof(EnumSerializer<DummyEnum>))]
53+
public enum DummyEnum
54+
{
55+
[EnumMember(Value = "known_value1")]
56+
KnownValue1,
57+
58+
[EnumMember(Value = "known_value2")]
59+
KnownValue2,
60+
}
61+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
using System;
2+
using System.Net.Http;
3+
using AssemblyAI.Core;
4+
using FluentAssertions;
5+
using NUnit.Framework;
6+
using WireMock.Server;
7+
using SystemTask = System.Threading.Tasks.Task;
8+
using WireMockRequest = WireMock.RequestBuilders.Request;
9+
using WireMockResponse = WireMock.ResponseBuilders.Response;
10+
11+
namespace AssemblyAI.Test.Core
12+
{
13+
[TestFixture]
14+
public class RawClientTests
15+
{
16+
private WireMockServer _server;
17+
private HttpClient _httpClient;
18+
private RawClient _rawClient;
19+
private string _baseUrl;
20+
private const int _maxRetries = 3;
21+
22+
[SetUp]
23+
public void SetUp()
24+
{
25+
_server = WireMockServer.Start();
26+
_baseUrl = _server.Url ?? "";
27+
_httpClient = new HttpClient { BaseAddress = new Uri(_baseUrl) };
28+
_rawClient = new RawClient(
29+
new ClientOptions() { HttpClient = _httpClient, MaxRetries = _maxRetries }
30+
);
31+
}
32+
33+
[Test]
34+
[TestCase(408)]
35+
[TestCase(429)]
36+
[TestCase(500)]
37+
[TestCase(504)]
38+
public async SystemTask MakeRequestAsync_ShouldRetry_OnRetryableStatusCodes(int statusCode)
39+
{
40+
_server
41+
.Given(WireMockRequest.Create().WithPath("/test").UsingGet())
42+
.InScenario("Retry")
43+
.WillSetStateTo("Server Error")
44+
.RespondWith(WireMockResponse.Create().WithStatusCode(statusCode));
45+
46+
_server
47+
.Given(WireMockRequest.Create().WithPath("/test").UsingGet())
48+
.InScenario("Retry")
49+
.WhenStateIs("Server Error")
50+
.WillSetStateTo("Success")
51+
.RespondWith(WireMockResponse.Create().WithStatusCode(statusCode));
52+
53+
_server
54+
.Given(WireMockRequest.Create().WithPath("/test").UsingGet())
55+
.InScenario("Retry")
56+
.WhenStateIs("Success")
57+
.RespondWith(WireMockResponse.Create().WithStatusCode(200).WithBody("Success"));
58+
59+
var request = new RawClient.BaseApiRequest
60+
{
61+
BaseUrl = _baseUrl,
62+
Method = HttpMethod.Get,
63+
Path = "/test",
64+
};
65+
66+
var response = await _rawClient.MakeRequestAsync(request);
67+
Assert.That(response.StatusCode, Is.EqualTo(200));
68+
69+
var content = await response.Raw.Content.ReadAsStringAsync();
70+
Assert.That(content, Is.EqualTo("Success"));
71+
72+
Assert.That(_server.LogEntries.Count, Is.EqualTo(_maxRetries));
73+
}
74+
75+
[Test]
76+
[TestCase(400)]
77+
[TestCase(409)]
78+
public async SystemTask MakeRequestAsync_ShouldRetry_OnNonRetryableStatusCodes(
79+
int statusCode
80+
)
81+
{
82+
_server
83+
.Given(WireMockRequest.Create().WithPath("/test").UsingGet())
84+
.InScenario("Retry")
85+
.WillSetStateTo("Server Error")
86+
.RespondWith(
87+
WireMockResponse.Create().WithStatusCode(statusCode).WithBody("Failure")
88+
);
89+
90+
var request = new RawClient.BaseApiRequest
91+
{
92+
BaseUrl = _baseUrl,
93+
Method = HttpMethod.Get,
94+
Path = "/test",
95+
};
96+
97+
var response = await _rawClient.MakeRequestAsync(request);
98+
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
99+
100+
var content = await response.Raw.Content.ReadAsStringAsync();
101+
Assert.That(content, Is.EqualTo("Failure"));
102+
103+
Assert.That(_server.LogEntries.Count, Is.EqualTo(1));
104+
}
105+
106+
[TearDown]
107+
public void TearDown()
108+
{
109+
_server.Dispose();
110+
_httpClient.Dispose();
111+
}
112+
}
113+
}

src/AssemblyAI.Test/TestClient.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using NUnit.Framework;
2+
3+
#nullable enable
4+
5+
namespace AssemblyAI.Test;
6+
7+
[TestFixture]
8+
public class TestClient { }

0 commit comments

Comments
 (0)