Implement the download Function for C# (#2076)

Port the `download` function to the C# service.
This commit is contained in:
George Pollard
2022-06-23 15:48:24 +12:00
committed by GitHub
parent 4eec0bfc45
commit fb9af4b811
5 changed files with 168 additions and 10 deletions

View File

@ -12,21 +12,21 @@ using Moq;
namespace Tests.Fakes;
sealed class TestHttpRequestData : HttpRequestData {
private static readonly ObjectSerializer Serializer =
private static readonly ObjectSerializer _serializer =
// we must use our shared JsonSerializerOptions to be able to serialize & deserialize polymorphic types
new JsonObjectSerializer(Microsoft.OneFuzz.Service.OneFuzzLib.Orm.EntityConverter.GetJsonSerializerOptions());
sealed class TestServices : IServiceProvider {
sealed class TestOptions : IOptions<WorkerOptions> {
// WorkerOptions only has one setting: Serializer
public WorkerOptions Value => new() { Serializer = Serializer };
public WorkerOptions Value => new() { Serializer = _serializer };
}
static readonly IOptions<WorkerOptions> Options = new TestOptions();
static readonly IOptions<WorkerOptions> _options = new TestOptions();
public object? GetService(Type serviceType) {
if (serviceType == typeof(IOptions<WorkerOptions>)) {
return Options;
return _options;
}
return null;
@ -42,7 +42,7 @@ sealed class TestHttpRequestData : HttpRequestData {
}
public static TestHttpRequestData FromJson<T>(string method, T obj)
=> new(method, Serializer.Serialize(obj));
=> new(method, _serializer.Serialize(obj));
public static TestHttpRequestData Empty(string method)
=> new(method, new BinaryData(Array.Empty<byte>()));
@ -53,6 +53,7 @@ sealed class TestHttpRequestData : HttpRequestData {
_body = body;
}
private Uri _url = new("https://example.com/");
private readonly BinaryData _body;
public override Stream Body => _body.ToStream();
@ -61,12 +62,15 @@ sealed class TestHttpRequestData : HttpRequestData {
public override IReadOnlyCollection<IHttpCookie> Cookies => throw new NotImplementedException();
public override Uri Url => throw new NotImplementedException();
public override IEnumerable<ClaimsIdentity> Identities => throw new NotImplementedException();
public override string Method { get; }
public override Uri Url => _url;
public void SetUrl(Uri url) => _url = url;
public override HttpResponseData CreateResponse()
=> new TestHttpResponseData(FunctionContext);
}