Ejemplo n.º 1
0
        public Task <ICheckResult> RunAsync()
        {
            var couchbaseApi = new RestHelper(
                new HttpBasicAuthenticator(_settings.Bucket, _settings.BucketPassword),
                new Uri(_settings.Server));

            var request = new RestRequest($"/pools/default/buckets/{_settings.Bucket}/");
            var stats   = couchbaseApi.Execute <CouchbaseBucketStat>(request);


            return(AvailableMemoryCheck(stats));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Rest API communication
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="resourceURL"></param>
        /// <param name="useBaseAPI"></param>
        /// <returns></returns>
        private T GetHubData <T>(string resourceURL = "pulls?state=closed", bool useBaseAPI = false)
        {
            RestHelper.BaseURL = useBaseAPI ? configuration["git_base_url"] : configuration["git_repo_url"];

            RestRequest restRequest = RestHelper.GetBaseRequest();

            restRequest.Resource = resourceURL;
            restRequest.Method   = Method.GET;

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            return(RestHelper.Execute <T>(restRequest, new HttpBasicAuthenticator(configuration["git_username"], configuration["git_access_token"])));
        }
Ejemplo n.º 3
0
        public void Execute_RestXml_CorrectInterpretation()
        {
            var xml = new RestXml()
            {
                Authentication = new AuthenticationXml {
                    Protocol = new AnonymousXml()
                },
                BaseAddress = "https://api.website.com",
                Path        = new RestPathXml {
                    Value = "v1/user/{user}"
                },
                Headers = new List <RestHeaderXml> {
                    new RestHeaderXml {
                        Name = "user-agent", Value = "nbi"
                    }
                },
                Parameters = new List <RestParameterXml> {
                    new RestParameterXml {
                        Name = "order-by", Value = "FullName | text-to-lower"
                    }
                },
                Segments = new List <RestSegmentXml> {
                    new RestSegmentXml {
                        Name = "user", Value = "@User"
                    }
                },
            };

            var variables = new Dictionary <string, ITestVariable> {
                { "User", new GlobalVariable(new LiteralScalarResolver <string>("seddryck")) }
            };

            var helper     = new RestHelper(new ServiceLocator(), null, SettingsXml.DefaultScope.Everywhere, variables);
            var restEngine = helper.Execute(xml);

            Assert.That(restEngine.BaseUrl.Execute(), Is.EqualTo("https://api.website.com"));
            Assert.That(restEngine.Path.Execute(), Is.EqualTo("v1/user/{user}"));
            Assert.That(restEngine.Headers.Count, Is.EqualTo(1));
            Assert.That(restEngine.Headers.First().Name.Execute(), Is.EqualTo("user-agent"));
            Assert.That(restEngine.Headers.First().Value.Execute(), Is.EqualTo("nbi"));
            Assert.That(restEngine.Parameters.Count, Is.EqualTo(1));
            Assert.That(restEngine.Parameters.First().Name.Execute(), Is.EqualTo("order-by"));
            Assert.That(restEngine.Parameters.First().Value.Execute(), Is.EqualTo("fullname"));
            Assert.That(restEngine.Segments.Count, Is.EqualTo(1));
            Assert.That(restEngine.Segments.First().Name.Execute(), Is.EqualTo("user"));
            Assert.That(restEngine.Segments.First().Value.Execute(), Is.EqualTo("seddryck"));
        }