小编Cra*_*tin的帖子

用于单元测试的模拟 gRPC 响应流 - C#

我有一个函数调用 gRPC 端点,将对象转换为 POCO 对象并将它们作为列表返回。

public class ActionPlanConnectionsService : IConnectionService
    {
            #region Fields
    
            /// <summary>
            /// Grpc client
            /// </summary>
            private readonly ConnectionDb.ConnectionDbClient _client;
            #endregion
    
            public ActionPlanConnectionsService(ConnectionDb.ConnectionDbClient channel)
            {
                _client = channel;
            }
    
            public async Task<IEnumerable<Connection>> Get(int actionPlanId, int implementation)
            {
               List<Connection> diagramConnections = new List<Connection>();
               GetConnectionsByIdAndImplementationMessage message = new GetConnectionsByIdAndImplementationMessage
               {
                   ActionPlanId = actionPlanId,
                   Implementation = implementation
               };
    
               using var call = _client.GetAllConnections(message);
               await foreach (ConnectionServiceModel connection in call.ResponseStream.ReadAllAsync())
               {
                   // Never enters here as ResponseStream has no elements …
Run Code Online (Sandbox Code Playgroud)

c# nunit unit-testing grpc

2
推荐指数
1
解决办法
5262
查看次数

标签 统计

c# ×1

grpc ×1

nunit ×1

unit-testing ×1