// ------------------------------------------------------------ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. // ------------------------------------------------------------ namespace Dapr.Client { using System.Text.Json; using System.Threading.Tasks; using Grpc.Core; using Moq; public class MockClient { public MockClient() { Mock = new Mock(MockBehavior.Strict); DaprClient = new DaprClientGrpc(Mock.Object, new JsonSerializerOptions()); } public Mock Mock { get; } public DaprClient DaprClient { get; } public InvokeApiCallBuilder Call() { return new InvokeApiCallBuilder(); } public class InvokeApiCallBuilder { private TResponse response; private Metadata headers; private Status status; private Metadata trailers; public InvokeApiCallBuilder() { headers = new Metadata(); trailers = new Metadata(); } public AsyncUnaryCall Build() { return new AsyncUnaryCall( Task.FromResult(response), Task.FromResult(headers), () => status, () => trailers, () => { }); } public InvokeApiCallBuilder SetResponse(TResponse response) { this.response = response; return this; } public InvokeApiCallBuilder SetStatus(Status status) { this.status = status; return this; } public InvokeApiCallBuilder AddHeader(string key, string value) { this.headers.Add(key, value); return this; } public InvokeApiCallBuilder AddTrailer(string key, string value) { this.trailers.Add(key, value); return this; } } } }