public static void Main(string[] args)
        {
            var contentAnalyzer = new ContentAnalyzer(new FakeRepository());             // Could also have used Moq.

            Console.WriteLine("Story 1");
            Console.WriteLine("Scanned the text:");
            contentAnalyzer.SetContentFilteringStatus(false);
            Console.WriteLine(contentAnalyzer.GetContent());
            Console.WriteLine("Total Number of negative words: " + contentAnalyzer.GetBannedWordCount());
            Console.WriteLine();

            Console.WriteLine("Story 2");
            Console.WriteLine("I haven't implemented an UpdateBannedWords method but the unit tests prove that the list of banned words is not hard coded.");
            Console.WriteLine();

            Console.WriteLine("Story 3");
            contentAnalyzer.SetContentFilteringStatus(true);
            Console.WriteLine(contentAnalyzer.GetContent());
            Console.WriteLine();

            Console.WriteLine("Story 4");
            Console.WriteLine("Scanned the text:");
            contentAnalyzer.SetContentFilteringStatus(false);
            Console.WriteLine(contentAnalyzer.GetContent());
            Console.WriteLine("Total Number of negative words: " + contentAnalyzer.GetBannedWordCount());
            Console.WriteLine();

            Console.WriteLine("Press ANY key to exit.");
            Console.ReadKey();
        }
        public async Task <List <HostInfoDto> > CheckDomainNames(IEnumerable <string> domains)
        {
            var hostInfoDtos = new List <HostInfoDto>();

            var tasks = domains
                        .Select(async domain =>
            {
                var host = await UriHelper.StringToAbsoluteUriAsync(domain);
                if (host != null)
                {
                    var hostInfoDto = new HostInfoDto()
                    {
                        Ips      = host.Ips,
                        SafeHost = host.SafeHost,
                        Uri      = host.Uri
                    };

                    var response = await _httpClient.GetAsync(host.Uri);

                    // analyze cookies
                    // analyze url
                    // analyze html content
                    // analyze scripts

                    var headersTechs = ContentAnalyzer.AnalyzeHeaders(response.Headers);
                    hostInfoDto.Techs.AddRange(headersTechs);

                    hostInfoDtos.Add(hostInfoDto);
                }
            });

            await Task.WhenAll(tasks);

            return(hostInfoDtos);
        }
Beispiel #3
0
        protected internal virtual async Task <string> GetMediaTypeAsync(Stream stream, string name, CancellationToken cancellationToken)
        {
            string mediaType;

            if (null != ContentAnalyzer)
            {
                var contentInfo = await ContentAnalyzer.Analyze(stream, name, true, cancellationToken).ConfigureAwait(false);

                if (null != contentInfo && !string.IsNullOrEmpty(contentInfo.MediaType))
                {
                    Logger.LogDebug("Successfully detected media type for \"{0}\" as \"{1}\".", name, contentInfo.MediaType);
                    mediaType = contentInfo.MediaType;
                }
                else
                {
                    Logger.LogDebug("Unable to detect media type for \"{0}\".", name);
                    mediaType = "application/octet-stream";
                }
            }
            else
            {
                Logger.LogDebug("No content type analyzer specified to detect media type for \"{0}\".", name);
                mediaType = "application/octet-stream";
            }
            return(mediaType);
        }
        public void BannedWordListNotHardCodedTest()
        {
            const string content = "weather in manchester is bad and horrible.";

            // The same content returns 2 banned words in the first case and
            // 1 in the second case when we change the master list of banned words.
            var mockRepository1 = new Mock <IContentRepository>();

            mockRepository1.Setup(x => x.GetBannedWords()).Returns(new List <string> {
                "bad", "horrible"
            });
            mockRepository1.Setup(x => x.GetContent()).Returns(content);
            var contentAnalyser1 = new ContentAnalyzer(mockRepository1.Object);
            int actualCount1     = contentAnalyser1.GetBannedWordCount();

            Assert.AreEqual(2, actualCount1);

            var mockRepository2 = new Mock <IContentRepository>();

            mockRepository2.Setup(x => x.GetBannedWords()).Returns(new List <string> {
                "horrible"
            });
            mockRepository2.Setup(x => x.GetContent()).Returns(content);
            var contentAnalyser2 = new ContentAnalyzer(mockRepository2.Object);
            int actualCount2     = contentAnalyser2.GetBannedWordCount();

            Assert.AreEqual(1, actualCount2);
        }
        public void BannedWordCountTest(string content, int expectedCount)
        {
            var mockRepository = new Mock <IContentRepository>();

            mockRepository.Setup(x => x.GetBannedWords()).Returns(new List <string> {
                "swine", "nasty", "bad", "horrible"
            });
            mockRepository.Setup(x => x.GetContent()).Returns(content);
            var contentAnalyser = new ContentAnalyzer(mockRepository.Object);
            int actualCount     = contentAnalyser.GetBannedWordCount();

            Assert.AreEqual(expectedCount, actualCount);
        }
        public void DisableFilteringTest()
        {
            string content        = "bad weather";
            var    mockRepository = new Mock <IContentRepository>();

            mockRepository.Setup(x => x.GetBannedWords()).Returns(new List <string> {
                "bad", "horrible"
            });
            mockRepository.Setup(x => x.GetContent()).Returns(content);
            var contentAnalyser = new ContentAnalyzer(mockRepository.Object);

            Assert.AreEqual("b#d weather", contentAnalyser.GetContent());

            // After filtering is disabled.
            contentAnalyser.SetContentFilteringStatus(false);
            Assert.AreEqual(content, contentAnalyser.GetContent());
        }
Beispiel #7
0
 private static void SetupServices(IConfigurationRoot configuration)
 {
     m_FeedDownloader  = new FeedDownloader();
     m_WebScraper      = new WebScraper();
     m_ContentAnalyzer = new ContentAnalyzer(configuration["CognitiveServicesKeys:TextAnalyticsAPI"], configuration["CognitiveServicesKeys:VisionAPI"], configuration["CognitiveServicesKeys:VideoIndexerAPI"]);
 }
Beispiel #8
0
 private static void SetupServices(IConfigurationRoot configuration)
 {
     m_ContentAnalyzer = new ContentAnalyzer(configuration["CognitiveServicesKeys:TextAnalyticsAPI"], configuration["CognitiveServicesKeys:VisionAPI"], configuration["CognitiveServicesKeys:VideoIndexerAPI"], configuration["CognitiveServicesKeys:FaceAPI"]);
 }
Beispiel #9
0
 private static void SetupServices(IConfigurationRoot configuration)
 {
     m_TwitterMonitor  = new TwitterMonitor(configuration["Twitter:ConsumerKey"], configuration["Twitter:ConsumerSecret"], configuration["Twitter:AccessToken"], configuration["Twitter:AccessTokenSecret"]);
     m_WebScraper      = new WebScraper();
     m_ContentAnalyzer = new ContentAnalyzer(configuration["CognitiveServicesKeys:TextAnalyticsAPI"], configuration["CognitiveServicesKeys:VisionAPI"], configuration["CognitiveServicesKeys:VideoIndexerAPI"], configuration["CognitiveServicesKeys:FaceAPI"]);
 }