Exemple #1
0
        public async Task BeginTransactionAsync2()
        {
            Mock <Spanner.SpannerClient> mockGrpcClient = new Mock <Spanner.SpannerClient>(MockBehavior.Strict);
            BeginTransactionRequest      request        = new BeginTransactionRequest
            {
                SessionAsSessionName = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"),
                Options = new TransactionOptions(),
            };
            Transaction expectedResponse = new Transaction
            {
                Id = ByteString.CopyFromUtf8("27"),
            };

            mockGrpcClient.Setup(x => x.BeginTransactionAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Transaction>(Task.FromResult(expectedResponse), null, null, null, null));
            SpannerClient client   = new SpannerClientImpl(mockGrpcClient.Object, null);
            Transaction   response = await client.BeginTransactionAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemple #2
0
        public void CreateSession()
        {
            Mock <Spanner.SpannerClient> mockGrpcClient  = new Mock <Spanner.SpannerClient>(MockBehavior.Strict);
            CreateSessionRequest         expectedRequest = new CreateSessionRequest
            {
                DatabaseAsDatabaseName = new DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"),
            };
            Session expectedResponse = new Session
            {
                SessionName = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"),
            };

            mockGrpcClient.Setup(x => x.CreateSession(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            SpannerClient client   = new SpannerClientImpl(mockGrpcClient.Object, null);
            DatabaseName  database = new DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]");
            Session       response = client.CreateSession(database);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemple #3
0
        public async Task GetSessionAsync()
        {
            Mock <Spanner.SpannerClient> mockGrpcClient  = new Mock <Spanner.SpannerClient>(MockBehavior.Strict);
            GetSessionRequest            expectedRequest = new GetSessionRequest
            {
                SessionName = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"),
            };
            Session expectedResponse = new Session
            {
                SessionName = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"),
            };

            mockGrpcClient.Setup(x => x.GetSessionAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Session>(Task.FromResult(expectedResponse), null, null, null, null));
            SpannerClient client   = new SpannerClientImpl(mockGrpcClient.Object, null);
            SessionName   name     = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
            Session       response = await client.GetSessionAsync(name);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemple #4
0
        public async Task CommitAsync2()
        {
            Mock <Spanner.SpannerClient> mockGrpcClient = new Mock <Spanner.SpannerClient>(MockBehavior.Strict);
            CommitRequest expectedRequest = new CommitRequest
            {
                SessionAsSessionName = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"),
                SingleUseTransaction = new TransactionOptions(),
                Mutations            = { },
            };
            CommitResponse expectedResponse = new CommitResponse();

            mockGrpcClient.Setup(x => x.CommitAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <CommitResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            SpannerClient          client  = new SpannerClientImpl(mockGrpcClient.Object, null);
            SessionName            session = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
            TransactionOptions     singleUseTransaction = new TransactionOptions();
            IEnumerable <Mutation> mutations            = new List <Mutation>();
            CommitResponse         response             = await client.CommitAsync(session, singleUseTransaction, mutations);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemple #5
0
        public void Commit()
        {
            Mock <Spanner.SpannerClient> mockGrpcClient = new Mock <Spanner.SpannerClient>(MockBehavior.Strict);
            CommitRequest expectedRequest = new CommitRequest
            {
                SessionAsSessionName = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"),
                TransactionId        = ByteString.CopyFromUtf8("28"),
                Mutations            = { },
            };
            CommitResponse expectedResponse = new CommitResponse();

            mockGrpcClient.Setup(x => x.Commit(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            SpannerClient          client        = new SpannerClientImpl(mockGrpcClient.Object, null);
            SessionName            session       = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
            ByteString             transactionId = ByteString.CopyFromUtf8("28");
            IEnumerable <Mutation> mutations     = new List <Mutation>();
            CommitResponse         response      = client.Commit(session, transactionId, mutations);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemple #6
0
        public void BeginTransaction()
        {
            Mock <Spanner.SpannerClient> mockGrpcClient  = new Mock <Spanner.SpannerClient>(MockBehavior.Strict);
            BeginTransactionRequest      expectedRequest = new BeginTransactionRequest
            {
                SessionAsSessionName = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"),
                Options = new TransactionOptions(),
            };
            Transaction expectedResponse = new Transaction
            {
                Id = ByteString.CopyFromUtf8("27"),
            };

            mockGrpcClient.Setup(x => x.BeginTransaction(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            SpannerClient      client   = new SpannerClientImpl(mockGrpcClient.Object, null);
            SessionName        session  = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
            TransactionOptions options  = new TransactionOptions();
            Transaction        response = client.BeginTransaction(session, options);

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