parent
605463ec24
commit
ae67b12313
28 changed files with 943 additions and 554 deletions
57
src/FrostFS.SDK.Tests/Mocks/SessionMock.cs
Normal file
57
src/FrostFS.SDK.Tests/Mocks/SessionMock.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using Moq;
|
||||
using FrostFS.Session;
|
||||
using Grpc.Core;
|
||||
using FrostFS.SDK.ClientV2;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace FrostFS.SDK.Tests;
|
||||
|
||||
public class SessionMockFactory(string key) : ServiceBase(key)
|
||||
{
|
||||
public byte[]? SessionId { get; set; }
|
||||
|
||||
public byte[]? SessionKey { get; set; }
|
||||
|
||||
public Mock<SessionService.SessionServiceClient> GetMock()
|
||||
{
|
||||
var mock = new Mock<SessionService.SessionServiceClient>();
|
||||
|
||||
Random rand = new();
|
||||
SessionId = new byte[32];
|
||||
SessionKey = new byte[32];
|
||||
|
||||
rand.NextBytes(SessionId);
|
||||
rand.NextBytes(SessionKey);
|
||||
|
||||
CreateResponse response = new()
|
||||
{
|
||||
Body = new CreateResponse.Types.Body
|
||||
{
|
||||
Id = ByteString.CopyFrom(SessionId),
|
||||
SessionKey = ByteString.CopyFrom(SessionId)
|
||||
},
|
||||
MetaHeader = ResponseMetaHeader
|
||||
};
|
||||
|
||||
response.VerifyHeader = GetResponseVerificationHeader(response);
|
||||
|
||||
mock.Setup(x => x.CreateAsync(
|
||||
It.IsAny<CreateRequest>(),
|
||||
It.IsAny<Metadata>(),
|
||||
It.IsAny<DateTime?>(),
|
||||
It.IsAny<CancellationToken>()))
|
||||
.Returns((CreateRequest r, Metadata m, DateTime? dt, CancellationToken ct) =>
|
||||
{
|
||||
Verifier.CheckRequest(r);
|
||||
|
||||
return new AsyncUnaryCall<CreateResponse>(
|
||||
Task.FromResult(response),
|
||||
Task.FromResult(ResponseMetaData),
|
||||
() => new Grpc.Core.Status(StatusCode.OK, string.Empty),
|
||||
() => ResponseMetaData,
|
||||
() => { });
|
||||
});
|
||||
|
||||
return mock;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue