Пример #1
0
        public void outputWordCount_ReviewWithNoProperty()
        {
            List <AnalyzerRule> rules = new List <AnalyzerRule>()
            {
                new AnalyzerRule()
                {
                    Key   = "testProperty",
                    Rules = new List <KeyWeight>()
                    {
                        new KeyWeight()
                        {
                            Keyword = "positiveOne", Weight = 1
                        },
                        new KeyWeight()
                        {
                            Keyword = "negativeOne", Weight = -1
                        },
                        new KeyWeight()
                        {
                            Keyword = "positiveTwo", Weight = 2
                        }
                    }
                }
            };

            JsonAnalyzer <testType> analyzer = new JsonAnalyzer <testType>(rules);

            List <testType> testList = new List <testType>()
            {
                new testType(),
                new testType()
            };

            Assert.ThrowsException <Exception>(() => analyzer.outputWordCount(JsonConvert.SerializeObject(testList)));
        }
Пример #2
0
        public void outputWordCount_OneReviewOneRule()
        {
            List <AnalyzerRule> rules = new List <AnalyzerRule>()
            {
                new AnalyzerRule()
                {
                    Key   = "comments",
                    Rules = new List <KeyWeight>()
                    {
                        new KeyWeight()
                        {
                            Keyword = "positiveOne", Weight = 1
                        },
                        new KeyWeight()
                        {
                            Keyword = "negativeOne", Weight = -1
                        },
                        new KeyWeight()
                        {
                            Keyword = "positiveTwo", Weight = 2
                        }
                    }
                }
            };

            JsonAnalyzer <Review> analyzer = new JsonAnalyzer <Review>(rules);

            StringWriter debugLog = new StringWriter();

            Console.SetOut(debugLog);
            Console.SetError(debugLog);

            ReviewCollection mockCollection = new ReviewCollection()
            {
                dealerId    = "12345",
                ratingURl   = "test/ratings",
                name        = "testDealer",
                reviewCount = 1,
                reviews     = new List <Review>()
                {
                    new Review()
                    {
                        id          = "001",
                        dateWritten = "01/19/2021",
                        comments    = "positiveOne positiveOne positiveOne positiveOne positiveTwo " +
                                      "positiveTwo negativeOne negativeOne negativeOne negativeOne negativeOne"
                    }
                }
            };

            analyzer.outputWordCount(JsonConvert.SerializeObject(mockCollection.reviews));

            string log = debugLog.ToString();

            Assert.AreEqual(0, "negativeone 5\r\npositiveone 4\r\npositivetwo 2\r\n".CompareTo(log));
        }
Пример #3
0
        public void outputWordCount_CustomObject()
        {
            List <AnalyzerRule> rules = new List <AnalyzerRule>()
            {
                new AnalyzerRule()
                {
                    Key   = "testProperty",
                    Rules = new List <KeyWeight>()
                    {
                        new KeyWeight()
                        {
                            Keyword = "positiveOne", Weight = 1
                        },
                        new KeyWeight()
                        {
                            Keyword = "negativeOne", Weight = -1
                        },
                        new KeyWeight()
                        {
                            Keyword = "positiveTwo", Weight = 2
                        }
                    }
                }
            };

            JsonAnalyzer <testType> analyzer = new JsonAnalyzer <testType>(rules);

            StringWriter debugLog = new StringWriter();

            Console.SetOut(debugLog);
            Console.SetError(debugLog);

            List <testType> testList = new List <testType>()
            {
                new testType()
                {
                    testProperty = "positiveTwo"
                },
                new testType()
                {
                    testProperty = "negativeOne negativeOne"
                }
            };

            analyzer.outputWordCount(JsonConvert.SerializeObject(testList));

            string log = debugLog.ToString();

            Assert.AreEqual(0, "negativeone 2\r\npositivetwo 1\r\n".CompareTo(log));
        }