Example #1
0
        public async stt::Task Commit2Async()
        {
            moq::Mock <Datastore.DatastoreClient> mockGrpcClient = new moq::Mock <Datastore.DatastoreClient>(moq::MockBehavior.Strict);
            CommitRequest request = new CommitRequest
            {
                Mode      = CommitRequest.Types.Mode.Unspecified,
                Mutations = { new Mutation(), },
                ProjectId = "project_id43ad98b0",
            };
            CommitResponse expectedResponse = new CommitResponse
            {
                MutationResults =
                {
                    new MutationResult(),
                },
                IndexUpdates = 1466771529,
            };

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

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            CommitResponse responseCancellationToken = await client.CommitAsync(request.ProjectId, request.Mode, request.Mutations, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        public async Task CommitAsync2()
        {
            Mock <Datastore.DatastoreClient> mockGrpcClient = new Mock <Datastore.DatastoreClient>(MockBehavior.Strict);
            CommitRequest expectedRequest = new CommitRequest
            {
                ProjectId = "projectId-1969970175",
                Mode      = CommitRequest.Types.Mode.Unspecified,
                Mutations = { },
            };
            CommitResponse expectedResponse = new CommitResponse
            {
                IndexUpdates = 1425228195,
            };

            mockGrpcClient.Setup(x => x.CommitAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <CommitResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            DatastoreClient client    = new DatastoreClientImpl(mockGrpcClient.Object, null);
            string          projectId = "projectId-1969970175";

            CommitRequest.Types.Mode mode      = CommitRequest.Types.Mode.Unspecified;
            IEnumerable <Mutation>   mutations = new List <Mutation>();
            CommitResponse           response  = await client.CommitAsync(projectId, mode, mutations);

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