diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml
index f3b39fb..2c336e1 100644
--- a/.github/workflows/test-pr.yml
+++ b/.github/workflows/test-pr.yml
@@ -34,7 +34,7 @@ jobs:
strategy:
matrix:
os: [windows-2022, windows-2025, ubuntu-22.04, ubuntu-24.04]
- dotnet: [6.0.x, 7.0.x, 8.0.x]
+ dotnet: [6.0.x, 7.0.x, 8.0.x, 10.0.x]
fail-fast: false
steps:
- name: Checkout
@@ -50,4 +50,5 @@ jobs:
OPERATING_SYSTEM: ${{ matrix.os }}
DOTNET_VERSION: ${{ matrix.dotnet }}
run: |
- dotnet test src/Bandwidth.Standard.Test --filter DisplayName~Bandwidth.Standard.Test.Unit
+ npm install -g @stoplight/prism-cli
+ prism mock ./bandwidth.yml & dotnet test src/Bandwidth.Standard.Test --filter DisplayName~Bandwidth.Standard.Test.Unit
diff --git a/src/Bandwidth.Standard.Test/Unit/Api/CallsApiTests.cs b/src/Bandwidth.Standard.Test/Unit/Api/CallsApiTests.cs
index 0021482..ef1b3dd 100644
--- a/src/Bandwidth.Standard.Test/Unit/Api/CallsApiTests.cs
+++ b/src/Bandwidth.Standard.Test/Unit/Api/CallsApiTests.cs
@@ -9,41 +9,46 @@
*/
using System;
-using System.IO;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Reflection;
-using RestSharp;
+using System.Net;
using Xunit;
using Bandwidth.Standard.Client;
using Bandwidth.Standard.Api;
using Bandwidth.Standard.Model;
-using Moq;
-using System.Net;
namespace Bandwidth.Standard.Test.Unit.Api
{
///
- /// Class for testing CallsApi
+ /// CallsApi Unit Tests
///
public class CallsApiTests : IDisposable
{
- private CallsApi instance;
- private Mock mockClient;
- private Mock mockAsynchronousClient;
- private Configuration fakeConfiguration;
+ private readonly CallsApi instance;
+
+ private readonly string accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID");
+ private readonly string userNumber = Environment.GetEnvironmentVariable("USER_NUMBER");
+ private readonly string bwNumber = Environment.GetEnvironmentVariable("BW_NUMBER");
+ private readonly string voiceApplicationId = Environment.GetEnvironmentVariable("BW_VOICE_APPLICATION_ID");
+ private readonly string callbackUrl = Environment.GetEnvironmentVariable("BASE_CALLBACK_URL");
+
+ private readonly string callId = "c-1234";
+ private readonly string displayName = "C# SDK";
+ private readonly CallbackMethodEnum answerMethod = CallbackMethodEnum.POST;
+ private readonly CallbackMethodEnum disconnectMethod = CallbackMethodEnum.GET;
+ private readonly double callTimeout = 30.0;
+ private readonly double callbackTimeout = 15.0;
public CallsApiTests()
{
- mockClient = new Mock();
- mockAsynchronousClient = new Mock();
- fakeConfiguration = new Configuration();
- fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2";
- fakeConfiguration.Username = "username";
- fakeConfiguration.Password = "password";
- instance = new CallsApi(mockClient.Object, mockAsynchronousClient.Object, fakeConfiguration);
+ Configuration configuration = new()
+ {
+ BasePath = "http://127.0.0.1:4010",
+ IgnoreOperationServers = true,
+ OAuthClientId = Environment.GetEnvironmentVariable("BW_CLIENT_ID"),
+ OAuthClientSecret = Environment.GetEnvironmentVariable("BW_CLIENT_SECRET")
+ };
+ instance = new CallsApi(configuration);
}
public void Dispose()
@@ -66,228 +71,113 @@ public void InstanceTest()
[Fact]
public void CreateCallTest()
{
- string accountId = "9900000";
- CreateCall createCall = new CreateCall(
- to: "+19195551234",
- from: "+19195554321",
- applicationId: "1234-qwer-5679-tyui",
- answerUrl: "https://www.myCallbackServer.example/webhooks/answer"
- );
- CreateCallResponse callResponse = new CreateCallResponse(
- applicationId: "04e88489-df02-4e34-a0ee-27a91849555f",
- accountId: "9900000",
- callId: "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85",
- to: "+19195551234",
- from: "+19195554321",
- callUrl: "https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85",
- answerMethod: CallbackMethodEnum.POST,
- answerUrl: "https://myServer.example/bandwidth/webhooks/answer",
- disconnectMethod: CallbackMethodEnum.POST
+ MachineDetectionConfiguration machineDetection = new(
+ mode: MachineDetectionModeEnum.Async,
+ detectionTimeout: 5.0,
+ silenceTimeout: 5.0,
+ speechThreshold: 5.0,
+ speechEndThreshold: 5.0,
+ delayResult: true,
+ callbackUrl: callbackUrl,
+ callbackMethod: CallbackMethodEnum.POST
);
- var apiResponse = new ApiResponse(HttpStatusCode.Created, callResponse);
- mockClient.Setup(x => x.Post("/accounts/{accountId}/calls", It.IsAny(), fakeConfiguration)).Returns(apiResponse);
- var response = instance.CreateCallWithHttpInfo(accountId, createCall);
-
- Assert.IsType>(response);
- Assert.Equal(HttpStatusCode.Created, response.StatusCode);
- }
-
- ///
- /// Test failed CreateCall Request
- ///
- [Fact]
- public void CreateCallBadRequest()
- {
- string accountId = "9900000";
- CreateCall createCall = new CreateCall(
- to: "invalidNumber",
- from: "+19195554321",
- applicationId: "1234-qwer-5679-tyui",
- answerUrl: "https://www.myCallbackServer.example/webhooks/answer"
+ CreateCall createCall = new(
+ applicationId: voiceApplicationId,
+ to: userNumber,
+ from: bwNumber,
+ privacy: false,
+ displayName: displayName,
+ answerUrl: callbackUrl,
+ answerMethod: answerMethod,
+ disconnectUrl: callbackUrl,
+ disconnectMethod: disconnectMethod,
+ machineDetection: machineDetection,
+ callTimeout: callTimeout,
+ callbackTimeout: callbackTimeout
);
- var apiResponse = new ApiResponse(HttpStatusCode.BadRequest, null);
- mockClient.Setup(x => x.Post("/accounts/{accountId}/calls", It.IsAny(), fakeConfiguration)).Returns(apiResponse);
- ApiException Exception = Assert.Throws(() => instance.CreateCall(accountId, createCall));
-
- Assert.Equal("Error calling CreateCall: ", Exception.Message);
- Assert.Equal(400, Exception.ErrorCode);
- }
+ ApiResponse response = instance.CreateCallWithHttpInfo(accountId, createCall);
- ///
- /// Test unauthorized CreateCall Request
- ///
- [Fact]
- public void CreateCallUnauthorizedRequest()
- {
- string accountId = "9900000";
- CreateCall createCall = new CreateCall(
- to: "+19195551234",
- from: "+19195554321",
- applicationId: "1234-qwer-5679-tyui",
- answerUrl: "https://www.myCallbackServer.example/webhooks/answer"
- );
- fakeConfiguration.Username = "badUsername";
- fakeConfiguration.Password = "badPassword";
-
- var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null);
- mockClient.Setup(x => x.Post("/accounts/{accountId}/calls", It.IsAny(), fakeConfiguration)).Returns(apiResponse);
- ApiException Exception = Assert.Throws(() => instance.CreateCall(accountId, createCall));
-
- Assert.Equal("Error calling CreateCall: ", Exception.Message);
- Assert.Equal(401, Exception.ErrorCode);
+ Assert.Equal(HttpStatusCode.Created, response.StatusCode);
+ Assert.IsType(response.Data);
+ Assert.Equal(36, response.Data.ApplicationId.Length);
+ Assert.Equal(7, response.Data.AccountId.Length);
+ Assert.Equal(47, response.Data.CallId.Length);
+ Assert.Equal(12, response.Data.To.Length);
+ Assert.Equal(12, response.Data.From.Length);
+ Assert.IsType(response.Data.EnqueuedTime);
+ Assert.IsType(response.Data.CallUrl);
+ Assert.IsType(response.Data.CallTimeout);
+ Assert.IsType(response.Data.CallbackTimeout);
+ Assert.IsType(response.Data.Tag);
+ Assert.IsType(response.Data.AnswerMethod);
+ Assert.IsType(response.Data.AnswerUrl);
+ Assert.IsType(response.Data.AnswerFallbackMethod);
+ Assert.IsType(response.Data.AnswerFallbackUrl);
+ Assert.IsType(response.Data.DisconnectMethod);
+ Assert.IsType(response.Data.DisconnectUrl);
+ Assert.IsType(response.Data.Username);
+ Assert.IsType(response.Data.Password);
+ Assert.IsType(response.Data.FallbackUsername);
+ Assert.IsType(response.Data.FallbackPassword);
+ Assert.IsType(response.Data.Priority);
}
- ///
- /// Test forbidden CreateCall Request
- ///
- [Fact]
- public void CreateCallForbiddenRequest()
- {
- string accountId = "9900000";
- CreateCall createCall = new CreateCall(
- to: "+19195551234",
- from: "+19195554321",
- applicationId: "1234-qwer-5679-tyui",
- answerUrl: "https://www.myCallbackServer.example/webhooks/answer"
- );
- fakeConfiguration.Username = "forbiddenUsername";
- fakeConfiguration.Password = "forbiddenPassword";
-
- var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null);
- mockClient.Setup(x => x.Post("/accounts/{accountId}/calls", It.IsAny(), fakeConfiguration)).Returns(apiResponse);
- ApiException Exception = Assert.Throws(() => instance.CreateCall(accountId, createCall));
-
- Assert.Equal("Error calling CreateCall: ", Exception.Message);
- Assert.Equal(403, Exception.ErrorCode);
- }
-
///
/// Test GetCallState
///
[Fact]
public void GetCallStateTest()
{
- string accountId = "9900000";
- string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85";
-
- var apiResponse = new ApiResponse(HttpStatusCode.OK, new CallState());
- mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse);
- var response = instance.GetCallStateWithHttpInfo(accountId, callId);
+ ApiResponse response = instance.GetCallStateWithHttpInfo(accountId, callId);
- Assert.IsType>(response);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
+ Assert.IsType(response.Data);
+ Assert.Equal(36, response.Data.ApplicationId.Length);
+ Assert.Equal(7, response.Data.AccountId.Length);
+ Assert.Equal(47, response.Data.CallId.Length);
+ Assert.Equal(47, response.Data.ParentCallId.Length);
+ Assert.Equal(12, response.Data.To.Length);
+ Assert.Equal(12, response.Data.From.Length);
+ Assert.IsType(response.Data.Direction);
+ Assert.IsType(response.Data.State);
+ Assert.IsType>(response.Data.StirShaken);
+ Assert.IsType(response.Data.Identity);
+ Assert.IsType(response.Data.EnqueuedTime);
+ Assert.IsType(response.Data.StartTime);
+ Assert.IsType(response.Data.AnswerTime);
+ Assert.IsType(response.Data.EndTime);
+ Assert.IsType(response.Data.DisconnectCause);
+ Assert.IsType(response.Data.LastUpdate);
}
- ///
- /// Test unauthorized GetCallState Request
- ///
- [Fact]
- public void GetCallStateUnauthorizedRequest()
- {
- string accountId = "9900000";
- string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85";
- fakeConfiguration.Username = "badUsername";
- fakeConfiguration.Password = "badPassword";
-
- var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null);
- mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse);
- ApiException Exception = Assert.Throws(() => instance.GetCallState(accountId, callId));
-
- Assert.Equal("Error calling GetCallState: ", Exception.Message);
- Assert.Equal(401, Exception.ErrorCode);
- }
-
- ///
- /// Test forbidden GetCallState Request
- ///
- [Fact]
- public void GetCallStateForbiddenRequest()
- {
- string accountId = "9900000";
- string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85";
- fakeConfiguration.Username = "forbiddenUsername";
- fakeConfiguration.Password = "forbiddenPassword";
-
- var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null);
- mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse);
- ApiException Exception = Assert.Throws(() => instance.GetCallState(accountId, callId));
-
- Assert.Equal("Error calling GetCallState: ", Exception.Message);
- Assert.Equal(403, Exception.ErrorCode);
- }
-
- ///
- /// Test not found GetCallState Request
- ///
- [Fact]
- public void GetCallStateNotFoundRequest()
- {
- string accountId = "9900000";
- string callId = "not a call id";
-
- var apiResponse = new ApiResponse(HttpStatusCode.NotFound, null);
- mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse);
- ApiException Exception = Assert.Throws(() => instance.GetCallState(accountId, callId));
-
- Assert.Equal("Error calling GetCallState: ", Exception.Message);
- Assert.Equal(404, Exception.ErrorCode);
- }
-
///
/// Test ListCalls
///
[Fact]
public void ListCallsTest()
{
- string accountId = "9900000";
- CallState callState = new CallState(
- state: "answered"
- );
-
- var apiResponse = new ApiResponse>(HttpStatusCode.OK, new List() { callState });
- mockClient.Setup(x => x.Get>("/accounts/{accountId}/calls", It.IsAny(), fakeConfiguration)).Returns(apiResponse);
- var response = instance.ListCallsWithHttpInfo(accountId);
+ ApiResponse> response = instance.ListCallsWithHttpInfo(accountId, userNumber, bwNumber);
- Assert.IsType>>(response);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- }
-
- ///
- /// Test unauthorized ListCalls Request
- ///
- [Fact]
- public void ListCallsUnauthorizedRequest()
- {
- string accountId = "9900000";
- fakeConfiguration.Username = "badUsername";
- fakeConfiguration.Password = "badPassword";
-
- var apiResponse = new ApiResponse>(HttpStatusCode.Unauthorized, null);
- mockClient.Setup(x => x.Get>("/accounts/{accountId}/calls", It.IsAny(), fakeConfiguration)).Returns(apiResponse);
- ApiException Exception = Assert.Throws(() => instance.ListCalls(accountId));
-
- Assert.Equal("Error calling ListCalls: ", Exception.Message);
- Assert.Equal(401, Exception.ErrorCode);
- }
-
- ///
- /// Test forbidden ListCalls Request
- ///
- [Fact]
- public void ListCallsForbiddenRequest()
- {
- string accountId = "9900000";
- fakeConfiguration.Username = "forbiddenUsername";
- fakeConfiguration.Password = "forbiddenPassword";
-
- var apiResponse = new ApiResponse>(HttpStatusCode.Forbidden, null);
- mockClient.Setup(x => x.Get>("/accounts/{accountId}/calls", It.IsAny(), fakeConfiguration)).Returns(apiResponse);
- ApiException Exception = Assert.Throws(() => instance.ListCalls(accountId));
-
- Assert.Equal("Error calling ListCalls: ", Exception.Message);
- Assert.Equal(403, Exception.ErrorCode);
+ Assert.IsType(response.Data[0]);
+ Assert.Equal(36, response.Data[0].ApplicationId.Length);
+ Assert.Equal(7, response.Data[0].AccountId.Length);
+ Assert.Equal(47, response.Data[0].CallId.Length);
+ Assert.Equal(47, response.Data[0].ParentCallId.Length);
+ Assert.Equal(12, response.Data[0].To.Length);
+ Assert.Equal(12, response.Data[0].From.Length);
+ Assert.IsType(response.Data[0].Direction);
+ Assert.IsType(response.Data[0].State);
+ Assert.IsType>(response.Data[0].StirShaken);
+ Assert.IsType(response.Data[0].Identity);
+ Assert.IsType(response.Data[0].EnqueuedTime);
+ Assert.IsType(response.Data[0].StartTime);
+ Assert.IsType(response.Data[0].AnswerTime);
+ Assert.IsType(response.Data[0].EndTime);
+ Assert.IsType(response.Data[0].DisconnectCause);
+ Assert.IsType(response.Data[0].LastUpdate);
}
///
@@ -296,147 +186,13 @@ public void ListCallsForbiddenRequest()
[Fact]
public void UpdateCallTest()
{
- string accountId = "9900000";
- string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85";
- UpdateCall updateCall = new UpdateCall(
- state: CallStateEnum.Completed,
- redirectUrl: "https://myServer.example/bandwidth/webhooks/redirect",
- redirectMethod: RedirectMethodEnum.POST,
- username: "username",
- password: "password",
- redirectFallbackUrl: "https://myFallbackServer.example/bandwidth/webhooks/redirect",
- redirectFallbackMethod: RedirectMethodEnum.POST,
- fallbackUsername: "fallbackUsername",
- fallbackPassword: "fallbackPassword",
- tag: "My Custom Tag"
+ UpdateCall updateCall = new(
+ state: CallStateEnum.Active
);
- var apiResponse = new ApiResponse