Esempio n. 1
0
        public async void CsvToDynamic_Execute()
        {
            var csv = "id,name\r\n1,teste1\r\n2,teste2";

            using (var ms = new MemoryStream())
            {
                using (var sw = new StreamWriter(ms))
                {
                    sw.Write(csv);
                    sw.Flush();
                    ms.Position = 0;

                    var stepMock = new Mock <Step <Stream> >();
                    stepMock
                    .Setup(_ => _.Execute())
                    .ReturnsAsync(new StepValue <Stream>(ms, null));

                    var result = (await CsvToDynamicTransformExtensions.TransformCsvToDynamic(stepMock.Object).Execute());

                    var list = result.Value.ToList();
                    list.Should().HaveCount(2);
                    var item1 = list[0];
                    var item2 = list[1];
                    ((string)item1.id).Should().Be("1");
                    ((string)item1.name).Should().Be("teste1");
                    ((string)item2.id).Should().Be("2");
                    ((string)item2.name).Should().Be("teste2");
                }
            }
        }
Esempio n. 2
0
        public async void CsvToDynamic_Collection_Execute()
        {
            var csv = "id,name\r\n1,teste1\r\n2,teste2";

            using (var ms = new MemoryStream())
            {
                using (var sw = new StreamWriter(ms))
                {
                    sw.Write(csv);
                    sw.Flush();
                    ms.Position = 0;
                    var listStepValue = new List <StepValue <Stream> >()
                    {
                        new StepValue <Stream>(ms, null)
                    };

                    var result = (await CsvToDynamicTransformExtensions.TransformCsvToDynamic(listStepValue).Execute()).ToList();

                    result.Should().HaveCount(1);
                    var list = result[0].Value.ToList();
                    list.Should().HaveCount(2);
                    var item1 = list[0];
                    var item2 = list[1];
                    ((string)item1.id).Should().Be("1");
                    ((string)item1.name).Should().Be("teste1");
                    ((string)item2.id).Should().Be("2");
                    ((string)item2.name).Should().Be("teste2");
                }
            }
        }