Ejemplo n.º 1
0
        public void StartDropNewFileProcessFile()
        {
            var fileData = CreateTestFileIn(tempLocation);

            var resetEvent  = new AutoResetEvent(false);
            var mockHandler = new Mock <IHandleFiles>();

            using (var listener = new PollingBasedFileProcessor(endpoint, mockHandler.Object, new DefaultFileFilter()))
            {
                listener.Start();

                new FileInfo(Path.Combine(tempLocation, fileData.Filename)).MoveTo(Path.Combine(dropLocation, fileData.Filename));

                resetEvent.WaitOne(1000);
            }

            mockHandler.Verify(x => x.Notify(It.IsAny <ProcessingFile>()));
            AssertDirectoryIsEmpty(dropLocation);

            var filePaths = Directory.GetFiles(acknowledgedLocation);

            Assert.AreEqual(filePaths.Length, 1);

            var actualFile = new FileInfo(filePaths[0]);

            AssertFileMatches(fileData.Content, fileData.Filename, actualFile);
        }
        public void StartDropNewFileProcessFile()
        {
            var fileData = this.CreateTestFileIn(this.tempLocation);

            var resetEvent  = new AutoResetEvent(false);
            var mockHandler = MockRepository.GenerateMock <IHandleFiles>();

            using (var listener = new PollingBasedFileProcessor(this.endpoint, mockHandler, new DefaultFileFilter()))
            {
                listener.Start();

                new FileInfo(Path.Combine(this.tempLocation, fileData.Filename)).MoveTo(Path.Combine(this.dropLocation, fileData.Filename));

                resetEvent.WaitOne(1000);
            }

            mockHandler.AssertWasCalled(x => x.Notify(Arg <ProcessingFile> .Is.NotNull));
            this.AssertDirectoryIsEmpty(this.dropLocation);

            var filePaths = Directory.GetFiles(this.acknowledgedLocation);

            Assert.AreEqual(filePaths.Length, 1);

            var actualFile = new FileInfo(filePaths[0]);

            AssertFileMatches(fileData.Content, fileData.Filename, actualFile);
        }
Ejemplo n.º 3
0
        private void TestFilePickup(string originalFilename, string originalContent)
        {
            var resetEvent  = new AutoResetEvent(false);
            var mockHandler = new Mock <IHandleFiles>();

            using (var listener = new PollingBasedFileProcessor(endpoint, mockHandler.Object, new DefaultFileFilter()))
            {
                listener.Start();
                resetEvent.WaitOne(1000);
            }

            mockHandler.Verify(x => x.Notify(It.IsAny <ProcessingFile>()));
            AssertDirectoryIsEmpty(dropLocation);

            var filePaths = Directory.GetFiles(acknowledgedLocation);

            Assert.AreEqual(filePaths.Length, 1);

            var actualFile = new FileInfo(filePaths[0]);

            AssertFileMatches(originalContent, originalFilename, actualFile);
        }
        private void TestFilePickup(string originalFilename, string originalContent)
        {
            var resetEvent  = new AutoResetEvent(false);
            var mockHandler = MockRepository.GenerateMock <IHandleFiles>();

            using (var listener = new PollingBasedFileProcessor(this.endpoint, mockHandler, new DefaultFileFilter()))
            {
                listener.Start();
                resetEvent.WaitOne(1000);
            }

            mockHandler.AssertWasCalled(x => x.Notify(Arg <ProcessingFile> .Is.NotNull));
            this.AssertDirectoryIsEmpty(this.dropLocation);

            var filePaths = Directory.GetFiles(this.acknowledgedLocation);

            Assert.AreEqual(filePaths.Length, 1);

            var actualFile = new FileInfo(filePaths[0]);

            AssertFileMatches(originalContent, originalFilename, actualFile);
        }
        public void RegisterWithRestartMechanism(IUnityContainer container, FileProcessorEndpoint fileProcessorEndpoint)
        {
            var producerConsumerQueue = new FileProducerConsumerQueue(fileProcessorEndpoint.NumberOfConsumers,
                                                                      container.Resolve <IFileProcessResultHandler>(fileProcessorEndpoint.Name),
                                                                      container.Resolve <IFileHandler>(fileProcessorEndpoint.Name));

            var fileThroughputAlerter = new FileThroughPutAlerter(producerConsumerQueue, fileProcessorEndpoint.PollingRestartInterval);

            var fileProcessor = new PollingBasedFileProcessor(fileProcessorEndpoint,
                                                              fileThroughputAlerter,
                                                              container.Resolve <IFileFilter>(fileProcessorEndpoint.Name));

            fileThroughputAlerter.Alert += (sender, args) => fileProcessor.Restart();

            container.RegisterInstance(typeof(IHandleFiles),
                                       fileProcessorEndpoint.Name,
                                       fileThroughputAlerter);

            container.RegisterInstance(typeof(IFileProcessor),
                                       fileProcessorEndpoint.Name,
                                       fileProcessor);
        }