Skip to content

Commit

Permalink
Update code from pr review.
Browse files Browse the repository at this point in the history
  • Loading branch information
marabooy committed Sep 10, 2024
1 parent 841a978 commit fd4870d
Showing 1 changed file with 7 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
// </copyright>
//---------------------------------------------------------------------

using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System;
using Xunit;
using Microsoft.Extensions.DependencyInjection;
using System.Linq;
using Microsoft.OData.Tests;

namespace Microsoft.OData.Core.Tests
{
Expand Down Expand Up @@ -52,7 +52,12 @@ private static async Task<string> WritePayloadAsync(string content, IServiceProv
{
using Stream outputStream = new MemoryStream();

var message = new ODataMessage(outputStream, serviceProvider);
var message = new InMemoryMessage
{
Stream = outputStream,
ServiceProvider = serviceProvider
};

var responseMessage = new ODataResponseMessage(message, writing: true, enableMessageStreamDisposal: true, maxMessageSize: -1);
await using ODataMessageWriter writer = new ODataMessageWriter(responseMessage);

Expand All @@ -69,47 +74,5 @@ private static async Task<string> WritePayloadAsync(string content, IServiceProv
await writer.DisposeAsync();
return written;
}


class ODataMessage : IODataResponseMessage, IODataResponseMessageAsync, IServiceCollectionProvider
{
private Dictionary<string, string> _headers = new();
private Stream _outputStream;
public ODataMessage(Stream outputStream, IServiceProvider serviceProvider)
{
this.ServiceProvider = serviceProvider;
_outputStream = outputStream;
}
public IEnumerable<KeyValuePair<string, string>> Headers => _headers;

public int StatusCode { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

public IServiceProvider ServiceProvider { get; private set; }

public string GetHeader(string headerName)
{
if (_headers.TryGetValue(headerName, out var value))
{
return value;
}

return null;
}

public Stream GetStream()
{
return _outputStream;
}

public Task<Stream> GetStreamAsync()
{
return Task.FromResult(_outputStream);
}

public void SetHeader(string headerName, string headerValue)
{
_headers[headerName] = headerValue;
}
}
}
}

0 comments on commit fd4870d

Please sign in to comment.