Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWI-1680: [.NET] Unit Tests for APIs #74

Merged
merged 5 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

.gitignore

1 change: 0 additions & 1 deletion .openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.gitignore
Bandwidth.Standard.sln
README.md
api/openapi.yaml
Expand Down
12 changes: 6 additions & 6 deletions Bandwidth.Standard.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bandwidth.Standard", "src\Bandwidth.Standard\Bandwidth.Standard.csproj", "{7D4D34CE-1DA1-4BD0-8473-2427EAFACD98}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bandwidth.Standard", "src\Bandwidth.Standard\Bandwidth.Standard.csproj", "{30F08C47-9EF1-4C33-AF8F-445E79C564E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bandwidth.Standard.Test", "src\Bandwidth.Standard.Test\Bandwidth.Standard.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
EndProject
Expand All @@ -12,10 +12,10 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7D4D34CE-1DA1-4BD0-8473-2427EAFACD98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D4D34CE-1DA1-4BD0-8473-2427EAFACD98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D4D34CE-1DA1-4BD0-8473-2427EAFACD98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D4D34CE-1DA1-4BD0-8473-2427EAFACD98}.Release|Any CPU.Build.0 = Release|Any CPU
{30F08C47-9EF1-4C33-AF8F-445E79C564E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30F08C47-9EF1-4C33-AF8F-445E79C564E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30F08C47-9EF1-4C33-AF8F-445E79C564E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30F08C47-9EF1-4C33-AF8F-445E79C564E8}.Release|Any CPU.Build.0 = Release|Any CPU
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -24,4 +24,4 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
EndGlobal
2 changes: 1 addition & 1 deletion openapi-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiName: Bandwidth
packageName: Bandwidth.Standard
packageTags: Bandwidth
packageVersion: 1.0.0
targetFramework: netstandard2.1
targetFramework: netstandard2.0
411 changes: 382 additions & 29 deletions src/Bandwidth.Standard.Test/Api/CallsApiTests.cs

Large diffs are not rendered by default.

259 changes: 197 additions & 62 deletions src/Bandwidth.Standard.Test/Api/ConferencesApiTests.cs

Large diffs are not rendered by default.

175 changes: 151 additions & 24 deletions src/Bandwidth.Standard.Test/Api/MFAApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,31 @@

using Bandwidth.Standard.Client;
using Bandwidth.Standard.Api;
// uncomment below to import models
//using Bandwidth.Standard.Model;
using Bandwidth.Standard.Model;
using Moq;
using System.Net;

namespace Bandwidth.Standard.Test.Api
{
/// <summary>
/// Class for testing MFAApi
/// </summary>
/// <remarks>
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
/// Please update the test case below to test the API endpoint.
/// </remarks>
public class MFAApiTests : IDisposable
{
private MFAApi instance;
private Mock<ISynchronousClient> mockClient;
private Mock<IAsynchronousClient> mockAsynchronousClient;
private Configuration fakeConfiguration;

public MFAApiTests()
{
instance = new MFAApi();
mockClient = new Mock<ISynchronousClient>();
mockAsynchronousClient = new Mock<IAsynchronousClient>();
fakeConfiguration = new Configuration();
fakeConfiguration.BasePath = "https://mfa.bandwidth.com/api/v1";
fakeConfiguration.Username = "username";
fakeConfiguration.Password = "password";
instance = new MFAApi(mockClient.Object, mockAsynchronousClient.Object, fakeConfiguration);
}

public void Dispose()
Expand All @@ -51,8 +57,7 @@ public void Dispose()
[Fact]
public void InstanceTest()
{
// TODO uncomment below to test 'IsType' MFAApi
//Assert.IsType<MFAApi>(instance);
Assert.IsType<MFAApi>(instance);
}

/// <summary>
Expand All @@ -61,11 +66,15 @@ public void InstanceTest()
[Fact]
public void GenerateMessagingCodeTest()
{
// TODO uncomment below to test the method and replace null with proper value
//string accountId = null;
//CodeRequest codeRequest = null;
//var response = instance.GenerateMessagingCode(accountId, codeRequest);
//Assert.IsType<MessagingCodeResponse>(response);
string accountId = "9900000";
CodeRequest codeRequest = new CodeRequest("+19195551234", "+19195554321", "66fd98ae-ac8d-a00f-7fcd-ba3280aeb9b1", "2FA", "Your temporary {NAME} {SCOPE} code is {CODE}", 6);

var apiResponse = new ApiResponse<MessagingCodeResponse>(HttpStatusCode.OK, new MessagingCodeResponse("123-456-abcd"));
mockClient.Setup(x => x.Post<MessagingCodeResponse>("/accounts/{accountId}/code/messaging", It.IsAny<RequestOptions>(), fakeConfiguration)).Returns(apiResponse);
var response = instance.GenerateMessagingCodeWithHttpInfo(accountId, codeRequest);

Assert.IsType<ApiResponse<MessagingCodeResponse>>(response);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

/// <summary>
Expand All @@ -74,11 +83,15 @@ public void GenerateMessagingCodeTest()
[Fact]
public void GenerateVoiceCodeTest()
{
// TODO uncomment below to test the method and replace null with proper value
//string accountId = null;
//CodeRequest codeRequest = null;
//var response = instance.GenerateVoiceCode(accountId, codeRequest);
//Assert.IsType<VoiceCodeResponse>(response);
string accountId = "9900000";
CodeRequest codeRequest = new CodeRequest("+19195551234", "+19195554321", "66fd98ae-ac8d-a00f-7fcd-ba3280aeb9b1", "2FA", "Your temporary {NAME} {SCOPE} code is {CODE}", 6);

var apiResponse = new ApiResponse<VoiceCodeResponse>(HttpStatusCode.OK, new VoiceCodeResponse("c-1234"));
mockClient.Setup(x => x.Post<VoiceCodeResponse>("/accounts/{accountId}/code/voice", It.IsAny<RequestOptions>(), fakeConfiguration)).Returns(apiResponse);
var response = instance.GenerateVoiceCodeWithHttpInfo(accountId, codeRequest);

Assert.IsType<ApiResponse<VoiceCodeResponse>>(response);
Assert.Equal(HttpStatusCode.OK, apiResponse.StatusCode);
}

/// <summary>
Expand All @@ -87,11 +100,125 @@ public void GenerateVoiceCodeTest()
[Fact]
public void VerifyCodeTest()
{
// TODO uncomment below to test the method and replace null with proper value
//string accountId = null;
//VerifyCodeRequest verifyCodeRequest = null;
//var response = instance.VerifyCode(accountId, verifyCodeRequest);
//Assert.IsType<VerifyCodeResponse>(response);
string accountId = "9900000";
VerifyCodeRequest verifyCodeRequest = new VerifyCodeRequest("+19195551234", "2FA", 3, "123456");

var apiResponse = new ApiResponse<VerifyCodeResponse>(HttpStatusCode.OK, new VerifyCodeResponse(true));
mockClient.Setup(x => x.Post<VerifyCodeResponse>("/accounts/{accountId}/code/verify", It.IsAny<RequestOptions>(), fakeConfiguration)).Returns(apiResponse);
var response = instance.VerifyCodeWithHttpInfo(accountId, verifyCodeRequest);

Assert.IsType<ApiResponse<VerifyCodeResponse>>(response);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

/// <summary>
/// Test failed Generate Messaging Code Request
/// </summary>
[Fact]
public void GenerateMessagingCodeBadRequest()
{
string accountId = "9900000";
CodeRequest codeRequest = new CodeRequest("+19195551234", "+19195554321", "not-an-application-id", "2FA", "Your temporary {NAME} {SCOPE} code is {CODE}", 6);

var apiResponse = new ApiResponse<MessagingCodeResponse>(HttpStatusCode.BadRequest, null);
mockClient.Setup(x => x.Post<MessagingCodeResponse>("/accounts/{accountId}/code/messaging", It.IsAny<RequestOptions>(), fakeConfiguration)).Returns(apiResponse);
ApiException Exception = Assert.Throws<ApiException>(() => instance.GenerateMessagingCode(accountId, codeRequest));

Assert.Equal("Error calling GenerateMessagingCode: ", Exception.Message);
Assert.Equal(400, Exception.ErrorCode);
}

/// <summary>
/// Test failed Generate Voice Code Request
/// </summary>
[Fact]
public void GenerateVoiceCodeBadRequest()
{
string accountId = "9900000";
CodeRequest codeRequest = new CodeRequest("+19195551234", "+19195554321", "not-an-application-id", "2FA", "Your temporary {NAME} {SCOPE} code is {CODE}", 6);

var apiResponse = new ApiResponse<VoiceCodeResponse>(HttpStatusCode.BadRequest, null);
mockClient.Setup(x => x.Post<VoiceCodeResponse>("/accounts/{accountId}/code/voice", It.IsAny<RequestOptions>(), fakeConfiguration)).Returns(apiResponse);
ApiException Exception = Assert.Throws<ApiException>(() => instance.GenerateVoiceCode(accountId, codeRequest));

Assert.Equal("Error calling GenerateVoiceCode: ", Exception.Message);
Assert.Equal(400, Exception.ErrorCode);
}

/// <summary>
/// Test unauthorized Generate Messaging Code Request
/// </summary>
[Fact]
public void GenerateMessagingCodeUnauthorizedRequest()
{
string accountId = "9900000";
CodeRequest codeRequest = new CodeRequest("+19195551234", "+19195554321", "123-456-abcd", "2FA", "Your temporary {NAME} {SCOPE} code is {CODE}", 6);
fakeConfiguration.Username = "badUsername";
fakeConfiguration.Password = "badPassword";

var apiResponse = new ApiResponse<MessagingCodeResponse>(HttpStatusCode.Unauthorized, new MessagingCodeResponse("Unauthorized"));
mockClient.Setup(x => x.Post<MessagingCodeResponse>("/accounts/{accountId}/code/messaging", It.IsAny<RequestOptions>(), fakeConfiguration)).Returns(apiResponse);
ApiException Exception = Assert.Throws<ApiException>(() => instance.GenerateMessagingCode(accountId, codeRequest));

Assert.Equal("Error calling GenerateMessagingCode: ", Exception.Message);
Assert.Equal(401, Exception.ErrorCode);
}

/// <summary>
/// Test unauthorized Generate Voice Code Request
/// </summary>
[Fact]
public void GenerateVoiceCodeUnauthorizedRequest()
{
string accountId = "9900000";
CodeRequest codeRequest = new CodeRequest("+19195551234", "+19195554321", "123-456-abcd", "2FA", "Your temporary {NAME} {SCOPE} code is {CODE}", 6);
fakeConfiguration.Username = "badUsername";
fakeConfiguration.Password = "badPassword";

var apiResponse = new ApiResponse<VoiceCodeResponse>(HttpStatusCode.Unauthorized, new VoiceCodeResponse("Unauthorized"));
mockClient.Setup(x => x.Post<VoiceCodeResponse>("/accounts/{accountId}/code/voice", It.IsAny<RequestOptions>(), fakeConfiguration)).Returns(apiResponse);
ApiException Exception = Assert.Throws<ApiException>(() => instance.GenerateVoiceCode(accountId, codeRequest));

Assert.Equal("Error calling GenerateVoiceCode: ", Exception.Message);
Assert.Equal(401, Exception.ErrorCode);
}

/// <summary>
/// Test forbidden Generate Messaging Code Request
/// </summary>
[Fact]
public void GenerateMessagingCodeForbiddenRequest()
{
string accountId = "9900000";
CodeRequest codeRequest = new CodeRequest("+19195551234", "+19195554321", "123-456-abcd", "2FA", "Your temporary {NAME} {SCOPE} code is {CODE}", 6);
fakeConfiguration.Username = "forbiddenUsername";
fakeConfiguration.Password = "badPassword";

var apiResponse = new ApiResponse<MessagingCodeResponse>(HttpStatusCode.Forbidden, new MessagingCodeResponse("Missing Authentication Token"));
mockClient.Setup(x => x.Post<MessagingCodeResponse>("/accounts/{accountId}/code/messaging", It.IsAny<RequestOptions>(), fakeConfiguration)).Returns(apiResponse);
ApiException Exception = Assert.Throws<ApiException>(() => instance.GenerateMessagingCode(accountId, codeRequest));

Assert.Equal("Error calling GenerateMessagingCode: ", Exception.Message);
Assert.Equal(403, Exception.ErrorCode);
}

/// <summary>
/// Test forbidden Generate Voice Code Request
/// </summary>
[Fact]
public void GenerateVoiceCodeForbiddenRequest()
{
string accountId = "9900000";
CodeRequest codeRequest = new CodeRequest("+19195551234", "+19195554321", "123-456-abcd", "2FA", "Your temporary {NAME} {SCOPE} code is {CODE}", 6);
fakeConfiguration.Username = "forbiddenUsername";
fakeConfiguration.Password = "badPassword";

var apiResponse = new ApiResponse<VoiceCodeResponse>(HttpStatusCode.Forbidden, new VoiceCodeResponse("Missing Authentication Token"));
mockClient.Setup(x => x.Post<VoiceCodeResponse>("/accounts/{accountId}/code/voice", It.IsAny<RequestOptions>(), fakeConfiguration)).Returns(apiResponse);
ApiException Exception = Assert.Throws<ApiException>(() => instance.GenerateVoiceCode(accountId, codeRequest));

Assert.Equal("Error calling GenerateVoiceCode: ", Exception.Message);
Assert.Equal(403, Exception.ErrorCode);
}
}
}
Loading
Loading