コード例 #1
0
        public void Can_write_To_File_with_Path_from_Configuration()
        {
            //Arrange
            var mockIlloger = new Mock <ILogger <IPublisher> >();
            var mockOptions = new Mock <IOptions <WordLadderOptions> >();


            var _newFilePath      = Path.Combine("./Data", Guid.NewGuid() + ".txt");
            var _path             = Path.GetFullPath(_newFilePath);
            WordLadderOptions wOp = new WordLadderOptions()
            {
                TypeOfSearch       = JobPayloadCommand.SearchType.BREATH_FIRST,
                ResultsDefaultPath = _path
            };

            mockOptions.Setup(e => e.Value).Returns(wOp);

            var _publisher            = new FileSystemTextPublisher(mockIlloger.Object, mockOptions.Object);
            JobPayloadCommand payload = new JobPayloadCommand();

            //Act
            _publisher.Publish("This is a test", payload);
            //Assert
            var _exist = File.Exists(_path);

            File.Delete(_path);
            Assert.True(_exist);
        }
コード例 #2
0
        public void Can_write_To_txt_file_from_string()
        {
            //Arrange
            var mockIlloger = new Mock <ILogger <IPublisher> >();
            var mockOptions = new Mock <IOptions <WordLadderOptions> >();


            var _newFilePath      = Path.Combine("./Data", Guid.NewGuid() + ".txt");
            var _path             = Path.GetFullPath(_newFilePath);
            WordLadderOptions wOp = new WordLadderOptions()
            {
                TypeOfSearch       = JobPayloadCommand.SearchType.BREATH_FIRST,
                ResultsDefaultPath = _path
            };

            mockOptions.Setup(e => e.Value).Returns(wOp);

            var _publisher            = new FileSystemTextPublisher(mockIlloger.Object, mockOptions.Object);
            JobPayloadCommand payload = new JobPayloadCommand();
            //Act
            var _txt = "This is a test.";

            _publisher.Publish(_txt, payload);
            //Assert
            var fromFile = File.ReadAllText(_path);

            File.Delete(_path);
            Assert.Equal(fromFile, _txt);
        }
コード例 #3
0
        public void Can_write_To_txt_file_from_ProcessingResult()
        {
            //Arrange
            var mockIlloger = new Mock <ILogger <IPublisher> >();
            var mockOptions = new Mock <IOptions <WordLadderOptions> >();


            var _newFilePath      = Path.Combine("./Data", Guid.NewGuid() + ".txt");
            var _path             = Path.GetFullPath(_newFilePath);
            WordLadderOptions wOp = new WordLadderOptions()
            {
                TypeOfSearch       = JobPayloadCommand.SearchType.BREATH_FIRST,
                ResultsDefaultPath = _path
            };

            mockOptions.Setup(e => e.Value).Returns(wOp);

            var _publisher            = new FileSystemTextPublisher(mockIlloger.Object, mockOptions.Object);
            JobPayloadCommand payload = new JobPayloadCommand();
            ProcessingResult  _result = new ProcessingResult();

            _result.Payload      = payload;
            _result.WasSuccefull = true;

            _result.Result.Add("Test");
            _result.Result.Add("Pest");
            _result.Result.Add("Post");
            //Act

            _publisher.Publish(_result);
            //Assert
            var fromFile = File.ReadAllLines(_path);

            File.Delete(_path);
            Assert.Equal("Post", fromFile[fromFile.Length - 1]);
            Assert.Equal("Pest", fromFile[fromFile.Length - 2]);
            Assert.Equal("Test", fromFile[fromFile.Length - 3]);
        }