コード例 #1
0
        public void CreateProfileRequestObject()
        {
            moq::Mock <ProfilerService.ProfilerServiceClient> mockGrpcClient = new moq::Mock <ProfilerService.ProfilerServiceClient>(moq::MockBehavior.Strict);
            CreateProfileRequest request = new CreateProfileRequest
            {
                Deployment  = new Deployment(),
                ProfileType =
                {
                    ProfileType.Contention,
                },
                Parent = "parent7858e4d0",
            };
            Profile expectedResponse = new Profile
            {
                Name         = "name1c9368b0",
                ProfileType  = ProfileType.Contention,
                Deployment   = new Deployment(),
                Duration     = new wkt::Duration(),
                ProfileBytes = proto::ByteString.CopyFromUtf8("profile_bytes12d9894a"),
                Labels       =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
            };

            mockGrpcClient.Setup(x => x.CreateProfile(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            ProfilerServiceClient client = new ProfilerServiceClientImpl(mockGrpcClient.Object, null);
            Profile response             = client.CreateProfile(request);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
コード例 #2
0
        public async stt::Task UpdateProfileRequestObjectAsync()
        {
            moq::Mock <ProfilerService.ProfilerServiceClient> mockGrpcClient = new moq::Mock <ProfilerService.ProfilerServiceClient>(moq::MockBehavior.Strict);
            UpdateProfileRequest request = new UpdateProfileRequest
            {
                Profile    = new Profile(),
                UpdateMask = new wkt::FieldMask(),
            };
            Profile expectedResponse = new Profile
            {
                Name         = "name1c9368b0",
                ProfileType  = ProfileType.Contention,
                Deployment   = new Deployment(),
                Duration     = new wkt::Duration(),
                ProfileBytes = proto::ByteString.CopyFromUtf8("profile_bytes12d9894a"),
                Labels       =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
            };

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

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

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