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

Fix some SonarCloud issues #955

Merged
merged 2 commits into from
Jun 13, 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
4 changes: 2 additions & 2 deletions src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,14 @@ private string MapBasePath(IList<OpenApiServer>? servers)
var mappedHeaders = headers?.ToDictionary(
item => item.Key,
_ => GetExampleMatcherModel(null, _settings.HeaderPatternToUse).Pattern!
);
) ?? new Dictionary<string, object>();

if (!string.IsNullOrEmpty(responseContentType))
{
mappedHeaders.TryAdd(HeaderContentType, responseContentType!);
}

return mappedHeaders?.Keys.Any() == true ? mappedHeaders : null;
return mappedHeaders.Keys.Any() ? mappedHeaders : null;
}

private IList<ParamModel>? MapQueryParameters(IEnumerable<OpenApiParameter> queryParameters)
Expand Down
4 changes: 2 additions & 2 deletions src/WireMock.Net.OpenApiParser/WireMockOpenApiParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public IReadOnlyList<MappingModel> FromFile(string path, WireMockOpenApiParserSe

/// <inheritdoc />
[PublicAPI]
public IReadOnlyList<MappingModel> FromDocument(OpenApiDocument openApiDocument, WireMockOpenApiParserSettings? settings = null)
public IReadOnlyList<MappingModel> FromDocument(OpenApiDocument document, WireMockOpenApiParserSettings? settings = null)
{
return new OpenApiPathsMapper(settings ?? new WireMockOpenApiParserSettings()).ToMappingModels(openApiDocument.Paths, openApiDocument.Servers);
return new OpenApiPathsMapper(settings ?? new WireMockOpenApiParserSettings()).ToMappingModels(document.Paths, document.Servers);
}

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/Util/CSharpFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static string ToCSharpStringLiteral(string? value)
return "\"\"";
}

if (value.Contains("\n"))
if (value.Contains('\n'))
{
var escapedValue = value?.Replace("\"", "\"\"") ?? string.Empty;
return $"@\"{escapedValue}\"";
Expand Down
18 changes: 16 additions & 2 deletions test/WireMock.Net.Tests/Pact/PactTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ public void SavePact_Get_Request_And_Response_WithBodyAsJson()
})
);

server.SavePact(Path.Combine("../../../", "Pact", "files"), "pact-get.json");
var folder = Path.Combine("../../../", "Pact", "files");
var file = "pact-get.json";

// Act
server.SavePact(folder, file);

// Assert
File.ReadAllBytes(Path.Combine(folder, file)).Length.Should().BeGreaterThan(1);
}

[Fact]
Expand Down Expand Up @@ -201,6 +208,13 @@ public void SavePact_Multiple_Requests()
})
);

server.SavePact(Path.Combine("../../../", "Pact", "files"), "pact-multiple.json");
var folder = Path.Combine("../../../", "Pact", "files");
var file = "pact-multiple.json";

// Act
server.SavePact(folder, file);

// Assert
File.ReadAllBytes(Path.Combine(folder, file)).Length.Should().BeGreaterThan(1);
}
}
Loading