Ejemplo n.º 1
0
        public void GivenExampleTabbed()
        {
            var expectedValidRows = new List <string>()
            {
                "Jane\tTaylor\tDoe",
                "Jose\t\tMorro"
            };
            var expectedInvalidRows = new List <string>()
            {
                "Chris\tLee"
            };
            var service = new DelimitedFileService(new ConsoleFileOptionsService(), new FileSystem(), new Factory());
            var result  = service.ProcessDelimitedFile(AppContext.BaseDirectory + "TestFiles\\example.tsv", "\t", 3);

            Assert.Equal(expectedValidRows, result.ValidRows);
            Assert.Equal(expectedInvalidRows, result.InvalidRows);
        }
Ejemplo n.º 2
0
        public void ShouldProcessExampleInput()
        {
            var expectedValidRows = new List <string>()
            {
                "Jane,Taylor,Doe",
                "Jose,,Morro"
            };
            var expectedInvalidRows = new List <string>()
            {
                "Chris,Lee"
            };
            var testFile = string.Format("First Name,Middle Name,Last Name{0}Jane,Taylor,Doe{0}Chris,Lee{0}Jose,,Morro", Environment.NewLine);

            byte[] bytes      = Encoding.UTF8.GetBytes(testFile);
            var    testStream = new StreamReader(new MemoryStream(bytes));

            var fileOptionsServiceMock = new Mock <IFileOptionsService>();

            fileOptionsServiceMock.Setup(mock => mock.GetFileOptions(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())).Returns(new FileOptionsDto
            {
                Location   = "test",
                Delimiter  = ",",
                FieldCount = 3
            });

            var fileMock = new Mock <IFile>();

            fileMock.Setup(mock => mock.OpenText(It.IsAny <string>())).Returns(testStream);

            var fileSystemMock = new Mock <IFileSystem>();

            fileSystemMock.Setup(mock => mock.File).Returns(fileMock.Object);

            var service = new DelimitedFileService(fileOptionsServiceMock.Object, fileSystemMock.Object, new Factory());
            var result  = service.ProcessDelimitedFile("test", ",", 3);

            Assert.Equal(expectedValidRows, result.ValidRows);
            Assert.Equal(expectedInvalidRows, result.InvalidRows);
        }
Ejemplo n.º 3
0
        public void ErrorOnFileNotFound()
        {
            var service = new DelimitedFileService(new ConsoleFileOptionsService(), new FileSystem(), new Factory());

            Assert.Throws <FileNotFoundException>(() => service.ProcessDelimitedFile(AppContext.BaseDirectory + "TestFiles\\notthere.csv", ",", 3));
        }