public async Task AddProfile_UrlIsValid_NewProfileWasAddedToDb()
        {
            //Arrange
            LinkedinURL urlLink = new LinkedinURL();

            urlLink.LinkedInUri = "https://www.linkedin.com/in/williamhgates";

            //Act
            var res = await linkedinProfileController.AddProfile(urlLink);

            //Assert
            Assert.IsInstanceOfType(res, typeof(OkNegotiatedContentResult <string>));
        }
        public async Task AddProfile_UrlIsEmpty_ReturnFailedResult()
        {
            //Arrange
            LinkedinURL urlLink = new LinkedinURL();

            urlLink.LinkedInUri = string.Empty;

            //Act
            IHttpActionResult res = await linkedinProfileController.AddProfile(urlLink);

            //Assert
            Assert.IsInstanceOfType(res, typeof(BadRequestErrorMessageResult));
        }
        public async Task AddProfile_UrlIsNotLinkedinURL_ReturnFailedResult()
        {
            //Arrange
            LinkedinURL urlLink = new LinkedinURL();

            urlLink.LinkedInUri = "https://www.google.com/in/williamhgates";

            //Act
            IHttpActionResult res = await linkedinProfileController.AddProfile(urlLink);

            //Assert
            Assert.IsInstanceOfType(res, typeof(BadRequestErrorMessageResult));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> AddProfile(LinkedinURL profile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                string linkedInProfileUrl = profile.LinkedInUri;
                string linkedinProfileHtml;

                // If the user didnt put the url
                if (string.IsNullOrEmpty(linkedInProfileUrl))
                {
                    return(BadRequest("is empty"));
                }

                if (!UrlIsValid(linkedInProfileUrl))
                {
                    return(BadRequest("url is not valid"));
                }
                // Check if the url is of linkedin website
                int    startIndex      = linkedInProfileUrl.IndexOf(".com");
                string checkProfileUrl = linkedInProfileUrl.Substring(0, startIndex + 4);

                if (linkedinWebSite != checkProfileUrl)
                {
                    return(BadRequest("url is not the requested url"));
                }

                //  999 Request denied
                //try
                //{
                //     linkedinProfileHtml = httpRequetsMaker.getResponse(linkedInProfileUrl);
                //}

                //catch (Exception ex)
                //{
                //    return InternalServerError(ex);
                //}
                // ProfileDetails linkedinProfile = linkedInProfileHtmlParser.parse(linkedinProfileHtml);

                // read the html from file
                string         strHtml         = File.ReadAllText(@"C:\Users\aya\Documents\Visual Studio 2015\Projects\LinkedinProject\exempleProfile.txt");
                ProfileDetails linkedinProfile = linkedInProfileHtmlParser.parse(strHtml);

                ScorableData profileScoreData = new ScorableData(linkedinProfile.ProfileExperience, linkedinProfile.ProfileEducation, linkedinProfile.ProfileSkills);

                // calc the score
                linkedinProfile.Score = scoreCalc.calculateScore(profileScoreData);

                await pesrsistenceManager.addProfile(linkedinProfile);
            }
            catch (Exception ex)
            {
                Console.WriteLine(String.Format(" Error:{0}", ex.ToString()));
                return(InternalServerError(ex));
            }

            return(Ok("Profile was added succesfuly"));
        }