frostfs-sdk-csharp/src/FrostFS.SDK.Tests/Mocks/AsyncStreamReaderMock.cs
Pavel Gross c9a75ea025 [#24] Client: Implement pool part1
first iteration - base classes and methods

Signed-off-by: Pavel Gross <p.gross@yadro.com>
2024-10-21 10:48:00 +03:00

64 lines
1.9 KiB
C#

using System.Security.Cryptography;
using FrostFS.Object;
using FrostFS.SDK.ClientV2;
using FrostFS.SDK.ClientV2.Mappers.GRPC;
using FrostFS.SDK.Cryptography;
using FrostFS.Session;
using Google.Protobuf;
using Grpc.Core;
namespace FrostFS.SDK.Tests;
public class AsyncStreamReaderMock(string key, FrostFsObjectHeader objectHeader) : ServiceBase(key), IAsyncStreamReader<GetResponse>
{
public GetResponse Current
{
get
{
var header = new Header
{
ContainerId = objectHeader.ContainerId.ToMessage(),
PayloadLength = objectHeader.PayloadLength,
Version = objectHeader.Version!.ToMessage(),
OwnerId = objectHeader.OwnerId!.ToMessage()
};
if (objectHeader.Attributes != null)
{
foreach (var attr in objectHeader.Attributes)
header.Attributes.Add(attr.ToMessage());
}
var response = new GetResponse
{
Body = new GetResponse.Types.Body
{
Init = new GetResponse.Types.Body.Types.Init
{
Header = header,
ObjectId = new Refs.ObjectID { Value = ByteString.CopyFrom(SHA256.HashData(Array.Empty<byte>())) },
Signature = new Refs.Signature
{
Key = ByteString.CopyFrom(Key.PublicKey()),
Sign = ByteString.CopyFrom(Key.SignData(header.ToByteArray())),
}
}
},
MetaHeader = new ResponseMetaHeader()
};
response.VerifyHeader = GetResponseVerificationHeader(response);
return response;
}
}
public Task<bool> MoveNext(CancellationToken cancellationToken)
{
return Task.FromResult(true);
}
}