Example #1
0
        public async stt::Task AllocateIdsAsync()
        {
            moq::Mock <Datastore.DatastoreClient> mockGrpcClient = new moq::Mock <Datastore.DatastoreClient>(moq::MockBehavior.Strict);
            AllocateIdsRequest request = new AllocateIdsRequest
            {
                Keys      = { new Key(), },
                ProjectId = "project_id43ad98b0",
            };
            AllocateIdsResponse expectedResponse = new AllocateIdsResponse {
                Keys = { new Key(), },
            };

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

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            AllocateIdsResponse responseCancellationToken = await client.AllocateIdsAsync(request.ProjectId, request.Keys, st::CancellationToken.None);

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

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

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