예제 #1
0
        public void TestCheckKeys()
        {
            // good credentials
            var goodCredentials = ReadCredentialsFromFile("..\\..\\Credentials.txt");
            Assert.IsNotNull(goodCredentials);

            var api = new CSAPILowLevel(goodCredentials.ApiKey, goodCredentials.ApiId);

            try
            {
                Assert.IsTrue(api.CheckKeys());
            }
            catch (ApiException e)
            {
                Assert.Fail("We shouldn't get ApiException: " + e.Message);
            }

            try
            {
                var task = api.CheckKeysAsync();
                task.Wait();
                Assert.IsTrue(task.Result);
            }
            catch (ApiException e)
            {
                Assert.Fail("We shouldn't get ApiException: " + e.Message);
            }

            // bad credentials
            var badCredentials = ReadCredentialsFromFile("..\\..\\BadCredentials.txt");
            Assert.IsNotNull(badCredentials);

            api = new CSAPILowLevel(badCredentials.ApiKey, badCredentials.ApiId);
            try
            {
                api.CheckKeys();
                Assert.Fail("CheckKeys should throw ApiException");
            }
            catch (ApiException e)
            {
                // we should get here
                Console.WriteLine(e.Message);
            }

            try
            {
                var task = api.CheckKeysAsync();
                task.Wait();
                Assert.Fail("CheckKeysAsync should throw ApiException");
            }
            catch (AggregateException e)
            {
                Assert.IsTrue(e.InnerExceptions.Any(ex => ex is ApiException));
                Console.WriteLine(e.InnerException.Message);
            }
        }
예제 #2
0
 public CSAPIHighLevel(string apiKey, string apiId, string hostname = null)
 {
     _api = new CSAPILowLevel(apiKey, apiId, hostname);
 }
예제 #3
0
        public void TestTemplates()
        {
            var goodCredentials = ReadCredentialsFromFile("..\\..\\Credentials.txt");
            Assert.IsNotNull(goodCredentials);

            var api = new CSAPILowLevel(goodCredentials.ApiKey, goodCredentials.ApiId);
            Assert.IsTrue(api.CheckKeys());

            var highlevel = new CSAPIHighLevel(goodCredentials.ApiKey, goodCredentials.ApiId);
            var templatesList = highlevel.ListTemplates();

            var categoriesLists = (from t in templatesList select t.categories).ToList();
            var categories = new HashSet<string>();
            foreach (var cList in categoriesLists)
            {
                if (cList != null)
                    foreach (var item in cList)
                        if (item != null)
                            categories.Add((String)item);
            }
            Console.WriteLine(String.Join("\n", categories));

            Console.WriteLine("number of templates = " + templatesList.Count.ToString());
            var envList = highlevel.ListEnvironments();
            foreach (var env in envList)
                Console.WriteLine(env.name + "\t" + env.envId);
            foreach (var tmp in templatesList)
                if (tmp.memory_size_mb < 1024)
                    Console.WriteLine(tmp.name + "\t" + tmp.id);
        }
예제 #4
0
 public CSAPIHighLevel(string apiKey, string apiId, string hostname = null)
 {
     _api = new CSAPILowLevel (apiKey, apiId, hostname);
 }