예제 #1
0
        public void runRules_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.runRules(JsonConvert.SerializeObject(testList)));
        }
예제 #2
0
        public void runRules_TwoReviewsOneRule()
        {
            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);

            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"
                    },
                    new Review()
                    {
                        id          = "002",
                        dateWritten = "01/19/2021",
                        comments    = "positiveOne positiveOne positiveOne positiveOne positiveTwo " +
                                      "positiveTwo negativeOne negativeOne negativeOne negativeOne negativeOne"
                    }
                }
            };

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

            KeyValuePair <Review, int> review = analyzer.getTop(2)[0];

            Assert.AreEqual(3, review.Value);
            review = analyzer.getTop(2)[1];
            Assert.AreEqual(3, review.Value);
        }
예제 #3
0
        public void runRules_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.runRules(JsonConvert.SerializeObject(testList));

            KeyValuePair <testType, int> testType = analyzer.getTop(2)[0];

            Assert.AreEqual(2, testType.Value);
            testType = analyzer.getTop(2)[1];
            Assert.AreEqual(-2, testType.Value);
        }
예제 #4
0
        public void runRules_BadRule()
        {
            List <AnalyzerRule> rules = new List <AnalyzerRule>()
            {
                new AnalyzerRule()
                {
                    Key   = "aPropertyThatDoesNotExist",
                    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()
                {
                    testProperty = "positiveTwo"
                },
                new testType()
                {
                    testProperty = "negativeOne negativeOne"
                }
            };

            Assert.ThrowsException <Exception>(() => analyzer.runRules(JsonConvert.SerializeObject(testList)));
        }
예제 #5
0
        public void getTop_ReturnSubset()
        {
            List <AnalyzerRule> rules = new List <AnalyzerRule>()
            {
                new AnalyzerRule()
                {
                    Key   = "comments",
                    Rules = new List <KeyWeight>()
                    {
                        new KeyWeight()
                        {
                            Keyword = "amazing", Weight = 2
                        },
                        new KeyWeight()
                        {
                            Keyword = "helpful", Weight = 1
                        },
                        new KeyWeight()
                        {
                            Keyword = "bad", Weight = -1
                        }
                    }
                }
            };
            JsonAnalyzer <Review> analyzer = new JsonAnalyzer <Review>(rules);


            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    = "Helpful and amazing"
                    },
                    new Review()
                    {
                        id          = "002",
                        dateWritten = "01/19/2021",
                        comments    = "Amazing and a little bad"
                    },
                    new Review()
                    {
                        id          = "003",
                        dateWritten = "01/19/2021",
                        comments    = "Helpful and a little bad"
                    },
                    new Review()
                    {
                        id          = "003",
                        dateWritten = "01/19/2021",
                        comments    = "Just bad"
                    }
                }
            };

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

            int numToReturn = 2;

            List <KeyValuePair <Review, int> > returned = analyzer.getTop(numToReturn);

            Assert.AreEqual(numToReturn, returned.Count);
        }