예제 #1
0
        public async Task Remap_Writes_Stream()
        {
            // arrange
            var config = GetTestConfig();
            var parser = GetTestParser().UseHeaders();
            var mapper = new CsvMapper(parser, _outStream);

            mapper.Load(config);

            // act
            await mapper.RemapAsync(',');

            // assert
            Assert.NotEqual(0, _outStream.Length);
        }
예제 #2
0
        public async Task Remap_IgnoresUnmapped()
        {
            // arrange
            var config = GetTestConfig();
            var parser = GetTestParser().UseHeaders();
            var mapper = new CsvMapper(parser, _outStream);

            mapper.Load(config);
            var outStream = new MemoryStream();

            // act
            await mapper.RemapAsync(',');

            outStream.Seek(0, SeekOrigin.Begin);
            var asText = Encoding.UTF8.GetString(outStream.ToArray());

            // assert
            Assert.DoesNotContain("bat", asText);
        }
예제 #3
0
        public async Task Remap_MutatorWasRun()
        {
            // arrange
            var config = GetTestConfig();
            var parser = GetTestParser().UseHeaders();
            var mapper = new CsvMapper(parser, _outStream);

            mapper.Load(config);

            // act
            await mapper.RemapAsync(',');


            // assert
            _outStream.Seek(0, SeekOrigin.Begin);
            var asText      = Encoding.UTF8.GetString(_outStream.ToArray());
            var lines       = asText.Split(Environment.NewLine);
            var firstRecord = lines[1];
            var fields      = firstRecord.Split(',');

            Assert.Equal("unknown", fields[0]);
        }
예제 #4
0
        public async Task Remap_Writes_TransformedFields()
        {
            // arrange
            var config = GetTestConfig();
            var parser = GetTestParser().UseHeaders();
            var mapper = new CsvMapper(parser, _outStream);

            mapper.Load(config);

            // act
            await mapper.RemapAsync(',');

            // assert
            _outStream.Seek(0, SeekOrigin.Begin);
            var asText    = Encoding.UTF8.GetString(_outStream.ToArray());
            var firstLine = asText.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries)[0];
            var fields    = firstLine.Split(',');

            Assert.Equal("foo-1", fields[0]);
            Assert.Equal("bar-1", fields[1]);
            Assert.Equal("baz-1", fields[2]);
        }