Example #1
0
        public void FileDecryption_UserEntersPathToFile_DisplaysRightContent()
        {
            var MockOfConsole = new Mock <IFakeConsole>();

            MockOfConsole.Setup(m => m.ReadLine()).Returns("file");

            var MockOfFile = new Mock <FilesEncryptor.IFakeFile>();

            MockOfFile.Setup(m => m.Exists("file.txt")).Returns(true);

            var Output = new StringWriter();

            Console.SetOut(Output);

            string FileNameRequest = "Podaj nazwę pliku (lub ścieżkę względną): ";

            string MessageAboutEncodingCompleted = "Odkodowano plik!";

            string ExpectedOutput = FileNameRequest + Environment.NewLine +
                                    MessageAboutEncodingCompleted + Environment.NewLine;

            var MemoryStreamToRead  = new MemoryStream();
            var MemoryStreamToWrite = new MemoryStream();

            var Encoder = new FilesEncryptor.EncoderFile(MockOfConsole.Object, MockOfFile.Object,
                                                         MemoryStreamToRead, MemoryStreamToWrite);

            Encoder.FileDecryption();

            Assert.AreEqual(ExpectedOutput, Output.ToString());
        }
Example #2
0
        public void FileDecryption_UserProvidesPathToFileThatDoesNotYetExist_DisplaysRightContent()
        {
            var MockOfConsole = new Mock <IFakeConsole>();

            MockOfConsole.Setup(m => m.ReadLine()).Returns("file");

            var MockOfFile = new Mock <FilesEncryptor.IFakeFile>();

            MockOfFile.Setup(m => m.Exists("file.txt")).Returns(false);

            var Output = new StringWriter();

            Console.SetOut(Output);

            string FileNameRequest = "Podaj nazwę pliku (lub ścieżkę względną): ";

            string MessageThatFileDoesNotExist = "Podany plik nie istnieje! Upewnij się czy " +
                                                 "wprowadziłeś odpowiednią ścieżkę!";

            string ExpectedOutput = FileNameRequest + Environment.NewLine +
                                    MessageThatFileDoesNotExist + Environment.NewLine;

            var Encoder = new FilesEncryptor.EncoderFile(MockOfConsole.Object, MockOfFile.Object,
                                                         null, null);

            Encoder.FileDecryption();

            Assert.AreEqual(ExpectedOutput, Output.ToString());
        }
Example #3
0
        public void FileDecryption_UserEntersPathToFile_DecryptsContentsOfFile()
        {
            var MockOfConsole = new Mock <IFakeConsole>();

            MockOfConsole.Setup(m => m.ReadLine()).Returns("file");

            var MockOfFile = new Mock <FilesEncryptor.IFakeFile>();

            MockOfFile.Setup(m => m.Exists("file.txt")).Returns(true);

            string FakeFileContents = "9012345678" + Environment.NewLine +
                                      "iąaśtłhżźkć" + Environment.NewLine +
                                      "IĄTŁKĆAŚWÓ";

            byte[] FakeFileBytes       = Encoding.GetEncoding("Windows-1250").GetBytes(FakeFileContents);
            var    MemoryStreamToRead  = new MemoryStream(FakeFileBytes);
            var    MemoryStreamToWrite = new MemoryStream();

            var ExpectedDecryptedLinesSentToFile = "1234567890" + Environment.NewLine +
                                                   "aąsślłzżźcć" + Environment.NewLine +
                                                   "AĄLŁCĆSŚOÓ" + Environment.NewLine;

            var Encoder = new FilesEncryptor.EncoderFile(MockOfConsole.Object, MockOfFile.Object,
                                                         MemoryStreamToRead, MemoryStreamToWrite);

            Encoder.FileDecryption();

            string Actual = Encoding
                            .GetEncoding("Windows-1250")
                            .GetString(MemoryStreamToWrite.ToArray());

            Assert.AreEqual(ExpectedDecryptedLinesSentToFile, Actual);
        }