Exemplo n.º 1
0
        public async stt::Task SearchHashesAsync()
        {
            moq::Mock <WebRiskServiceV1Beta1.WebRiskServiceV1Beta1Client> mockGrpcClient = new moq::Mock <WebRiskServiceV1Beta1.WebRiskServiceV1Beta1Client>(moq::MockBehavior.Strict);
            SearchHashesRequest request = new SearchHashesRequest
            {
                HashPrefix  = proto::ByteString.CopyFromUtf8("hash_prefix0c2a6688"),
                ThreatTypes =
                {
                    ThreatType.SocialEngineering,
                },
            };
            SearchHashesResponse expectedResponse = new SearchHashesResponse
            {
                Threats =
                {
                    new SearchHashesResponse.Types.ThreatHash(),
                },
                NegativeExpireTime = new wkt::Timestamp(),
            };

            mockGrpcClient.Setup(x => x.SearchHashesAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <SearchHashesResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            WebRiskServiceV1Beta1Client client = new WebRiskServiceV1Beta1ClientImpl(mockGrpcClient.Object, null);
            SearchHashesResponse        responseCallSettings = await client.SearchHashesAsync(request.HashPrefix, request.ThreatTypes, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            SearchHashesResponse responseCancellationToken = await client.SearchHashesAsync(request.HashPrefix, request.ThreatTypes, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 2
0
        public async Task SearchHashesAsync2()
        {
            Mock <WebRiskServiceV1Beta1.WebRiskServiceV1Beta1Client> mockGrpcClient = new Mock <WebRiskServiceV1Beta1.WebRiskServiceV1Beta1Client>(MockBehavior.Strict);
            SearchHashesRequest  request          = new SearchHashesRequest();
            SearchHashesResponse expectedResponse = new SearchHashesResponse();

            mockGrpcClient.Setup(x => x.SearchHashesAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <SearchHashesResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            WebRiskServiceV1Beta1Client client   = new WebRiskServiceV1Beta1ClientImpl(mockGrpcClient.Object, null);
            SearchHashesResponse        response = await client.SearchHashesAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 3
0
        public async Task SearchHashesAsync()
        {
            Mock <WebRiskServiceV1Beta1.WebRiskServiceV1Beta1Client> mockGrpcClient = new Mock <WebRiskServiceV1Beta1.WebRiskServiceV1Beta1Client>(MockBehavior.Strict);
            SearchHashesRequest expectedRequest = new SearchHashesRequest
            {
                HashPrefix  = ByteString.CopyFromUtf8("-29"),
                ThreatTypes = { },
            };
            SearchHashesResponse expectedResponse = new SearchHashesResponse();

            mockGrpcClient.Setup(x => x.SearchHashesAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <SearchHashesResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            WebRiskServiceV1Beta1Client client = new WebRiskServiceV1Beta1ClientImpl(mockGrpcClient.Object, null);
            ByteString hashPrefix = ByteString.CopyFromUtf8("-29");
            IEnumerable <ThreatType> threatTypes = new List <ThreatType>();
            SearchHashesResponse     response    = await client.SearchHashesAsync(hashPrefix, threatTypes);

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