public void HandleReadFile()
        {
            const string fileName    = "FileName";
            const string fileContent = "TheContent";

            _fileHandler.ReadText = fileContent;

            FileInfo fileInfo = new FileInfo(fileName);

            _sendAndMoveHandler.HandleReadFile(fileInfo);

            Assert.IsTrue(_fileHandler.FileMoved);

            Message fileReadMessage = _fileReadNotifier.SentMessages.FirstOrDefault();

            Assert.IsNotNull(fileReadMessage);
            Assert.IsInstanceOfType(fileReadMessage, typeof(FileReadMessage));
            Assert.AreEqual(fileReadMessage.Type, nameof(FileReadMessage));

            FileReadMessage fileReadMessageCasted = (FileReadMessage)fileReadMessage;

            Assert.AreEqual(fileReadMessageCasted.FileName, fileName);

            Message fileContentMessage = _fileContentNotifier.SentMessages.FirstOrDefault();

            Assert.IsNotNull(fileContentMessage);
            Assert.IsInstanceOfType(fileContentMessage, typeof(FileContentMessage));
            Assert.AreEqual(fileContentMessage.Type, nameof(FileContentMessage));

            FileContentMessage fileContentMessageCasted = (FileContentMessage)fileContentMessage;

            Assert.AreEqual(fileContentMessageCasted.FileName, fileName);
            Assert.AreEqual(fileContentMessageCasted.Payload, fileContent);
        }
Пример #2
0
        static void Main(string[] args)
        {
            FileReaderConfigurator fileReaderConfigurator = new FileReaderConfigurator();
            FileReaderConfig       fileReaderConfig       = fileReaderConfigurator.ReadConfig();

            //_notifier = new HttpNotifier(fileReaderConfig.NotificationTarget);
            _fileReadNotifier    = new KafkaNotifier(fileReaderConfig.KafkaServerAddress, fileReaderConfig.FileReadTopicName);
            _fileContentNotifier = new KafkaNotifier(fileReaderConfig.KafkaServerAddress, fileReaderConfig.FileContentTopicName);

            IFileHandler fileHandler = new FileHandlerImplementation(fileReaderConfig.ProcessedLocation);
            IFileReader  fileReader  = new PoorMansFileReader(fileReaderConfig.InputLocation, fileHandler);

            //IReadHandler readHandler = new SendAndDeleteHandler(_fileReadNotifier);

            Console.WriteLine($"{fileReaderConfig.ProcessedLocation}");

            IReadHandler readHandler = new SendAndMoveHandler(_fileReadNotifier, _fileContentNotifier, fileHandler);

            fileReader.FileRead += (fileReadEventArgs) =>
            {
                readHandler.HandleReadFile(fileReadEventArgs.FileInfo);
            };

            fileReader.Start();
        }