Пример #1
0
        public void SaveTextTest()
        {
            string        filePath = "filepath";
            List <string> lines    = new List <string>()
            {
                "dlkfjwoeitupisposf, ", "sjdlfujrtppqepoiqq", "fccoviuoeqlkjwe"
            };

            List <string> result = TextDataAccess.SaveText(filePath, lines);

            Assert.Equal(lines, result);
        }
Пример #2
0
        public void SaveTextTest2()
        {
            string filePath = "lskdfjkdjfkdjflkdjlfkdjlskdjfpwierpweurppppppppppppppppppppppppppppppppppppppppppppppp" +
                              "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" +
                              "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo";
            List <string> lines = new List <string>()
            {
                "dlkfjwoeitupisposf, ", "sjdlfujrtppqepoiqq", "fccoviuoeqlkjwe"
            };

            Action testCode = () => { List <string> result = TextDataAccess.SaveText(filePath, lines); };
            var    ex       = Record.Exception(testCode);

            Assert.IsType <PathTooLongException>(ex);
        }
        public void SaveText_WhenCalled_ShouldExecuteWriteAllText()
        {
            FakeWriteText  mockWrite      = new FakeWriteText();
            TextDataAccess textDataAccess = new TextDataAccess(mockWrite);
            List <string>  lines          = new List <string>
            {
                "First line",
                "Second line",
                "Third line"
            };

            string filePath = $"write.txt";

            textDataAccess.SaveText(filePath, lines);

            Assert.True(mockWrite.Done);
        }
        public void SaveText_Normal()
        {
            List <string> lines = new List <string>
            {
                "Test one",
                "Test 2",
                "Test III"
            };

            string filePath = @"C:\Temp\Test.txt";
            string fileName = "Test.txt";

            var mock = new Mock <IWriteToText>();

            mock.Setup(x => x.WriteToFile(fileName, It.IsAny <List <string> >())).Verifiable();

            TextDataAccess dataAccess = new TextDataAccess();

            dataAccess.SaveText(filePath, lines, mock.Object);

            mock.Verify();
        }
        public void SaveText_ShouldThrowException()
        {
            WriteText      writeText      = new WriteText();
            TextDataAccess textDataAccess = new TextDataAccess(writeText);
            List <string>  lines          = new List <string>
            {
                "First line",
                "Second line",
                "Third line"
            };

            string filePath =
                $"This path is too long with 261     characters" +
                $"qwertyuiopasdfghjklzxcvbnm1234567890" +
                $"qwertyuiopasdfghjklzxcvbnm1234567890" +
                $"qwertyuiopasdfghjklzxcvbnm1234567890" +
                $"qwertyuiopasdfghjklzxcvbnm1234567890" +
                $"qwertyuiopasdfghjklzxcvbnm1234567890" +
                $"qwertyuiopasdfghjklzxcvbnm1234567890";

            TestDelegate testDelegate = () => textDataAccess.SaveText(filePath, lines);

            Assert.Throws <PathTooLongException>(testDelegate);
        }
        public void SaveText_InvalidPathShouldThrowException()
        {
            List <string> lines = new List <string>
            {
                "Test one",
                "Test 2",
                "Test III"
            };

            string filePath = @"C:\Temp\Testendkjnewdjnwekdjnwkendwkjendkjwnedkjwnedkjwnedkjnwekdjnfvnkjtnrtnkrnvkjernvkjwnefnwefnwjenfkjwkjervkjnrkjvnekjrvbkwjenfkjwne
			jrbfkwrfkjbekrjfbekrbfkerfkebrfberfbehrbktnbmeprnvwnvwnowirnvpwmboientoivnernvoiwrncoiwnvoierpvowpfvbeoubvbeorivnworinvowrinvoiwrnvoiwnrviowrvniowrnvoiwrvwi
			jwnrfonworivnwoirnvoienrvoineworvneoinvoienvoienvoineorivnowirmfpoqke[fompevineonburbnoeirmgpowgviwnepfomqpeofmcwpoefmotibnoeinvwimcxwmewcwerneoirvnowiernvo
			iernviernnowirnv.txt"            ;
            string fileName = "Test.txt";

            var mock = new Mock <IWriteToText>();

            mock.Setup(x => x.WriteToFile(fileName, It.IsAny <List <string> >())).Verifiable();

            TextDataAccess dataAccess = new TextDataAccess();

            Assert.Throws <PathTooLongException>(
                () => dataAccess.SaveText(filePath, lines, mock.Object));
        }
Пример #7
0
        public void TooLongPathNamesThrowException(string filePath, List <string> lines)
        {
            PathTooLongException ex = Assert.Throws <PathTooLongException>(() => _textDataAccess.SaveText(filePath, lines));

            Assert.Equal("The path needs to be less than 261 characters long.", ex.Message);
        }