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

removal of Moq #114

Merged
merged 1 commit into from
Aug 11, 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
8 changes: 1 addition & 7 deletions Deepgram.Tests/ClientTests/DeepgramClientTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using Deepgram.Clients;
using Deepgram.Interfaces;
using Deepgram.Tests.Fakers;
using Deepgram.Utilities;
using Xunit;


namespace Deepgram.Tests.ClientTests
{
public class DeepClientTests
Expand Down
10 changes: 3 additions & 7 deletions Deepgram.Tests/ClientTests/KeyClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using AutoBogus;
using Bogus;
using AutoBogus;
using Deepgram.Models;
using Deepgram.Tests.Fakers;
using Deepgram.Tests.Fakes;
using Xunit;

namespace Deepgram.Tests.ClientTests
{
Expand Down Expand Up @@ -94,8 +90,8 @@ private static DeepgramClient GetDeepgramClient<T>(T returnObject)
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;
SUT.Keys.ApiRequest = mockIApiRequest;
SUT.Keys.RequestMessageBuilder = mockIRequestMessageBuilder;
return SUT;
}

Expand Down
11 changes: 4 additions & 7 deletions Deepgram.Tests/ClientTests/PrerecordedTranscriptionTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using AutoBogus;
using Bogus;
using Deepgram.Models;
using Deepgram.Request;
using Deepgram.Tests.Fakers;
using Deepgram.Tests.Fakes;
using Xunit;

namespace Deepgram.Tests.ClientTests
{
Expand Down Expand Up @@ -61,7 +58,7 @@ public async void Should_Return_A_Summary_Short_When_Summarize_Set_To_v2()
var SUT = GetDeepgramClient(responseObject);

responseObject.Results.Summary.Short = "This is a test summary";
var client = FakeHttpMessageHandler.CreateHttpClientWithResult(responseObject);
var client = MockHttpClient.CreateHttpClientWithResult(responseObject);
var fakeOptions = new PrerecordedTranscriptionOptions()
{
Summarize = "v2"
Expand All @@ -88,7 +85,7 @@ public async void Should_Return_A_Summary_Short_When_Summarize_Set_To_bool(bool
var responseObject = new AutoFaker<PrerecordedTranscription>().Generate();
var SUT = GetDeepgramClient(responseObject);
responseObject.Results.Summary.Short = null;
var client = FakeHttpMessageHandler.CreateHttpClientWithResult(responseObject);
var client = MockHttpClient.CreateHttpClientWithResult(responseObject);
var fakeOptions = new PrerecordedTranscriptionOptions()
{
Summarize = value
Expand All @@ -113,8 +110,8 @@ private static DeepgramClient GetDeepgramClient<T>(T returnObject)
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;
SUT.Transcription.Prerecorded.ApiRequest = mockIApiRequest;
SUT.Transcription.Prerecorded.RequestMessageBuilder = mockIRequestMessageBuilder;
return SUT;
}
}
Expand Down
7 changes: 2 additions & 5 deletions Deepgram.Tests/ClientTests/ProjectClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using AutoBogus;
using Bogus;
using Deepgram.Models;
using Deepgram.Tests.Fakers;
using Deepgram.Tests.Fakes;
using Xunit;

namespace Deepgram.Tests.ClientTests
{
Expand Down Expand Up @@ -170,8 +167,8 @@ private static DeepgramClient GetDeepgramClient<T>(T returnObject)
var mockIApiRequest = MockIApiRequest.Create(returnObject);
var credentials = new CredentialsFaker().Generate();
var SUT = new DeepgramClient(credentials);
SUT.Projects.ApiRequest = mockIApiRequest.Object;
SUT.Projects.RequestMessageBuilder = mockIRequestMessageBuilder.Object;
SUT.Projects.ApiRequest = mockIApiRequest;
SUT.Projects.RequestMessageBuilder = mockIRequestMessageBuilder;
return SUT;
}
}
Expand Down
9 changes: 3 additions & 6 deletions Deepgram.Tests/ClientTests/UsageClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using AutoBogus;
using AutoBogus;
using Deepgram.Models;
using Deepgram.Tests.Fakers;
using Deepgram.Tests.Fakes;
using Xunit;

namespace Deepgram.Tests.ClientTests
{
Expand Down Expand Up @@ -88,8 +85,8 @@ private static DeepgramClient GetDeepgramClient<T>(T returnObject)
var mockIApiRequest = MockIApiRequest.Create(returnObject);
var credentials = new CredentialsFaker().Generate();
var SUT = new DeepgramClient(credentials);
SUT.Usage.ApiRequest = mockIApiRequest.Object;
SUT.Usage.RequestMessageBuilder = mockIRequestMessageBuilder.Object;
SUT.Usage.ApiRequest = mockIApiRequest;
SUT.Usage.RequestMessageBuilder = mockIRequestMessageBuilder;
return SUT;
}

Expand Down
13 changes: 7 additions & 6 deletions Deepgram.Tests/Deepgram.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="AutoBogus" Version="2.13.1"/>
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="AutoBogus" Version="2.13.1" />
<PackageReference Include="NSubstitute" Version="5.0.0" />

<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
44 changes: 0 additions & 44 deletions Deepgram.Tests/Fakes/FakeHttpMessageHandler.cs

This file was deleted.

17 changes: 17 additions & 0 deletions Deepgram.Tests/Fakes/MockHttpClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

namespace Deepgram.Tests.Fakes
{
public static class MockHttpClient
{
public static HttpClient CreateHttpClientWithResult<T>(
T result, HttpStatusCode code = HttpStatusCode.OK)
{
var httpClient = new HttpClient(new MockHttpMessageHandler(result, code))
{
BaseAddress = new Uri(new Faker().Internet.Url()),
};

return httpClient;
}
}
}
22 changes: 22 additions & 0 deletions Deepgram.Tests/Fakes/MockHttpMessageHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;

namespace Deepgram.Tests.Fakes;
public class MockHttpMessageHandler : HttpMessageHandler
{
private readonly object _response;
private readonly HttpStatusCode _statusCode;
public MockHttpMessageHandler(object response, HttpStatusCode statusCode)
{
_response = response;
_statusCode = statusCode;
}

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

Check warning on line 14 in Deepgram.Tests/Fakes/MockHttpMessageHandler.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 14 in Deepgram.Tests/Fakes/MockHttpMessageHandler.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 14 in Deepgram.Tests/Fakes/MockHttpMessageHandler.cs

View workflow job for this annotation

GitHub Actions / test (3.1.x)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 14 in Deepgram.Tests/Fakes/MockHttpMessageHandler.cs

View workflow job for this annotation

GitHub Actions / test (5.0.x)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 14 in Deepgram.Tests/Fakes/MockHttpMessageHandler.cs

View workflow job for this annotation

GitHub Actions / test (6.0.x)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 14 in Deepgram.Tests/Fakes/MockHttpMessageHandler.cs

View workflow job for this annotation

GitHub Actions / test (7.0.x)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
return new HttpResponseMessage()
{
StatusCode = _statusCode,
Content = new StringContent(JsonConvert.SerializeObject(_response))
};
}
}
12 changes: 4 additions & 8 deletions Deepgram.Tests/Fakes/MockIApiRequest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using System.Net.Http;
using Deepgram.Interfaces;
using Moq;

namespace Deepgram.Tests.Fakes
namespace Deepgram.Tests.Fakes
{
public class MockIApiRequest
{
public static Mock<IApiRequest> Create<T>(T returnObject)
public static IApiRequest Create<T>(T returnObject)
{
var mockAPiRequest = new Mock<IApiRequest>();
mockAPiRequest.Setup(x => x.SendHttpRequestAsync<T>(It.IsAny<HttpRequestMessage>())).ReturnsAsync(returnObject);
var mockAPiRequest = Substitute.For<IApiRequest>();
mockAPiRequest.SendHttpRequestAsync<T>(Arg.Any<HttpRequestMessage>()).Returns(returnObject);
return mockAPiRequest;
}
}
Expand Down
22 changes: 10 additions & 12 deletions Deepgram.Tests/Fakes/MockIRequestMessageBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
using System.Net.Http;
using Deepgram.Interfaces;
using Deepgram.Models;
using Moq;
using Deepgram.Models;


namespace Deepgram.Tests.Fakes
{
public class MockIRequestMessageBuilder
{
public static Mock<IRequestMessageBuilder> Create()
public static IRequestMessageBuilder Create()
{
var mockRequestMessageBuilder = new Mock<IRequestMessageBuilder>();
mockRequestMessageBuilder.Setup(x => x.CreateHttpRequestMessage(
It.IsAny<HttpMethod>(),
It.IsAny<string>(),
It.IsAny<Credentials>(),
It.IsAny<object>(),
It.IsAny<object>())).Returns(new HttpRequestMessage());
var mockRequestMessageBuilder = Substitute.For<IRequestMessageBuilder>();
mockRequestMessageBuilder.CreateHttpRequestMessage(
Arg.Any<HttpMethod>(),
Arg.Any<string>(),
Arg.Any<Credentials>(),
Arg.Any<object>(),
Arg.Any<object>()).Returns(new HttpRequestMessage());
return mockRequestMessageBuilder;
}
}
Expand Down
15 changes: 15 additions & 0 deletions Deepgram.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Net;
global using System.Net.Http;
global using System.Text;
global using System.Threading;
global using System.Threading.Tasks;
global using Bogus;
global using Deepgram.Clients;
global using Deepgram.Interfaces;
global using Deepgram.Tests.Fakers;
global using Deepgram.Utilities;
global using NSubstitute;
global using Xunit;
2 changes: 1 addition & 1 deletion Deepgram.Tests/RequestTests/ApiRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async void Should_Return_A_Valid_Object_When_Deserialized()
{
//Arrange
var responseObject = new AutoFaker<Project>().Generate();
var client = FakeHttpMessageHandler.CreateHttpClientWithResult(responseObject);
var client = MockHttpClient.CreateHttpClientWithResult(responseObject);
var SUT = new ApiRequest(client);

//Act
Expand Down
Loading