public void ImgesSetReturnsBoolTrue()
        {
            //arrage
            Reccommendations fc = new Reccommendations
            {
                UseSentiment = true
            };

            //assert
            Assert.True(fc.UseSentiment);
        }
        public void UseSentiment()
        {
            //arrange
            Reccommendations Img = new Reccommendations
            {
                Sentiment = .01f
            };

            //assert
            Assert.Equal(.01f, Img.Sentiment);
        }
        public void UseKeyPhrase()
        {
            //arrange
            Reccommendations testPhrase = new Reccommendations
            {
                KeyPhrase = "Happy"
            };

            //assert
            Assert.Equal("Happy", testPhrase.KeyPhrase);
        }
示例#4
0
        // pulling out the logic to make testing easier
        public Reccommendations GenerateRecs(string data, int num)
        {
            // We only have 5 images in the database
            if (num > 5)
            {
                num = 3;
            }

            //Try to parse data as a float. If succeed, put the value into sentiment and return true
            //True will get you into the validation block.
            bool usesentiment = false;

            if (float.TryParse(data, out float sentiment))
            {
                usesentiment = true; // IF the input can be parsed as a float, use sentiment
                if (sentiment < 0 || sentiment > 1)
                {
                    usesentiment = false; // if data can be parsed as a float BUT is not a valid value for sentiment
                    data         = sentiment.ToString();
                }
            }
            IEnumerable <Image> reccomendations = usesentiment ?
                                                  GetImageBySentiment(sentiment) :
                                                  BingSearch(data).Result;

            //Repackage into single object
            Reccommendations rec = new Reccommendations()
            {
                Images       = reccomendations.Take(num),
                UseSentiment = usesentiment,
                Sentiment    = usesentiment ? sentiment : -1,
                KeyPhrase    = usesentiment ? "" : data
            };

            return(rec);
        }