public async stt::Task GetGroupRequestObjectAsync() { moq::Mock <ErrorGroupService.ErrorGroupServiceClient> mockGrpcClient = new moq::Mock <ErrorGroupService.ErrorGroupServiceClient>(moq::MockBehavior.Strict); GetGroupRequest request = new GetGroupRequest { GroupNameAsErrorGroupName = new ErrorGroupName("[PROJECT]", "[GROUP]"), }; ErrorGroup expectedResponse = new ErrorGroup { ErrorGroupName = new ErrorGroupName("[PROJECT]", "[GROUP]"), GroupId = "group_id4f9a930e", TrackingIssues = { new TrackingIssue(), }, }; mockGrpcClient.Setup(x => x.GetGroupAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <ErrorGroup>(stt::Task.FromResult(expectedResponse), null, null, null, null)); ErrorGroupServiceClient client = new ErrorGroupServiceClientImpl(mockGrpcClient.Object, null); ErrorGroup responseCallSettings = await client.GetGroupAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); ErrorGroup responseCancellationToken = await client.GetGroupAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task GetGroupAsync2() { Mock <ErrorGroupService.ErrorGroupServiceClient> mockGrpcClient = new Mock <ErrorGroupService.ErrorGroupServiceClient>(MockBehavior.Strict); GetGroupRequest request = new GetGroupRequest { GroupNameAsGroupName = new GroupName("[PROJECT]", "[GROUP]"), }; ErrorGroup expectedResponse = new ErrorGroup { GroupName = new GroupName("[PROJECT]", "[GROUP]"), GroupId = "groupId506361563", }; mockGrpcClient.Setup(x => x.GetGroupAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <ErrorGroup>(Task.FromResult(expectedResponse), null, null, null, null)); ErrorGroupServiceClient client = new ErrorGroupServiceClientImpl(mockGrpcClient.Object, null); ErrorGroup response = await client.GetGroupAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }