Exemplo n.º 1
0
        public void GetConnector()
        {
            moq::Mock <VpcAccessService.VpcAccessServiceClient> mockGrpcClient = new moq::Mock <VpcAccessService.VpcAccessServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetConnectorRequest request = new GetConnectorRequest
            {
                ConnectorName = ConnectorName.FromProjectLocationConnector("[PROJECT]", "[LOCATION]", "[CONNECTOR]"),
            };
            Connector expectedResponse = new Connector
            {
                ConnectorName     = ConnectorName.FromProjectLocationConnector("[PROJECT]", "[LOCATION]", "[CONNECTOR]"),
                Network           = "networkd22ce091",
                IpCidrRange       = "ip_cidr_range745a04d3",
                State             = Connector.Types.State.Unspecified,
                MinThroughput     = -1306078102,
                MaxThroughput     = 1609945563,
                ConnectedProjects =
                {
                    "connected_projects7e2fb014",
                },
                Subnet = new Connector.Types.Subnet(),
            };

            mockGrpcClient.Setup(x => x.GetConnector(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            VpcAccessServiceClient client = new VpcAccessServiceClientImpl(mockGrpcClient.Object, null);
            Connector response            = client.GetConnector(request.Name);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 2
0
        public async stt::Task GetConnectorRequestObjectAsync()
        {
            moq::Mock <VpcAccessService.VpcAccessServiceClient> mockGrpcClient = new moq::Mock <VpcAccessService.VpcAccessServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetConnectorRequest request = new GetConnectorRequest
            {
                ConnectorName = ConnectorName.FromProjectLocationConnector("[PROJECT]", "[LOCATION]", "[CONNECTOR]"),
            };
            Connector expectedResponse = new Connector
            {
                ConnectorName     = ConnectorName.FromProjectLocationConnector("[PROJECT]", "[LOCATION]", "[CONNECTOR]"),
                Network           = "networkd22ce091",
                IpCidrRange       = "ip_cidr_range745a04d3",
                State             = Connector.Types.State.Unspecified,
                MinThroughput     = -1306078102,
                MaxThroughput     = 1609945563,
                ConnectedProjects =
                {
                    "connected_projects7e2fb014",
                },
                Subnet = new Connector.Types.Subnet(),
            };

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

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

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