示例#1
0
        public void Reverser_Should_Use_The_FileWriter()
        {
            //Arrange

            var outPath = "This is a mock output path";

            var reveresedLines = new List <string>();

            var readerMock = new Mock <IFileReader>();
            var writerMock = new Mock <IFileWriter>();

            var logicMock = new Mock <IReversalLogic>();

            logicMock.Setup(x => x.Reverse(It.IsAny <List <string> >())).Returns(reveresedLines);

            var sut = new FileReverser(readerMock.Object, writerMock.Object, logicMock.Object);

            //Act

            sut.Reverse("inPath", outPath);

            //Assert

            writerMock.Verify(x => x.WriteLines(reveresedLines, outPath), Times.Once);
        }
示例#2
0
        public void Reverser_Should_Use_The_FileReader()
        {
            //Arrange

            var filePath = "This is a mock file path";

            var readerMock = new Mock <IFileReader>();
            var writerMock = new Mock <IFileWriter>();
            var logicMock  = new Mock <IReversalLogic>();

            var sut = new FileReverser(readerMock.Object, writerMock.Object, logicMock.Object);

            //Act

            sut.Reverse(filePath, "outPath");

            //Assert

            readerMock.Verify(x => x.ReadLines(filePath), Times.Once);
        }
示例#3
0
        static void Main(string[] args)
        {
            //Usually you'd set this up with DI
            var fileReverser = new FileReverser(
                new DefaultFileReader(),
                new DefaultFileWriter(),
                new ReversalLogic());

            //There error handling here is poorly designed and there is no validation
            //The focus of this exercise was not the console app

            try
            {
                Console.Write("Input path: ");
                var inPath = Console.ReadLine();

                Console.Write("Output path:");
                var outPath = Console.ReadLine();

                var outFile = fileReverser.Reverse(inPath, outPath);

                Console.WriteLine();

                Console.WriteLine($"File created: {outFile.FullName}");
                Console.WriteLine($"Contents:\n\n");

                foreach (var line in File.ReadLines(outFile.FullName))
                {
                    Console.WriteLine(line);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();
        }
示例#4
0
        public void Reverser_Should_Use_The_ReversalLogic()
        {
            //Arrange

            var lines = new List <string>();

            var readerMock = new Mock <IFileReader>();

            readerMock.Setup(x => x.ReadLines(It.IsAny <string>())).Returns(lines);

            var writerMock = new Mock <IFileWriter>();
            var logicMock  = new Mock <IReversalLogic>();

            var sut = new FileReverser(readerMock.Object, writerMock.Object, logicMock.Object);

            //Act

            sut.Reverse("inPath", "outPath");

            //Assert

            logicMock.Verify(x => x.Reverse(lines), Times.Once);
        }