< Summary

Information
Class: Elsa.Http.ContentWriters.FormUrlEncodedHttpContentFactory
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/ContentWriters/FormUrlEncodedHttpContentFactory.cs
Line coverage
12%
Covered lines: 1
Uncovered lines: 7
Coverable lines: 8
Total lines: 28
Line coverage: 12.5%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_SupportedContentTypes()100%11100%
CreateHttpContent(...)100%210%
GetContentAsDictionary(...)0%110100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/ContentWriters/FormUrlEncodedHttpContentFactory.cs

#LineLine coverage
 1using System.Text.Json;
 2using System.Text.Json.Nodes;
 3
 4namespace Elsa.Http.ContentWriters;
 5
 6/// <summary>
 7/// A content writer that writes content in the application/x-www-form-urlencoded format.
 8/// </summary>
 9public class FormUrlEncodedHttpContentFactory : IHttpContentFactory
 10{
 11    /// <inheritdoc />
 4012    public IEnumerable<string> SupportedContentTypes => ["application/x-www-form-urlencoded"];
 13
 14    /// <inheritdoc />
 015    public HttpContent CreateHttpContent(object content, string? contentType = null) => new FormUrlEncodedContent(GetCon
 16
 17    private static IDictionary<string, string> GetContentAsDictionary(object content)
 18    {
 019        if (content is IDictionary<string, object> dictionary)
 020            return dictionary.ToDictionary(x => x.Key, x => x.Value.ToString() ?? string.Empty);
 21
 022        if (content is string or JsonObject)
 023            return JsonSerializer.Deserialize<Dictionary<string, string>>(JsonSerializer.Serialize(content))!;
 24
 025        var jsonElement = JsonSerializer.SerializeToElement(content);
 026        return jsonElement.EnumerateObject().ToDictionary(x => x.Name, x => x.Value.ToString());
 27    }
 28}