Beispiel #1
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);
        }
Beispiel #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));
        }
Beispiel #3
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));
        }
Beispiel #4
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));
        }
Beispiel #5
0
        public void GitHubQuery_PingLocal_Test()
        {
            //Arrange
            bool result = false;

            //Act
            result = GitHubApiQuery.CheckByPing("127.0.0.1", 2000);

            //Assert
            Assert.IsTrue(result);
        }
Beispiel #6
0
        public void GitHubQuery_PingWEB_Test()
        {
            //Arrange
            bool result = false;

            //Act
            result = GitHubApiQuery.CheckByPing("8.8.8.8", 2000);

            //Assert
            Assert.IsTrue(result);
        }
Beispiel #7
0
        public void GitHubQuery_PingNoHost_Test()
        {
            //Arrange
            bool result = false;

            //Act
            result = GitHubApiQuery.CheckByPing("");

            //Assert
            Assert.IsFalse(result);
        }
Beispiel #8
0
        public void GitHubQuery_PingHostName_Test()
        {
            //Arrange
            bool result = false;

            //Act
            result = GitHubApiQuery.CheckByPing("www.google.com");

            //Assert
            Assert.IsTrue(result);
        }
Beispiel #9
0
        public void GitHubQuery_PingAssert_Test()
        {
            //Arrange
            bool result = false;

            //Act
            result = GitHubApiQuery.CheckByPing("127.0.0.1", -1);

            //Assert
            Assert.IsFalse(result);
        }
Beispiel #10
0
        public void RunQueryTest_ApiQueryMinStars()
        {
            // arrange
            int            apiResult      = 1000;
            GitHubApiQuery gitHubApiQuery = new GitHubApiQuery("Java");

            // act
            gitHubApiQuery.ApiQueryMinStars = apiResult;

            // assert
            Assert.IsTrue(apiResult == gitHubApiQuery.ApiQueryMinStars);
        }
Beispiel #11
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));
        }
Beispiel #12
0
        public void RunQueryTest_GetApiOrderCommand()
        {
            // arrange
            string         apiResult      = string.Empty;
            GitHubApiQuery gitHubApiQuery = new GitHubApiQuery("Java");

            // act
            apiResult = gitHubApiQuery.GetApiOrderCommand();

            // assert
            Assert.IsFalse(apiResult == string.Empty);
        }
Beispiel #13
0
        public void RunQueryTest_WhiteSpaceLanguageName_Exception()
        {
            // arrange
            bool throwArgumentException = false;

            // act
            try
            {
                GitHubApiQuery gitHubApiQuery = new GitHubApiQuery("     ");
            }
            catch (Exception ex)
            {
                throwArgumentException = ex is ArgumentException;
            }

            // assert
            Assert.IsTrue(throwArgumentException);
        }
Beispiel #14
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);
        }
Beispiel #15
0
        public void RunQueryTest_GitHubApiQuery_EmptyListString()
        {
            // arrange
            List <string>  languages      = new List <string>();
            GitHubApiQuery gitHubApiQuery = null;

            // act
            try
            {
                gitHubApiQuery = new GitHubApiQuery(languages);
            }
            catch (ArgumentException)
            {
                return;
            }

            // assert
            Assert.Fail();
        }
Beispiel #16
0
        public void RunQueryTest_HttpRequest_Exception()
        {
            // arrange
            bool           throwException         = false;
            bool           throwArgumentException = false;
            GitHubApiQuery gitHubApiQuery         = null;

            // act
            try
            {
                gitHubApiQuery = new GitHubApiQuery("");
            }
            catch (Exception ex)
            {
                throwException         = true;
                throwArgumentException = ex is ArgumentException;
            }

            // assert
            Assert.IsTrue(throwException && throwArgumentException);
        }
Beispiel #17
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));
        }
Beispiel #18
0
        public void ApiVersion_JustToCoverability_Test()
        {
            // arrange
            string         apiVersion     = string.Empty;
            GitHubApiQuery gitHubApiQuery = null;

            // act
            try
            {
                gitHubApiQuery            = new GitHubApiQuery(new List <string>(new string[] { "Java" }));
                apiVersion                = gitHubApiQuery.ApiVersion;
                gitHubApiQuery.ApiVersion = apiVersion;
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message, ex);
            }

            // assert
            Assert.IsFalse(string.IsNullOrEmpty(apiVersion));
        }
Beispiel #19
0
        public void CheckGitWebApiAccess_JustToCoverability_Test()
        {
            // arrange
            bool           result         = false;
            GitHubApiQuery gitHubApiQuery = null;

            // act
            try
            {
                gitHubApiQuery = new GitHubApiQuery(new List <string>(new string[] { "Java" }));
                gitHubApiQuery.CheckGitWebApiAccess();
                result = true;
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message, ex);
            }

            // assert
            Assert.IsTrue(result);
        }
Beispiel #20
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);
        }