Exemplo n.º 1
0
        private static void UseCustomMadeServer(string baseAddress, string outputFile, int numberOfWorkers)
        {
            var calculations = new ITextStatCalculation[]
            {
                new AlphanumericCountTextStatCalculation(),
                new NCountTextStatCalculation(),
                new ParagraphCountTextStatCalculation(),
                new SixteenOrMoreWordsSentenceTextStatCalculation()
            };
            IStatsCalculator statsCalculator = new StatsCalculator(calculations);
            IStatsPersister  statsPersister  = new StatsPersister(outputFile);
            var textStatsProcessor           = new TextStatsProcessor(statsCalculator, statsPersister);
            var textStatsProcessorHandler    = new TextStatsProcessorHandler("/", textStatsProcessor);

            IHttpListenerContextHandler[] handlers =
            {
                textStatsProcessorHandler,
                new PongHandler("/ping")
            };

            var options = new HttpServerOptions(baseAddress, handlers, numberOfWorkers);

            using (var server = new HttpServer(options))
            {
                server.Start();
                Ping(baseAddress);
                TellAndWait(baseAddress);
                server.Stop();
            }

            textStatsProcessorHandler.Complete();
        }
Exemplo n.º 2
0
        public void MustCallPersister()
        {
            IStatsCalculator calculator = new FakeStatsCalculator();
            var persister = new FakePersister();
            var processor = new TextStatsProcessor(calculator, persister);

            Task <bool> addTextAsync = processor.AddTextAsync(Input);

            processor.Complete();
            addTextAsync.Wait();

            Assert.IsTrue(persister.Executed);
        }