Skip to content

Commit

Permalink
Check public methods for null values
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinobee committed Nov 8, 2019
1 parent ceddb97 commit 13286df
Showing 1 changed file with 69 additions and 3 deletions.
72 changes: 69 additions & 3 deletions src/VatLayerExternalSearchProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ private VatLayerExternalSearchProvider(bool tokenProviderIsRequired)
/// <returns>The search queries.</returns>
public override IEnumerable<IExternalSearchQuery> BuildQueries(ExecutionContext context, IExternalSearchRequest request)
{
if (string.IsNullOrEmpty(this.TokenProvider?.ApiToken))
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
throw new InvalidOperationException("ApiToken for VatLayer must be provided.");

if (!this.Accepts(request.EntityMetaData.EntityType))
Expand Down Expand Up @@ -92,6 +100,15 @@ public override IEnumerable<IExternalSearchQuery> BuildQueries(ExecutionContext
/// <returns>The results.</returns>
public override IEnumerable<IExternalSearchQueryResult> ExecuteSearch(ExecutionContext context, IExternalSearchQuery query)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
var vat = query.QueryParameters[ExternalSearchQueryParameter.Identifier].FirstOrDefault();

if (string.IsNullOrEmpty(vat))
Expand Down Expand Up @@ -129,7 +146,30 @@ public override IEnumerable<IExternalSearchQueryResult> ExecuteSearch(ExecutionC
/// <param name="result">The result.</param>
/// <param name="request">The request.</param>
/// <returns>The clues.</returns>
public override IEnumerable<Clue> BuildClues(ExecutionContext context, IExternalSearchQuery query, IExternalSearchQueryResult result, IExternalSearchRequest request)
public override IEnumerable<Clue> BuildClues(ExecutionContext context,
IExternalSearchQuery query,
IExternalSearchQueryResult result,
IExternalSearchRequest request)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

if (query == null)
{
throw new ArgumentNullException(nameof(query));
}

if (result == null)
{
throw new ArgumentNullException(nameof(result));
}

if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
{
var resultItem = result.As<VatLayerResponse>();
var code = this.GetOriginEntityCode(resultItem);
Expand All @@ -145,7 +185,24 @@ public override IEnumerable<Clue> BuildClues(ExecutionContext context, IExternal
/// <param name="result">The result.</param>
/// <param name="request">The request.</param>
/// <returns>The primary entity metadata.</returns>
public override IEntityMetadata GetPrimaryEntityMetadata(ExecutionContext context, IExternalSearchQueryResult result, IExternalSearchRequest request)
public override IEntityMetadata GetPrimaryEntityMetadata(ExecutionContext context,
IExternalSearchQueryResult result,
IExternalSearchRequest request)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

if (result == null)
{
throw new ArgumentNullException(nameof(result));
}

if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
{
var resultItem = result.As<VatLayerResponse>();
return this.CreateMetadata(resultItem);
Expand All @@ -158,6 +215,15 @@ public override IEntityMetadata GetPrimaryEntityMetadata(ExecutionContext contex
/// <returns>The preview image.</returns>
public override IPreviewImage GetPrimaryEntityPreviewImage(ExecutionContext context, IExternalSearchQueryResult result, IExternalSearchRequest request)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

if (result == null)
{
throw new ArgumentNullException(nameof(result));
}
return null;
}

Expand Down

0 comments on commit 13286df

Please sign in to comment.