コード例 #1
0
ファイル: Program.cs プロジェクト: podskalicky/software-task
        static void Main(string[] args)
        {
            // Use some IoC to initialize
            IParser<string> parser = new SyncStringToStringParser();
            IConsumerUnit consumer = new ConsumerUnit(parser, Program.PrintResults);

            IInputQueue<string> inputQueue = new StringInputQueue();
            IOutputQueue<string> outputQueue = new StringOutputQueue();

            IExtractor<string, string> extractor = new AsyncStringToStringExtractor(5, new RealWebClient());
            IProducerUnit producer = new ProducerUnit(inputQueue, outputQueue, extractor);
            producer.Consumer = consumer;

            // Retrieve input from file
            string relative = "Input/InputFile.txt";
            string absolute = Path.GetFullPath(relative);
            string[] lines = File.ReadAllLines(absolute);

            // Add input to producer
            producer.AddInput(lines);

            // Start processing
            producer.StartProcessing();
            Console.WriteLine("Processing started.");

            Console.ReadLine();
        }
コード例 #2
0
        public void AddInput_ValidInput_GetSizeCorrectValue()
        {
            // Arrange
            IInputQueue<string> inputQueue = new StringInputQueue();
            IProducerUnit producer = new ProducerUnit(inputQueue, null, null);

            List<string> input = new List<string>
            {
                "https://en.wikipedia.org/wiki/Web_scraping",
                "https://en.wikipedia.org/wiki/Firefox",
                "https://en.wikipedia.org/wiki/Foxfire"
            };

            // Act
            producer.AddInput(input);
            int inputQueueSize = producer.GetInputQueueSize();

            // Assert
            Assert.AreEqual(3, inputQueueSize);
        }
コード例 #3
0
        public void StartProcessing_WebException_DoNotPropagateException()
        {
            // Arrange
            IInputQueue<string> inputQueue = new StringInputQueue();
            inputQueue.Enqueue("https://en.wikipedia.org/wiki/Web_scraping");
            inputQueue.Enqueue("https://en.wikipedia.org/wiki/Foxfire");

            IOutputQueue<string> outputQueue = new StringOutputQueue();
            // Use ExceptionWebClient to simulate Web Exception
            IExtractor<string, string> extractor = new SyncStringToStringExtractor(new ExceptionWebClient());
            IProducerUnit producer = new ProducerUnit(inputQueue, outputQueue, extractor);

            // Act
            producer.StartProcessing();

            // Assert
            int outputQueueLength = 0;
            while (outputQueue.Dequeue() != null)
            {
                outputQueueLength++;
            }
            Assert.AreEqual(0, outputQueueLength);
        }
コード例 #4
0
        public void StartProcessing_ValidInput_GetCorrectOutput()
        {
            // Arrange
            IInputQueue<string> inputQueue = new StringInputQueue();
            inputQueue.Enqueue("https://en.wikipedia.org/wiki/Web_scraping");
            inputQueue.Enqueue("https://en.wikipedia.org/wiki/Firefox");
            inputQueue.Enqueue("https://en.wikipedia.org/wiki/Foxfire");

            IOutputQueue<string> outputQueue = new StringOutputQueue();
            IExtractor<string, string> extractor = new SyncStringToStringExtractor(new MockWebClient());
            IProducerUnit producer = new ProducerUnit(inputQueue, outputQueue, extractor);

            // Act
            producer.StartProcessing();

            // Assert
            int outputQueueLength = 0;
            while (outputQueue.Dequeue() != null)
            {
                outputQueueLength++;
            }
            Assert.AreEqual(3, outputQueueLength);
        }