Esempio n. 1
0
        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();
        }
        public void StartConsuming_ValidInput_ValidOutput()
        {
            // Arrange
            string[] output = new string[]
            {
                "html code <a href=\"http://www.google1.com\">link to google</a> html code",
                "html code <a href=\"http://www.google2.com\">link to google</a> html code",
                "html code <a href=\"http://www.google3.com\">link to google</a> html code",
            };

            string firstResult = null;

            IProducerUnit producer = new MockProducerUnit(output);
            IParser<string> parser = new SyncStringToStringParser();
            List<string> results = new List<string>();
            IConsumerUnit consumer = new ConsumerUnit(parser,
                (res) => firstResult = new List<string>(res)[0]);

            // Act
            consumer.StartConsuming(producer);
            // TODO
            Thread.Sleep(2000);

            // Assert
            Assert.IsNotNull(firstResult);
        }