public void Profle_Catch_Exception()
        {
            IClient client = CreateClient();

            IRequest request = Substitute.For <IRequest>();

            client.PostAsync(Arg.Any <string>())
            .Returns(x =>
            {
                throw new AggregateException(new ServiceResponseException(Substitute.For <IResponse>(),
                                                                          Substitute.For <HttpResponseMessage>(HttpStatusCode.BadRequest),
                                                                          string.Empty));
            });

            //  Test Profile
            ContentListContainer contentListContainer = new ContentListContainer()
            {
                ContentItems = new List <ContentItem>()
                {
                    new ContentItem()
                    {
                        Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN,
                        Language    = ContentItem.LanguageEnum.EN,
                        Content     = content
                    }
                }
            };

            PersonalityInsightsService service = new PersonalityInsightsService(client);

            service.VersionDate = "versionDate";

            service.Profile("contentType", "application/json", contentListContainer);
        }
        public static void Main(string[] args)
        {
            var environmentVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES");
            var fileContent         = File.ReadAllText(environmentVariable);
            var vcapServices        = JObject.Parse(fileContent);
            var _username           = vcapServices["personality_insights"][0]["credentials"]["username"];
            var _password           = vcapServices["personality_insights"][0]["credentials"]["password"];

            PersonalityInsightsService _personalityInsights = new PersonalityInsightsService(_username.ToString(), _password.ToString(), "2016-10-20");
            string content = "The IBM Watson™ Personality Insights service provides a Representational State Transfer (REST) Application Programming Interface (API) that enables applications to derive insights from social media, enterprise data, or other digital communications. The service uses linguistic analytics to infer individuals' intrinsic personality characteristics, including Big Five, Needs, and Values, from digital communications such as email, text messages, tweets, and forum posts. The service can automatically infer, from potentially noisy social media, portraits of individuals that reflect their personality characteristics. The service can report consumption preferences based on the results of its analysis, and for JSON content that is timestamped, it can report temporal behavior.";

            //  Test Profile
            ContentListContainer contentListContainer = new ContentListContainer()
            {
                ContentItems = new List <ContentItem>()
                {
                    new ContentItem()
                    {
                        Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN,
                        Language    = ContentItem.LanguageEnum.EN,
                        Content     = content
                    }
                }
            };

            var result = _personalityInsights.Profile("text/plain", "application/json", contentListContainer, rawScores: true, consumptionPreferences: true, csvHeaders: true);

            Console.WriteLine(string.Format("Profile result: {0}", result));

            Console.ReadKey();
        }
        public Profile Profile(string contentType, string accept, ContentListContainer body, string contentLanguage = null, string acceptLanguage = null, bool?rawScores = null, bool?csvHeaders = null, bool?consumptionPreferences = null)
        {
            if (string.IsNullOrEmpty(contentType))
            {
                throw new ArgumentNullException(nameof(contentType));
            }
            if (string.IsNullOrEmpty(accept))
            {
                throw new ArgumentNullException(nameof(accept));
            }
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }

            if (string.IsNullOrEmpty(VersionDate))
            {
                throw new ArgumentNullException("versionDate cannot be null.");
            }

            Profile result = null;

            try
            {
                result = this.Client.WithAuthentication(this.UserName, this.Password)
                         .PostAsync($"{this.Endpoint}/v3/profile")
                         .WithArgument("version", VersionDate)
                         .WithHeader("Content-Type", contentType)
                         .WithHeader("Content-Language", contentLanguage)
                         .WithHeader("Accept", accept)
                         .WithHeader("Accept-Language", acceptLanguage)
                         .WithArgument("raw_scores", rawScores)
                         .WithArgument("csv_headers", csvHeaders)
                         .WithArgument("consumption_preferences", consumptionPreferences)
                         .WithBody <ContentListContainer>(body)
                         .As <Profile>()
                         .Result;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }
        public void Profile_No_Accept()
        {
            PersonalityInsightsService service =
                new PersonalityInsightsService("username", "password", "versionDate");

            //  Test Profile
            ContentListContainer contentListContainer = new ContentListContainer()
            {
                ContentItems = new List <ContentItem>()
                {
                    new ContentItem()
                    {
                        Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN,
                        Language    = ContentItem.LanguageEnum.EN,
                        Content     = content
                    }
                }
            };

            service.Profile("test", null, contentListContainer);
        }
        public void Profile_Success()
        {
            PersonalityInsightsService _personalityInsights = new PersonalityInsightsService(_username.ToString(), _password.ToString(), "2016-10-20");
            string content = "The IBM Watson™ Personality Insights service provides a Representational State Transfer (REST) Application Programming Interface (API) that enables applications to derive insights from social media, enterprise data, or other digital communications. The service uses linguistic analytics to infer individuals' intrinsic personality characteristics, including Big Five, Needs, and Values, from digital communications such as email, text messages, tweets, and forum posts. The service can automatically infer, from potentially noisy social media, portraits of individuals that reflect their personality characteristics. The service can report consumption preferences based on the results of its analysis, and for JSON content that is timestamped, it can report temporal behavior.";

            ContentListContainer contentListContainer = new ContentListContainer()
            {
                ContentItems = new List <ContentItem>()
                {
                    new ContentItem()
                    {
                        Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN,
                        Language    = ContentItem.LanguageEnum.EN,
                        Content     = content
                    }
                }
            };

            var result = _personalityInsights.Profile("text/plain", "application/json", contentListContainer, rawScores: true, consumptionPreferences: true, csvHeaders: true);

            Assert.IsNotNull(result);
        }
        private JsonResult AnalyseData(string data)
        {
            if (data.Length < 100)
            {
                throw new ArgumentException($"The number of words {data.Length} is less than the minimum number of words required for analysis: 100");
            }

            ContentListContainer contentListContainer = new ContentListContainer
            {
                ContentItems = new List <ContentItem>()
                {
                    new ContentItem()
                    {
                        Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN,
                        Language    = ContentItem.LanguageEnum.EN,
                        Content     = data
                    }
                }
            };

            var result = _personalityInsights.Profile("text/plain", "application/json", contentListContainer, rawScores: true, consumptionPreferences: true, csvHeaders: true);

            return(Json(result));
        }
        public void Profile_Success()
        {
            IClient client = this.CreateClient();

            IRequest request = Substitute.For <IRequest>();

            client.PostAsync(Arg.Any <string>())
            .Returns(request);

            #region Response
            Profile response =
                new Profile()
            {
                ProcessedLanguage = "en",
                WordCount         = 10,
                WordCountMessage  = "wordCountMessage",
                Personality       = new List <TraitTreeNode>()
                {
                    new TraitTreeNode()
                    {
                        TraitId    = "traitID",
                        Name       = "name",
                        Category   = "category",
                        Percentile = 50.0,
                        RawScore   = 25.0,
                        Children   = new List <TraitTreeNode>()
                        {
                            new TraitTreeNode()
                            {
                                TraitId    = "traitID",
                                Name       = "name",
                                Category   = "category",
                                Percentile = 50.0,
                                RawScore   = 25.0
                            }
                        }
                    }
                },
                Values = new List <TraitTreeNode>()
                {
                    new TraitTreeNode()
                    {
                        TraitId    = "traitID",
                        Name       = "name",
                        Category   = "category",
                        Percentile = 50.0,
                        RawScore   = 25.0,
                        Children   = new List <TraitTreeNode>()
                        {
                            new TraitTreeNode()
                            {
                                TraitId    = "traitID",
                                Name       = "name",
                                Category   = "category",
                                Percentile = 50.0,
                                RawScore   = 25.0
                            }
                        }
                    }
                },
                Needs = new List <TraitTreeNode>()
                {
                    new TraitTreeNode()
                    {
                        TraitId    = "traitID",
                        Name       = "name",
                        Category   = "category",
                        Percentile = 50.0,
                        RawScore   = 25.0,
                        Children   = new List <TraitTreeNode>()
                        {
                            new TraitTreeNode()
                            {
                                TraitId    = "traitID",
                                Name       = "name",
                                Category   = "category",
                                Percentile = 50.0,
                                RawScore   = 25.0
                            }
                        }
                    }
                },
                Behavior = new List <BehaviorNode>()
                {
                    new BehaviorNode()
                    {
                        TraitId    = "traitID",
                        Name       = "name",
                        Category   = "category",
                        Percentage = 50.0
                    }
                },
                ConsumptionPreferences = new List <ConsumptionPreferencesCategoryNode>()
                {
                    new ConsumptionPreferencesCategoryNode()
                    {
                        ConsumptionPreferenceCategoryId = "consumptionPreferenceCategoryId",
                        Name = "name",
                        ConsumptionPreferences = new List <ConsumptionPreferencesNode>()
                        {
                            new ConsumptionPreferencesNode()
                            {
                                ConsumptionPreferenceId = "consumptionPreferenceId",
                                Name  = "name",
                                Score = 50.0
                            }
                        }
                    }
                },
                Warnings = new List <Warning>()
                {
                    new Warning()
                    {
                        WarningId = "warningId",
                        Message   = "message"
                    }
                }
            };
            #endregion

            //  Test Profile
            ContentListContainer contentListContainer = new ContentListContainer()
            {
                ContentItems = new List <ContentItem>()
                {
                    new ContentItem()
                    {
                        Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN,
                        Language    = ContentItem.LanguageEnum.EN,
                        Content     = content
                    }
                }
            };

            request.WithArgument(Arg.Any <string>(), Arg.Any <string>())
            .Returns(request);
            request.WithHeader(Arg.Any <string>(), Arg.Any <string>())
            .Returns(request);
            request.WithHeader(Arg.Any <string>(), Arg.Any <string>())
            .Returns(request);
            request.WithHeader(Arg.Any <string>(), Arg.Any <string>())
            .Returns(request);
            request.WithHeader(Arg.Any <string>(), Arg.Any <string>())
            .Returns(request);
            request.WithArgument(Arg.Any <string>(), Arg.Any <bool>())
            .Returns(request);
            request.WithArgument(Arg.Any <string>(), Arg.Any <bool>())
            .Returns(request);
            request.WithArgument(Arg.Any <string>(), Arg.Any <bool>())
            .Returns(request);
            request.WithBody(Arg.Any <ContentListContainer>())
            .Returns(request);

            request.As <Profile>()
            .Returns(Task.FromResult(response));

            PersonalityInsightsService service = new PersonalityInsightsService(client);
            service.VersionDate = "versionDate";

            var result =
                service.Profile("contentType", "application/json", contentListContainer);

            Assert.IsNotNull(result);
            client.Received().PostAsync(Arg.Any <string>());
            Assert.IsTrue(result.Behavior.Count > 0);
            Assert.IsTrue(result.ConsumptionPreferences.Count > 0);
            Assert.IsTrue(result.Needs.Count > 0);
            Assert.IsTrue(result.Personality.Count > 0);
            Assert.IsTrue(result.ProcessedLanguage == "en");
            Assert.IsTrue(result.WordCount == 10);
            Assert.IsTrue(result.Values.Count > 0);
            Assert.IsTrue(result.Warnings.Count > 0);
            Assert.IsTrue(result.WordCountMessage == "wordCountMessage");
        }