예제 #1
0
        public async Task <IEnumerable <TestCase> > GetTestCasesDataFromExcel(string filePath)
        {
            var excelMapper = new ExcelMapper();
            var excelData   = await excelMapper.FetchAsync <TestCase>(filePath).ConfigureAwait(false);

            var testCasesData = new List <TestCase>();

            excelData.ToList().ForEach(x =>
            {
                var testStepData = this.BuildTestStep(x);
                if (!string.IsNullOrWhiteSpace(x.TestName))
                {
                    x.Steps = new List <TestStep>
                    {
                        testStepData
                    };

                    x.AttachmentReferences = new List <AttachmentReference>();
                    testCasesData.Add(x);
                }
                else
                {
                    testCasesData.Last().Steps.Add(testStepData);
                }
            });

            return(testCasesData);
        }
예제 #2
0
        public async Task SaveAsyncTest()
        {
            var products = new List <Product>
            {
                new Product {
                    Name = "Nudossi", NumberInStock = 60, Price = 1.99m, Value = "C2*D2"
                },
                new Product {
                    Name = "Halloren", NumberInStock = 33, Price = 2.99m, Value = "C3*D3"
                },
                new Product {
                    Name = "Filinchen", NumberInStock = 100, Price = 0.99m, Value = "C4*D4"
                },
            };

            var file = "productssave.xlsx";

            await new ExcelMapper().SaveAsync(file, products, "Products");
            var productsFetched = new ExcelMapper(file).Fetch <Product>().ToList();

            CollectionAssert.AreEqual(products, productsFetched);

            await new ExcelMapper().SaveAsync(file, products);
            productsFetched = new ExcelMapper(file).Fetch <Product>().ToList();
            CollectionAssert.AreEqual(products, productsFetched);

            var fs = File.OpenWrite(file);

            await new ExcelMapper().SaveAsync(fs, products, "Products");
            fs.Close();
            productsFetched = new ExcelMapper(file).Fetch <Product>().ToList();
            CollectionAssert.AreEqual(products, productsFetched);

            fs = File.OpenWrite(file);
            await new ExcelMapper().SaveAsync(fs, products);
            fs.Close();
            productsFetched = new ExcelMapper(file).Fetch <Product>().ToList();
            CollectionAssert.AreEqual(products, productsFetched);

            var path = @"..\..\..\products.xlsx";

            var mapper = new ExcelMapper()
            {
                TrackObjects = true
            };
            var tracked = (await mapper.FetchAsync <Product>(path)).ToList();
            await mapper.SaveAsync(file, "Tabelle1");

            productsFetched = new ExcelMapper(file).Fetch <Product>().ToList();
            CollectionAssert.AreEqual(tracked, productsFetched);

            mapper = new ExcelMapper()
            {
                TrackObjects = true
            };
            tracked = (await mapper.FetchAsync <Product>(path)).ToList();
            await mapper.SaveAsync(file);

            productsFetched = new ExcelMapper(file).Fetch <Product>().ToList();
            CollectionAssert.AreEqual(tracked, productsFetched);

            mapper = new ExcelMapper()
            {
                TrackObjects = true
            };
            tracked = (await mapper.FetchAsync <Product>(path)).ToList();
            fs      = File.OpenWrite(file);
            await mapper.SaveAsync(fs, "Tabelle1");

            fs.Close();
            productsFetched = new ExcelMapper(file).Fetch <Product>().ToList();
            CollectionAssert.AreEqual(tracked, productsFetched);

            mapper = new ExcelMapper()
            {
                TrackObjects = true
            };
            tracked = (await mapper.FetchAsync <Product>(path)).ToList();
            fs      = File.OpenWrite(file);
            await mapper.SaveAsync(fs);

            fs.Close();
            productsFetched = new ExcelMapper(file).Fetch <Product>().ToList();
            CollectionAssert.AreEqual(tracked, productsFetched);
        }