[#16] Client: Unit tests
Signed-off-by: Pavel Gross <p.gross@yando.com>
This commit is contained in:
parent
2a28806ace
commit
22e2a53551
6 changed files with 544 additions and 25 deletions
|
@ -1,8 +1,7 @@
|
|||
using Moq;
|
||||
using FrostFS.Session;
|
||||
using Grpc.Core;
|
||||
using FrostFS.SDK.ClientV2;
|
||||
using Google.Protobuf;
|
||||
using Grpc.Core;
|
||||
using Moq;
|
||||
|
||||
namespace FrostFS.SDK.Tests;
|
||||
|
||||
|
@ -11,24 +10,33 @@ public class SessionMocker(string key) : ServiceBase(key)
|
|||
public byte[]? SessionId { get; set; }
|
||||
|
||||
public byte[]? SessionKey { get; set; }
|
||||
|
||||
|
||||
public CreateRequest CreateSessionRequest { get; private 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);
|
||||
if (SessionId == null)
|
||||
{
|
||||
SessionId = new byte[32];
|
||||
rand.NextBytes(SessionId);
|
||||
}
|
||||
|
||||
if (SessionKey == null)
|
||||
{
|
||||
SessionKey = new byte[32];
|
||||
rand.NextBytes(SessionKey);
|
||||
}
|
||||
|
||||
CreateResponse response = new()
|
||||
{
|
||||
Body = new CreateResponse.Types.Body
|
||||
{
|
||||
Id = ByteString.CopyFrom(SessionId),
|
||||
SessionKey = ByteString.CopyFrom(SessionId)
|
||||
SessionKey = ByteString.CopyFrom(SessionKey)
|
||||
},
|
||||
MetaHeader = ResponseMetaHeader
|
||||
};
|
||||
|
@ -40,17 +48,20 @@ public class SessionMocker(string key) : ServiceBase(key)
|
|||
It.IsAny<Metadata>(),
|
||||
It.IsAny<DateTime?>(),
|
||||
It.IsAny<CancellationToken>()))
|
||||
.Returns((CreateRequest r, Metadata m, DateTime? dt, CancellationToken ct) =>
|
||||
{
|
||||
Verifier.CheckRequest(r);
|
||||
.Returns((CreateRequest r, Metadata m, DateTime? dt, CancellationToken ct) =>
|
||||
{
|
||||
CreateSessionRequest = r;
|
||||
Metadata = m;
|
||||
DateTime = dt;
|
||||
CancellationToken = ct;
|
||||
|
||||
return new AsyncUnaryCall<CreateResponse>(
|
||||
Task.FromResult(response),
|
||||
Task.FromResult(ResponseMetaData),
|
||||
() => new Grpc.Core.Status(StatusCode.OK, string.Empty),
|
||||
() => ResponseMetaData,
|
||||
() => { });
|
||||
});
|
||||
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