Skip to content
Closed
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
5 changes: 0 additions & 5 deletions .github/workflows/snyk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@ jobs:
run: dotnet restore
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/dotnet@master
continue-on-error: true # To make sure that SARIF upload gets called
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args:
--all-projects
--sarif-file-output=snyk.sarif
--severity-threshold=high
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: snyk.sarif
34 changes: 18 additions & 16 deletions ApiClient.Tests/Api/ApiTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Globalization;
using System.Reflection;
using System.Runtime.Serialization;
using Infobip.Api.Client;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WireMock.Matchers;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
Expand All @@ -22,26 +22,28 @@ public class ApiTest
protected const string SERVER_HEADER_VALUE_COMMA = "SMS,API";
protected const string X_REQUEST_ID_HEADER_VALUE = "1608758729810312842";

protected Configuration? configuration;
protected Configuration? Configuration;

protected WireMockServer? wireMockServer;
protected WireMockServer? WireMockServer;

[TestInitialize]
public void StartMockServer()
{
wireMockServer = WireMockServer.Start();
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;

WireMockServer = WireMockServer.Start();

configuration = new Configuration
Configuration = new Configuration
{
ApiKey = API_KEY,
BasePath = "http://localhost:" + wireMockServer.Ports[0]
BasePath = "http://localhost:" + WireMockServer.Ports[0]
};
}

[TestCleanup]
public void TearDown()
{
wireMockServer!.Stop();
WireMockServer!.Stop();
}

protected void SetUpGetRequest(string url, int statusCode, string expectedResponse,
Expand All @@ -55,7 +57,7 @@ protected void SetUpGetRequest(string url, int statusCode, string expectedRespon
if (givenParameters != null && givenParameters.Count > 0)
request = request.WithParam(EqualToParams(givenParameters));

wireMockServer!.Given(request)
WireMockServer!.Given(request)
.RespondWith(Response.Create()
.WithStatusCode(statusCode)
.WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE)
Expand All @@ -75,7 +77,7 @@ protected void SetUpGetRequestBinary(string url, int statusCode, string expected
if (givenParameters != null && givenParameters.Count > 0)
request = request.WithParam(EqualToParams(givenParameters));

wireMockServer!.Given(request)
WireMockServer!.Given(request)
.RespondWith(Response.Create()
.WithStatusCode(statusCode)
.WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE)
Expand Down Expand Up @@ -107,7 +109,7 @@ protected void SetUpPostRequest(string url, int statusCode, string? givenRequest
response = response.WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE)
.WithBody(expectedResponse);

wireMockServer!.Given(request).RespondWith(response);
WireMockServer!.Given(request).RespondWith(response);
}

protected void SetUpPatchRequest(string url, int statusCode, string givenRequest, string? expectedResponse = null,
Expand All @@ -132,7 +134,7 @@ protected void SetUpPatchRequest(string url, int statusCode, string givenRequest
response = response.WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE)
.WithBody(expectedResponse);

wireMockServer!.Given(request).RespondWith(response);
WireMockServer!.Given(request).RespondWith(response);
}

protected void SetUpPutRequest(string url, int statusCode, string givenRequest, string? expectedResponse = null,
Expand All @@ -157,7 +159,7 @@ protected void SetUpPutRequest(string url, int statusCode, string givenRequest,
response = response.WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE)
.WithBody(expectedResponse);

wireMockServer!.Given(request).RespondWith(response);
WireMockServer!.Given(request).RespondWith(response);
}

protected void SetUpDeleteRequest(string url, int statusCode, string? givenRequest = null,
Expand All @@ -182,7 +184,7 @@ protected void SetUpDeleteRequest(string url, int statusCode, string? givenReque
response = response.WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE)
.WithBody(expectedResponse);

wireMockServer!.Given(request).RespondWith(response);
WireMockServer!.Given(request).RespondWith(response);
}

protected void SetUpMultipartFormRequest(string url, Multimap<string, string> givenParts, string expectedResponse,
Expand All @@ -197,9 +199,9 @@ protected void SetUpMultipartFormRequest(string url, Multimap<string, string> gi
req.WithBody(body =>
{
var allKeysFound = givenParts.All(kvp =>
body.Contains($"name={kvp.Key}", StringComparison.InvariantCultureIgnoreCase));
body!.Contains($"name={kvp.Key}", StringComparison.InvariantCultureIgnoreCase));
var allValuesFound = givenParts.All(kvp =>
kvp.Value.All(value => body.Contains(value, StringComparison.InvariantCultureIgnoreCase)));
kvp.Value.All(value => body!.Contains(value, StringComparison.InvariantCultureIgnoreCase)));
return allValuesFound && allKeysFound;
});

Expand All @@ -210,7 +212,7 @@ protected void SetUpMultipartFormRequest(string url, Multimap<string, string> gi
.WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE)
.WithBody(expectedResponse);

wireMockServer!.Given(req).RespondWith(resp);
WireMockServer!.Given(req).RespondWith(resp);
}

private Func<IDictionary<string, WireMockList<string>>, bool>[] EqualToParams(Dictionary<string, string> parameters)
Expand Down
15 changes: 7 additions & 8 deletions ApiClient.Tests/Api/CallRoutingApiTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Infobip.Api.Client.Api;
using Infobip.Api.Client.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using JsonSerializer = System.Text.Json.JsonSerializer;

Expand Down Expand Up @@ -115,7 +114,7 @@ public void ShouldGetCallRoutes()

SetUpGetRequest(CALL_ROUTING_ROUTES, 200, expectedResponse, givenQueryParameters);

var callRoutingApi = new CallRoutingApi(configuration);
var callRoutingApi = new CallRoutingApi(Configuration);

void AssertCallRoutingRouteResponsePage(CallRoutingRouteResponsePage callRoutingRouteResponsePage)
{
Expand Down Expand Up @@ -266,7 +265,7 @@ public void ShouldCreateCallRoute()

SetUpPostRequest(CALL_ROUTING_ROUTES, 201, givenRequest, expectedResponse);

var callRoutingApi = new CallRoutingApi(configuration);
var callRoutingApi = new CallRoutingApi(Configuration);

var callroutingRouteRequest = new CallRoutingRouteRequest(
givenName,
Expand Down Expand Up @@ -367,7 +366,7 @@ public void ShouldGetCallRoute()

SetUpGetRequest(CALL_ROUTING_ROUTE.Replace("{routeId}", givenRouteId), 200, expectedResponse);

var callRoutingApi = new CallRoutingApi(configuration);
var callRoutingApi = new CallRoutingApi(Configuration);

void AssertCallRoutingRouteResponsePage(CallRoutingRouteResponse callRoutingRouteResponse)
{
Expand Down Expand Up @@ -487,7 +486,7 @@ public void ShouldUpdateCallRoutes()

SetUpPutRequest(CALL_ROUTING_ROUTE.Replace("{routeId}", givenRouteId), 200, givenRequest, expectedResponse);

var callRoutingApi = new CallRoutingApi(configuration);
var callRoutingApi = new CallRoutingApi(Configuration);

var callroutingRouteRequest = new CallRoutingRouteRequest(
givenName,
Expand Down Expand Up @@ -591,7 +590,7 @@ public void ShouldDeleteCallRoutes()
SetUpDeleteRequest(CALL_ROUTING_ROUTE.Replace("{routeId}", givenRouteId), 200,
expectedResponse: exectedResponse, givenParameters: new Dictionary<string, string>());

var callRoutingApi = new CallRoutingApi(configuration);
var callRoutingApi = new CallRoutingApi(Configuration);

void AssertCallRoutingRouteResponsePage(CallRoutingRouteResponse callRoutingRouteResponse)
{
Expand Down Expand Up @@ -628,7 +627,7 @@ public void ShouldUrlDestinationWebhook()
var expectedSipTrunkId = "60d345fd3a799ec";
var expectedValueType = "SIP";
var expectedConnectTimeout = 30;
var expectedRecordingType = CallRoutingRecordingType.Audio;
var expectedRecordingType = "AUDIO";
var expectedType = "ENDPOINT";

var expectedResponse = $@"
Expand Down Expand Up @@ -689,7 +688,7 @@ void AssertCallRoutingEndpointDestinationResponse(
Assert.AreEqual(expectedSipTrunkId, callRoutingSipEndpoint.SipTrunkId);

Assert.AreEqual(expectedConnectTimeout, callRoutingEndpointDestinationResponse.ConnectTimeout);
Assert.AreEqual(expectedRecordingType, callRoutingEndpointDestinationResponse.Recording.RecordingType);
Assert.AreEqual(expectedRecordingType, GetEnumAttributeValue(callRoutingEndpointDestinationResponse.Recording.RecordingType));
}

void AssertCallRoutingUrlDestinationHttpRequest(
Expand Down
Loading
Loading