예제 #1
0
        public async stt::Task CreateContextRequestObjectAsync()
        {
            moq::Mock <Contexts.ContextsClient> mockGrpcClient = new moq::Mock <Contexts.ContextsClient>(moq::MockBehavior.Strict);
            CreateContextRequest request = new CreateContextRequest
            {
                Parent  = "parent7858e4d0",
                Context = new Context(),
            };
            Context expectedResponse = new Context
            {
                ContextName   = ContextName.FromProjectSessionContext("[PROJECT]", "[SESSION]", "[CONTEXT]"),
                LifespanCount = -2034952532,
                Parameters    = new wkt::Struct(),
            };

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

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

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
예제 #2
0
 public Task <ContextDto> CreateContext2(CreateContextRequest request, MethodCallContext callContext)
 {
     return(Task.Factory.StartNew(() =>
     {
         var newContext = _contextsSet.CreateContext(request.Kind, callContext.ConsumerApplicationInstanceId);
         foreach (var appConnection in _appLifecycleManager.GetAppInstanceConnections(callContext.ConsumerApplicationInstanceId))
         {
             newContext.AppConnected(appConnection.Info);
         }
         return ConvertContextToProto(newContext, callContext.ConsumerApplicationInstanceId);
     }));
 }
예제 #3
0
 /// <summary>Snippet for CreateContext</summary>
 public void CreateContextRequestObject()
 {
     // Snippet: CreateContext(CreateContextRequest, CallSettings)
     // Create client
     ContextsClient contextsClient = ContextsClient.Create();
     // Initialize request argument(s)
     CreateContextRequest request = new CreateContextRequest
     {
         ParentAsSessionName = SessionName.FromProjectSession("[PROJECT]", "[SESSION]"),
         Context             = new Context(),
     };
     // Make the request
     Context response = contextsClient.CreateContext(request);
     // End snippet
 }
예제 #4
0
 /// <summary>Snippet for CreateContext</summary>
 public void CreateContextRequestObject()
 {
     // Snippet: CreateContext(CreateContextRequest, CallSettings)
     // Create client
     ContextsClient contextsClient = ContextsClient.Create();
     // Initialize request argument(s)
     CreateContextRequest request = new CreateContextRequest
     {
         Parent  = "",
         Context = new Context(),
     };
     // Make the request
     Context response = contextsClient.CreateContext(request);
     // End snippet
 }
예제 #5
0
        /// <summary>Snippet for CreateContextAsync</summary>
        public async Task CreateContextRequestObjectAsync()
        {
            // Snippet: CreateContextAsync(CreateContextRequest, CallSettings)
            // Additional: CreateContextAsync(CreateContextRequest, CancellationToken)
            // Create client
            ContextsClient contextsClient = await ContextsClient.CreateAsync();

            // Initialize request argument(s)
            CreateContextRequest request = new CreateContextRequest
            {
                ParentAsSessionName = SessionName.FromProjectSession("[PROJECT]", "[SESSION]"),
                Context             = new Context(),
            };
            // Make the request
            Context response = await contextsClient.CreateContextAsync(request);

            // End snippet
        }
예제 #6
0
        /// <summary>Snippet for CreateContextAsync</summary>
        public async Task CreateContextRequestObjectAsync()
        {
            // Snippet: CreateContextAsync(CreateContextRequest, CallSettings)
            // Additional: CreateContextAsync(CreateContextRequest, CancellationToken)
            // Create client
            ContextsClient contextsClient = await ContextsClient.CreateAsync();

            // Initialize request argument(s)
            CreateContextRequest request = new CreateContextRequest
            {
                Parent  = "",
                Context = new Context(),
            };
            // Make the request
            Context response = await contextsClient.CreateContextAsync(request);

            // End snippet
        }
예제 #7
0
        public void CreateContextRequestObject()
        {
            moq::Mock <Contexts.ContextsClient> mockGrpcClient = new moq::Mock <Contexts.ContextsClient>(moq::MockBehavior.Strict);
            CreateContextRequest request = new CreateContextRequest
            {
                Parent  = "parent7858e4d0",
                Context = new Context(),
            };
            Context expectedResponse = new Context
            {
                ContextName   = ContextName.FromProjectSessionContext("[PROJECT]", "[SESSION]", "[CONTEXT]"),
                LifespanCount = -2034952532,
                Parameters    = new wkt::Struct(),
            };

            mockGrpcClient.Setup(x => x.CreateContext(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            ContextsClient client   = new ContextsClientImpl(mockGrpcClient.Object, null);
            Context        response = client.CreateContext(request);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
예제 #8
0
        public async Task CreateContextAsync2()
        {
            Mock <Contexts.ContextsClient> mockGrpcClient = new Mock <Contexts.ContextsClient>(MockBehavior.Strict);
            CreateContextRequest           request        = new CreateContextRequest
            {
                ParentAsSessionName = new SessionName("[PROJECT]", "[SESSION]"),
                Context             = new Context(),
            };
            Context expectedResponse = new Context
            {
                ContextName   = new ContextName("[PROJECT]", "[SESSION]", "[CONTEXT]"),
                LifespanCount = 1178775510,
            };

            mockGrpcClient.Setup(x => x.CreateContextAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Context>(Task.FromResult(expectedResponse), null, null, null, null));
            ContextsClient client   = new ContextsClientImpl(mockGrpcClient.Object, null);
            Context        response = await client.CreateContextAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
예제 #9
0
        public void CreateContext2()
        {
            Mock <Contexts.ContextsClient> mockGrpcClient = new Mock <Contexts.ContextsClient>(MockBehavior.Strict);
            CreateContextRequest           request        = new CreateContextRequest
            {
                ParentAsSessionName = new SessionName("[PROJECT]", "[SESSION]"),
                Context             = new Context(),
            };
            Context expectedResponse = new Context
            {
                ContextName   = new ContextName("[PROJECT]", "[SESSION]", "[CONTEXT]"),
                LifespanCount = 1178775510,
            };

            mockGrpcClient.Setup(x => x.CreateContext(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            ContextsClient client   = new ContextsClientImpl(mockGrpcClient.Object, null);
            Context        response = client.CreateContext(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        // [START dialogflow_create_context]
        public static int Create(string projectId,
                                 string sessionId,
                                 string contextId,
                                 int lifespanCount = 1)
        {
            var client = ContextsClient.Create();

            var context = new Context();

            context.ContextName   = new ContextName(projectId, sessionId, contextId);
            context.LifespanCount = lifespanCount;

            var createContextRequest = new CreateContextRequest
            {
                Parent  = SessionName.FromProjectSession(projectId, sessionId).ToString(),
                Context = context
            };

            var newContext = client.CreateContext(createContextRequest);

            Console.WriteLine($"Created Context: {newContext.Name}");

            return(0);
        }