< Summary

Information
Class: Elsa.Http.ContentWriters.XmlContentFactory
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/ContentWriters/XmlContentFactory.cs
Line coverage
66%
Covered lines: 8
Uncovered lines: 4
Coverable lines: 12
Total lines: 33
Line coverage: 66.6%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
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(...)50%22100%
Serialize(...)100%210%

File(s)

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

#LineLine coverage
 1using System.Net.Mime;
 2using System.Text;
 3using System.Xml.Serialization;
 4
 5namespace Elsa.Http.ContentWriters;
 6
 7/// <summary>
 8/// Creates a <see cref="HttpContent"/> object for XML types.
 9/// </summary>
 10public class XmlContentFactory : IHttpContentFactory
 11{
 12    /// <inheritdoc />
 4113    public IEnumerable<string> SupportedContentTypes => new[]
 4114    {
 4115        MediaTypeNames.Application.Xml,
 4116        MediaTypeNames.Text.Xml,
 4117        MediaTypeNames.Application.Soap,
 4118    };
 19
 20    /// <inheritdoc />
 21    public HttpContent CreateHttpContent(object content, string contentType)
 22    {
 223        var text = content as string ?? Serialize(content);
 224        return new RawStringContent(text, Encoding.UTF8, contentType);
 25    }
 26
 27    private string Serialize(object value)
 28    {
 029        using var writer = new StringWriter();
 030        new XmlSerializer(value.GetType()).Serialize(writer, value);
 031        return writer.ToString();
 032    }
 33}