Skip to content

Commit

Permalink
Shore up integration Tests. Resolve minor issue w/ Discover and add m…
Browse files Browse the repository at this point in the history
…ore options. (#48)

* Resolves #38

* Update code formatting from PR #37 / Issue #36

* Url Encode the API requests. Should have done this forever ago.

Resolves #39

* Update Lucasfilm integration tests to use revised API values.

* Resolves #40
* Also fixed error for AssemblyInit class decorated with a [TestClass] attribute, but declared as an internal class. Apparently only public classes are supposed to be decorated with the TestClassAttribute. Who knew 🤷‍♀️

* Cleaning up ApiRequestBase

* use updated syntax for using statements
* refactor Func into a local method
* add error message when response uri is null

* Update integration tests to use file scoped namespaces / global usings.

* Battle of Lucasfile continues; guess it's back to Ltd.

* Update MovieApi project to use file scoped namespaces / global usings.

* Add assert structure for known types in AssertCanPageSearchResponse.

* Simplify condition for AssertCanPageSearchResponse.

* Simplify AssertCanPageSearchResponse w/ more straight forward page num.

* Consistent formatting.

* Add can page test for recommendations.

* Use the util for paging test with get similar (already does the same)

* Set the known page size as a constant.

* Increase the tolerance for duplicate results in a search query test.

* Clean up/simplify some of the tests validating type/interfaces.

* Remove discovery builder interface; improve discovery; add more methods.

Remove discovery builder interface; improve discovery; add more methods.
* No need for the IDiscoverMovieParameterBuilder - should be a concrete type as no other implementations should be allowed in the api.
* fix discovery parameter for original language (was wrong name)
* add a few more discovery builder options
* shore up the discovery tests w/ more data/tests.
  • Loading branch information
nCubed authored Aug 17, 2022
1 parent 28b174d commit bb14419
Show file tree
Hide file tree
Showing 89 changed files with 4,936 additions and 5,204 deletions.
189 changes: 90 additions & 99 deletions DM.MovieApi.IntegrationTests/ApiResponse/ApiResponseTests.cs
Original file line number Diff line number Diff line change
@@ -1,139 +1,130 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using DM.MovieApi.ApiResponse;
using DM.MovieApi.IntegrationTests.Infrastructure;
using DM.MovieApi.MovieDb.Configuration;
using DM.MovieApi.MovieDb.Movies;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DM.MovieApi.IntegrationTests.ApiResponse
namespace DM.MovieApi.IntegrationTests.ApiResponse;

[TestClass]
public class ApiResponseBaseTests
{
[TestClass]
public class ApiResponseBaseTests
private IntegrationApiRequest _api;

[TestInitialize]
public void TestInit()
{
private IntegrationApiRequest _api;
ApiResponseUtil.ThrottleTests();
_api = new IntegrationApiRequest( AssemblyInit.Settings );
}

[TestInitialize]
public void TestInit()
{
ApiResponseUtil.ThrottleTests();
_api = new IntegrationApiRequest( AssemblyInit.Settings );
}
[TestMethod]
public async Task ApiQueryResponse_Includes_CommandText()
{
const string command = "configuration";

[TestMethod]
public async Task ApiQueryResponse_Includes_CommandText()
{
const string command = "configuration";
ApiQueryResponse<ApiConfiguration> response = await _api.QueryAsync<ApiConfiguration>( command );

ApiQueryResponse<ApiConfiguration> response = await _api.QueryAsync<ApiConfiguration>( command );
ApiResponseUtil.AssertErrorIsNull( response );

ApiResponseUtil.AssertErrorIsNull( response );
string actualCommandText = $"Actual: {response.CommandText}";

string actualCommandText = $"Actual: {response.CommandText}";
Assert.IsTrue( response.CommandText.Contains( command ), actualCommandText );
Assert.IsTrue( response.CommandText.Contains( AssemblyInit.Settings.ApiUrl ), actualCommandText );
}

Assert.IsTrue( response.CommandText.Contains( command ), actualCommandText );
Assert.IsTrue( response.CommandText.Contains( AssemblyInit.Settings.ApiUrl ), actualCommandText );
}
[TestMethod]
public async Task ApiQueryResponse_Includes_CommandText_OnError()
{
const string command = "invalid/request";

[TestMethod]
public async Task ApiQueryResponse_Includes_CommandText_OnError()
{
const string command = "invalid/request";
ApiQueryResponse<ApiConfiguration> response = await _api.QueryAsync<ApiConfiguration>( command );

ApiQueryResponse<ApiConfiguration> response = await _api.QueryAsync<ApiConfiguration>( command );
Assert.IsNotNull( response.Error );

Assert.IsNotNull( response.Error );
string actualCommandText = $"Actual: {response.CommandText}";

string actualCommandText = $"Actual: {response.CommandText}";
Assert.IsTrue( response.CommandText.Contains( command ), actualCommandText );
Assert.IsTrue( response.CommandText.Contains( AssemblyInit.Settings.ApiUrl ), actualCommandText );
}

Assert.IsTrue( response.CommandText.Contains( command ), actualCommandText );
Assert.IsTrue( response.CommandText.Contains( AssemblyInit.Settings.ApiUrl ), actualCommandText );
}
[TestMethod]
public async Task ApiSearchAsyncResponse_Includes_CommandText()
{
const string command = "search/movie";

[TestMethod]
public async Task ApiSearchAsyncResponse_Includes_CommandText()
var param = new Dictionary<string, string>
{
const string command = "search/movie";
{"query", "Run Lola Run"},
};

var param = new Dictionary<string, string>
{
{"query", "Run Lola Run"},
};
ApiSearchResponse<MovieInfo> response = await _api.SearchAsync<MovieInfo>( command, param );

ApiSearchResponse<MovieInfo> response = await _api.SearchAsync<MovieInfo>( command, param );
ApiResponseUtil.AssertErrorIsNull( response );

ApiResponseUtil.AssertErrorIsNull( response );
AssertResponseIncludesCommandText( response, command );
}

AssertResponseIncludesCommandText( response, command );
}
[TestMethod]
public async Task ApiSearchAsyncResponse_Includes_CommandText_OnError()
{
const string command = "search/invalid";

[TestMethod]
public async Task ApiSearchAsyncResponse_Includes_CommandText_OnError()
var param = new Dictionary<string, string>
{
const string command = "search/invalid";
{"query", "Run Lola Run"},
};

var param = new Dictionary<string, string>
{
{"query", "Run Lola Run"},
};
ApiSearchResponse<MovieInfo> response = await _api.SearchAsync<MovieInfo>( command, param );

ApiSearchResponse<MovieInfo> response = await _api.SearchAsync<MovieInfo>( command, param );
Assert.IsNotNull( response.Error );

Assert.IsNotNull( response.Error );
AssertResponseIncludesCommandText( response, command );
}

AssertResponseIncludesCommandText( response, command );
}
[TestMethod]
public async Task ApiSearchAsyncResponse_Includes_Json()
{
const string command = "search/movie";

[TestMethod]
public async Task ApiSearchAsyncResponse_Includes_Json()
var param = new Dictionary<string, string>
{
const string command = "search/movie";

var param = new Dictionary<string, string>
{
{"query", "Run Lola Run"},
};
{"query", "Run Lola Run"},
};

ApiSearchResponse<MovieInfo> response = await _api.SearchAsync<MovieInfo>( command, param );
ApiSearchResponse<MovieInfo> response = await _api.SearchAsync<MovieInfo>( command, param );

ApiResponseUtil.AssertErrorIsNull( response );
ApiResponseUtil.AssertErrorIsNull( response );

AssertResponseIncludesJson( response );
}
AssertResponseIncludesJson( response );
}

[TestMethod]
public async Task ApiQueryAsyncResponse_Includes_Json()
{
// Run Lola Run MovieId=104
const string command = "movie/104";
[TestMethod]
public async Task ApiQueryAsyncResponse_Includes_Json()
{
// Run Lola Run MovieId=104
const string command = "movie/104";

ApiQueryResponse<Movie> response = await _api.QueryAsync<Movie>( command );
ApiQueryResponse<Movie> response = await _api.QueryAsync<Movie>( command );

AssertResponseIncludesJson( response );
}
AssertResponseIncludesJson( response );
}

// ReSharper disable once UnusedParameter.Local
private void AssertResponseIncludesCommandText( ApiResponseBase response, string command )
{
string actualCommandText = $"Actual: {response.CommandText}";
// ReSharper disable once UnusedParameter.Local
private void AssertResponseIncludesCommandText( ApiResponseBase response, string command )
{
string actualCommandText = $"Actual: {response.CommandText}";

Assert.IsTrue( response.CommandText.Contains( command ), actualCommandText );
Assert.IsTrue( response.CommandText.Contains( "&page=" ), actualCommandText );
Assert.IsTrue( response.CommandText.Contains( "?query=Run+Lola+Run" ), actualCommandText );
Assert.IsTrue( response.CommandText.Contains( AssemblyInit.Settings.ApiUrl ), actualCommandText );
}
Assert.IsTrue( response.CommandText.Contains( command ), actualCommandText );
Assert.IsTrue( response.CommandText.Contains( "&page=" ), actualCommandText );
Assert.IsTrue( response.CommandText.Contains( "?query=Run+Lola+Run" ), actualCommandText );
Assert.IsTrue( response.CommandText.Contains( AssemblyInit.Settings.ApiUrl ), actualCommandText );
}

private void AssertResponseIncludesJson( ApiResponseBase response )
{
string actualJson = $"Actual: {response.Json}";
private void AssertResponseIncludesJson( ApiResponseBase response )
{
string actualJson = $"Actual: {response.Json}";

ApiResponseUtil.AssertErrorIsNull( response );
ApiResponseUtil.AssertErrorIsNull( response );

Assert.IsTrue( response.Json.Contains( "\"release_date\":\"1998-03-03\"" ), actualJson );
Assert.IsTrue( response.Json.Contains( "\"original_title\":\"Lola rennt\"" ), actualJson );
Assert.IsTrue( response.Json.Contains( "\"title\":\"Run Lola Run\"" ), actualJson );
Assert.IsTrue( response.Json.Contains( "\"original_language\":\"de\"" ), actualJson );
Assert.IsTrue( response.Json.Contains( "\"id\":104" ), actualJson );
}
Assert.IsTrue( response.Json.Contains( "\"release_date\":\"1998-03-03\"" ), actualJson );
Assert.IsTrue( response.Json.Contains( "\"original_title\":\"Lola rennt\"" ), actualJson );
Assert.IsTrue( response.Json.Contains( "\"title\":\"Run Lola Run\"" ), actualJson );
Assert.IsTrue( response.Json.Contains( "\"original_language\":\"de\"" ), actualJson );
Assert.IsTrue( response.Json.Contains( "\"id\":104" ), actualJson );
}
}
Loading

0 comments on commit bb14419

Please sign in to comment.