예제 #1
0
        public void RunQueryTest_GetJsonFromSqlTest_SQLServerOffline()
        {
            // arrange
            string         jsonResult     = string.Empty;
            GitHubApiQuery gitHubApiQuery = null;

            // act
            try
            {
                gitHubApiQuery = new GitHubApiQuery(new List <string>(new string[] { "Java" }));
                gitHubApiQuery.MillisecondsToWait = 10000; //  Adjust for LAN service access.
                gitHubApiQuery.ApiItemsPerPage    = 5;
                gitHubApiQuery.ApiPages           = 1;

                gitHubApiQuery.RunQuery();

                jsonResult = gitHubApiQuery.GetJsonFromSql();

                Assert.IsTrue(string.IsNullOrEmpty(jsonResult), "\n\nPara este teste passar o SQL Server deve estar indisponível.\n");
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message, ex);
            }

            // assert
            Assert.IsTrue(string.IsNullOrEmpty(jsonResult));
        }
예제 #2
0
        public void RunQueryTest_GitHubApiOffline_Exception()
        {
            // arrange
            GitHubApiQuery gitHubApiQuery  = null;
            string         gitHubApiResult = string.Empty;

            // act
            try
            {
                gitHubApiQuery  = new GitHubApiQuery("Java");
                gitHubApiResult = gitHubApiQuery.RunQuery();

                if (!string.IsNullOrEmpty(gitHubApiResult))
                {
                    Assert.IsTrue(string.IsNullOrEmpty(gitHubApiResult),
                                  "\nO serviço GitHubApi tem que estar fora do ar para este teste passar\nDesconecte-se da internet.");
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message, ex);
            }

            // assert
            Assert.IsTrue(string.IsNullOrEmpty(gitHubApiResult));
        }
예제 #3
0
        public void RunQueryTest_GetJsonFromSqlTest_SQLServerOnline()
        {
            // arrange
            List <string>  languages      = new List <string>(new string[] { "Java", "C", "Python", "C++", "C#" });
            string         jsonResult     = string.Empty;
            GitHubApiQuery gitHubApiQuery = null;

            // act
            try
            {
                gitHubApiQuery = new GitHubApiQuery(languages);
                gitHubApiQuery.MillisecondsToWait = 100000; //  Adjust for LAN service access.
                gitHubApiQuery.ApiItemsPerPage    = 5;
                gitHubApiQuery.ApiPages           = 1;

                gitHubApiQuery.RunQuery();

                jsonResult = gitHubApiQuery.GetJsonFromSql();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message, ex);
            }

            // assert
            Assert.IsFalse(string.IsNullOrEmpty(jsonResult));
        }
예제 #4
0
        public void RunQueryTest_HttpRequest_TimeOutException()
        {
            // arrange
            bool           throwException        = false;
            bool           throwTimeOutException = false;
            string         result         = string.Empty;
            GitHubApiQuery gitHubApiQuery = new GitHubApiQuery("Java");

            gitHubApiQuery.MillisecondsToWait = 500;

            // act
            try
            {
                result = gitHubApiQuery.RunQuery();

                if (string.IsNullOrEmpty(result))
                {
                    throwException        = true;
                    throwTimeOutException = true;
                }
            }
            //
            //  HttpClient take care about TimeoutException so TaskCanceledException should be used instead.
            //  Keep this code here things may change in the future.
            //
            catch (TimeoutException)
            {
                throwException        = true;
                throwTimeOutException = true;
            }

            // assert
            Assert.IsTrue(throwException && throwTimeOutException);
        }
예제 #5
0
        public void RunQueryTest_WithValidLanguageName()
        {
            // arrange
            string         queryResult    = string.Empty;
            GitHubApiQuery gitHubApiQuery = new GitHubApiQuery("Java");

            // act
            queryResult = gitHubApiQuery.RunQuery();

            // assert
            Assert.IsFalse(string.IsNullOrEmpty(queryResult));
        }
예제 #6
0
        public void RunQueryTest_GetItemsTest_EmptyObjectListFromJson()
        {
            // arrange
            GitHubApiQuery gitHubApiQuery = null;

            // act
            try
            {
                gitHubApiQuery = new GitHubApiQuery("");
                gitHubApiQuery.RunQuery();
            }
            catch (ArgumentException)
            {
                gitHubApiQuery = null;
            }

            // assert
            Assert.IsTrue(gitHubApiQuery == null);
        }
예제 #7
0
        public void RunQueryTest_GetItemsTest_NotEmptyObjectListFromJson()
        {
            // arrange
            string         jsonResult     = string.Empty;
            GitHubApiQuery gitHubApiQuery = null;

            // act
            try
            {
                gitHubApiQuery = new GitHubApiQuery(new List <string>(new string[] { "Java", "C", "Python", "C++", "C#" }));
                gitHubApiQuery.MillisecondsToWait = 100000; //  Adjust for LAN service access.
                jsonResult = gitHubApiQuery.RunQuery();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message, ex);
            }

            // assert
            Assert.IsFalse(gitHubApiQuery == null && string.IsNullOrEmpty(jsonResult));
        }
예제 #8
0
        public HttpResponseMessage GitHubQuery()
        {
            // arrange
            string         jsonResult     = string.Empty;
            GitHubApiQuery gitHubApiQuery = null;

            //Requester info - Just to log - Later a cache control may be implemented.
            //var ip = HttpRequestMessageExtensions.GetClientIpAddress(this.Request);

            // act
            try
            {
                gitHubApiQuery =
                    new GitHubApiQuery(new List <string>(new string[] { "Java", "C", "Python", "C++", "C#" }));
                gitHubApiQuery.ApiItemsPerPage = 5;
                gitHubApiQuery.ApiPages        = 1;

                gitHubApiQuery.RunQuery();

                jsonResult = gitHubApiQuery.GetJsonFromSql();
            }
            catch (FileLoadException)
            {
                // Ignore - Debug exception.
            }
            catch (Exception)
            {
                // Serviço não está ativo.
                //throw new Exception(ex.Message, ex);
                return(null);
            }

            HttpResponseMessage resp = new HttpResponseMessage {
                Content = new StringContent(jsonResult, System.Text.Encoding.UTF8, "application/json")
            };

            return(resp);
        }