예제 #1
0
        public async stt::Task LookupRequestObjectAsync()
        {
            moq::Mock <Datastore.DatastoreClient> mockGrpcClient = new moq::Mock <Datastore.DatastoreClient>(moq::MockBehavior.Strict);
            LookupRequest request = new LookupRequest
            {
                ReadOptions = new ReadOptions(),
                Keys        = { new Key(), },
                ProjectId   = "project_id43ad98b0",
            };
            LookupResponse expectedResponse = new LookupResponse
            {
                Found    = { new EntityResult(), },
                Missing  = { new EntityResult(), },
                Deferred = { new Key(), },
            };

            mockGrpcClient.Setup(x => x.LookupAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <LookupResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            DatastoreClient client = new DatastoreClientImpl(mockGrpcClient.Object, null);
            LookupResponse  responseCallSettings = await client.LookupAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            LookupResponse responseCancellationToken = await client.LookupAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        public async Task LookupAsync2()
        {
            Mock <Datastore.DatastoreClient> mockGrpcClient = new Mock <Datastore.DatastoreClient>(MockBehavior.Strict);
            LookupRequest request = new LookupRequest
            {
                ProjectId = "projectId-1969970175",
                Keys      = { },
            };
            LookupResponse expectedResponse = new LookupResponse();

            mockGrpcClient.Setup(x => x.LookupAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <LookupResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            DatastoreClient client   = new DatastoreClientImpl(mockGrpcClient.Object, null);
            LookupResponse  response = await client.LookupAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }