public async stt::Task CreateSchemaRequestObjectAsync()
        {
            moq::Mock <SchemaService.SchemaServiceClient> mockGrpcClient = new moq::Mock <SchemaService.SchemaServiceClient>(moq::MockBehavior.Strict);
            CreateSchemaRequest request = new CreateSchemaRequest
            {
                ParentAsProjectName = gagr::ProjectName.FromProject("[PROJECT]"),
                Schema   = new Schema(),
                SchemaId = "schema_idb515cf80",
            };
            Schema expectedResponse = new Schema
            {
                SchemaName = SchemaName.FromProjectSchema("[PROJECT]", "[SCHEMA]"),
                Type       = Schema.Types.Type.Unspecified,
                Definition = "definition3b8b6130",
            };

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

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

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
    public Schema CreateAvroSchema(string projectId, string schemaId, string pathToDefinition)
    {
        SchemaServiceClient schemaService = SchemaServiceClient.Create();
        var    schemaName       = SchemaName.FromProjectSchema(projectId, schemaId);
        string schemaDefinition = File.ReadAllText(pathToDefinition);
        Schema schema           = new Schema
        {
            Name       = schemaName.ToString(),
            Type       = Schema.Types.Type.Avro,
            Definition = schemaDefinition
        };
        CreateSchemaRequest createSchemaRequest = new CreateSchemaRequest
        {
            Parent   = "projects/" + projectId,
            SchemaId = schemaId,
            Schema   = schema
        };

        try
        {
            schema = schemaService.CreateSchema(createSchemaRequest);
            Console.WriteLine($"Schema {schema.Name} created.");
        }
        catch (RpcException e) when(e.Status.StatusCode == StatusCode.AlreadyExists)
        {
            Console.WriteLine($"Schema {schemaName} already exists.");
        }
        return(schema);
    }
Beispiel #3
0
 /// <summary>Snippet for CreateSchema</summary>
 public void CreateSchemaRequestObject()
 {
     // Snippet: CreateSchema(CreateSchemaRequest, CallSettings)
     // Create client
     SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create();
     // Initialize request argument(s)
     CreateSchemaRequest request = new CreateSchemaRequest
     {
         ParentAsProjectName = ProjectName.FromProject("[PROJECT]"),
         Schema   = new Schema(),
         SchemaId = "",
     };
     // Make the request
     Schema response = schemaServiceClient.CreateSchema(request);
     // End snippet
 }
Beispiel #4
0
        /// <summary>Snippet for CreateSchemaAsync</summary>
        public async Task CreateSchemaRequestObjectAsync()
        {
            // Snippet: CreateSchemaAsync(CreateSchemaRequest, CallSettings)
            // Additional: CreateSchemaAsync(CreateSchemaRequest, CancellationToken)
            // Create client
            SchemaServiceClient schemaServiceClient = await SchemaServiceClient.CreateAsync();

            // Initialize request argument(s)
            CreateSchemaRequest request = new CreateSchemaRequest
            {
                ParentAsProjectName = ProjectName.FromProject("[PROJECT]"),
                Schema   = new Schema(),
                SchemaId = "",
            };
            // Make the request
            Schema response = await schemaServiceClient.CreateSchemaAsync(request);

            // End snippet
        }
Beispiel #5
0
        /// <summary>
        /// Handles the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <returns></returns>
        public int Handle(CreateSchemaCommand command)
        {
            CreateSchemaRequest request = new CreateSchemaRequest
            {
                Name        = command.Name,
                Description = command.Description,
                ServerUrl   = command.ServerUrl
            };

            try
            {
                var response = this._schemaService.CreateSchema(request);
                Console.WriteLine(response);
                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(1);
            }
        }
        public void CreateSchema()
        {
            moq::Mock <SchemaService.SchemaServiceClient> mockGrpcClient = new moq::Mock <SchemaService.SchemaServiceClient>(moq::MockBehavior.Strict);
            CreateSchemaRequest request = new CreateSchemaRequest
            {
                ParentAsProjectName = gagr::ProjectName.FromProject("[PROJECT]"),
                Schema   = new Schema(),
                SchemaId = "schema_idb515cf80",
            };
            Schema expectedResponse = new Schema
            {
                SchemaName = SchemaName.FromProjectSchema("[PROJECT]", "[SCHEMA]"),
                Type       = Schema.Types.Type.Unspecified,
                Definition = "definition3b8b6130",
            };

            mockGrpcClient.Setup(x => x.CreateSchema(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            SchemaServiceClient client = new SchemaServiceClientImpl(mockGrpcClient.Object, null);
            Schema response            = client.CreateSchema(request.Parent, request.Schema, request.SchemaId);

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