-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathTestApiResponse.cs
More file actions
52 lines (38 loc) · 1.65 KB
/
TestApiResponse.cs
File metadata and controls
52 lines (38 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// <copyright file="TestApiResponse.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Datadog.Trace.Agent;
namespace Datadog.Trace.TestHelpers.TransportHelpers;
internal class TestApiResponse : IApiResponse
{
private readonly string _body;
private readonly Dictionary<string, string> _headers;
public TestApiResponse(int statusCode, string body, string contentType, Dictionary<string, string> headers = null)
{
StatusCode = statusCode;
_body = body;
ContentTypeHeader = contentType;
_headers = headers ?? new Dictionary<string, string>();
}
public string ContentTypeHeader { get; }
public string ContentEncodingHeader { get; set; }
public int StatusCode { get; }
public long ContentLength => _body?.Length ?? 0;
public Encoding GetCharsetEncoding() => Encoding.UTF8;
public ContentEncodingType GetContentEncodingType() => ApiResponseExtensions.GetContentEncodingType(ContentEncodingHeader);
public void Dispose()
{
}
public string GetHeader(string headerName) => _headers.TryGetValue(headerName, out var value) ? value : null;
public Task<Stream> GetStreamAsync()
{
return Task.FromResult((Stream)new MemoryStream(GetCharsetEncoding().GetBytes(_body)));
}
public Task<string> ReadAsStringAsync() => Task.FromResult(_body);
}