Exemplo n.º 1
0
        public void EnumConverterBad()
        {
            ExcelStorage provider = new ExcelStorage(typeof(SmallEnumType), 4, 2);

            provider.FileName = @"..\data\Excel\OneColumnEnumBad.xls";
            provider.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;

            SmallEnumType[] res = (SmallEnumType[])provider.ExtractRecords();

            Assert.AreEqual(9, res.Length);
            Assert.AreEqual(NetVisibility.Public, res[0].Visibility);
            Assert.AreEqual(NetVisibility.Private, res[1].Visibility);
            Assert.AreEqual(NetVisibility.Protected, res[8].Visibility);

            Assert.AreEqual(1, provider.ErrorManager.ErrorCount);
            Assert.AreEqual(8, provider.ErrorManager.Errors[0].LineNumber);
            Assert.AreEqual("BadValue", provider.ErrorManager.Errors[0].RecordString);
        }
Exemplo n.º 2
0
        public void CustomersRead()
        {
            ExcelStorage provider = new ExcelStorage(typeof(CustomersVerticalBar));

            provider.StartRow    = 3;
            provider.StartColumn = 2;

            provider.FileName = @"..\data\Excel\Customers.xls";

            long start = DateTime.Now.Ticks;

            object[] res = provider.ExtractRecords();

            TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - start);

            Console.WriteLine(ts.TotalSeconds);

            Assert.AreEqual(91, res.Length);
        }
Exemplo n.º 3
0
        public DataBucket GetData(string filename)
        {
            var dataBucket = new DataBucket();

            if (!string.IsNullOrEmpty(filename))
            {
                foreach (var sheetName in Utility.GetExcelSheetNames(filename))
                {
                    if (IsDataTable(filename, sheetName))
                    {
                        var dataProvider = new ExcelStorage(typeof(UIDataRaw));
                        dataProvider.FileName    = filename;
                        dataProvider.StartRow    = 1;
                        dataProvider.StartColumn = 1;
                        dataProvider.SheetName   = sheetName;
                        var d1 = new UIData(dataProvider.SheetName, (UIDataRaw[])dataProvider.ExtractRecords());
                        if (!dataBucket.DataTables.ContainsKey(d1.DataName.ToLower()))
                        {
                            dataBucket.DataTables.Add(d1.DataName.ToLower(), d1);
                        }
                    }
                    else
                    {
                        var dataProvider = new ExcelStorage(typeof(UIMappingValueRaw));
                        dataProvider.SheetName   = sheetName;
                        dataProvider.FileName    = filename;
                        dataProvider.StartRow    = 2;
                        dataProvider.StartColumn = 1;
                        dataBucket.DataValues.Add(dataProvider.SheetName.ToLower(), new Dictionary <string, string>());
                        var d1 = (UIMappingValueRaw[])dataProvider.ExtractRecords();
                        foreach (var uiMappingValueRaw in d1)
                        {
                            string key = uiMappingValueRaw.Key.ToLower().TrimEnd();
                            if (!dataBucket.DataValues[dataProvider.SheetName.ToLower()].ContainsKey(key))
                            {
                                dataBucket.DataValues[dataProvider.SheetName.ToLower()].Add(key, uiMappingValueRaw.Value);
                            }
                        }
                    }
                }
            }
            return(dataBucket);
        }
Exemplo n.º 4
0
        public void PortfolioHoldingExcelTest()
        {
            Console.WriteLine("Portfolio excelfile...");
            Console.WriteLine();
            string fileName = "PortfolioHolding_CLICHY_P.xlsx";

            // classe dynamique generee par un fichier xml
            ClassBuilder cd          = ClassBuilder.LoadFromXml(ROOT + "PortfolioHolding.fhw");
            Type         recordClass = cd.CreateRecordClass();

            ExcelStorage provider = new ExcelStorage(recordClass);

            provider.StartRow    = 2;
            provider.StartColumn = 1;

            provider.FileName = ROOT + fileName;

            Object[] o = provider.ExtractRecords();
            analyse(o, recordClass);

            Console.WriteLine("Data successful written !!!");
            Console.ReadLine();
        }
Exemplo n.º 5
0
        public Dictionary <string, string> GetUIMap(string filename)
        {
            var result       = new Dictionary <string, string>();
            var dataProvider = new ExcelStorage(typeof(UIMappingValueRaw));

            dataProvider.StartRow    = 2;
            dataProvider.StartColumn = 1;
            dataProvider.FileName    = filename;
            foreach (var sheetName in Utility.GetExcelSheetNames(filename))
            {
                dataProvider.SheetName = sheetName;
                var d1 = (UIMappingValueRaw[])dataProvider.ExtractRecords();
                foreach (var uiMappingValueRaw in d1)
                {
                    string key = dataProvider.SheetName.ToLower() + "|" + uiMappingValueRaw.Key.ToLower();
                    if (!result.ContainsKey(key))
                    {
                        result.Add(key, uiMappingValueRaw.Value);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 6
0
        public UITestSuite[] GetTestSuites(string filename, string filename2)
        {
            List <UITestSuite> testSuites = new List <UITestSuite>();
            var dataProvider = new ExcelStorage(typeof(UIDataRaw));

            dataProvider.FileName    = filename;
            dataProvider.StartRow    = 2;
            dataProvider.StartColumn = 1;

            var sequenceList = new List <UICommandContainer>();
            var list         = GetSequencesFromMaster(filename);
            var sequences    = GetCommandSequences(filename2, list);

            foreach (var sequence in sequences.Sequences)
            {
                sequenceList.Add(sequence.Value);
            }

            foreach (var sheetName in Utility.GetExcelSheetNames(filename))
            {
                dataProvider.SheetName = sheetName;
                var         data             = (UIDataRaw[])dataProvider.ExtractRecords();
                var         props            = data.FirstOrDefault().GetType().GetProperties();
                var         orderedSequences = new SerializableDictionary <int, UICommandContainer>();
                UITestSuite testSuite        = null;
                for (int i = 0; i < data.Length; i++)
                {
                    TestCase testCase = null;
                    for (int x = 0; x < props.Count(); x++)
                    {
                        object val = data[i].GetType().GetProperty(props[x].Name).GetValue(data[i], null);
                        if (x == 0 && val != null)
                        {
                            if (Utility.IsAllUpper(val.ToString()))
                            {
                                // add the last test case before creating new test suite and test case
                                if (testCase != null && !string.IsNullOrEmpty(testCase.GroupName))
                                {
                                    testSuite.Add(testCase.GroupName, testCase);
                                    testCase = new TestCase();
                                }

                                // add the previous test suite before creating a new one
                                if (testSuite != null)
                                {
                                    testSuites.Add(testSuite);
                                }
                                // get the suite name
                                testSuite      = new UITestSuite();
                                testSuite.Name = val.ToString();
                                break;
                            }

                            object testcaseEnabled = data[i].GetType().GetProperty(props[x + 1].Name).GetValue(data[i], null);
                            if (testcaseEnabled == null || (testcaseEnabled.ToString().ToLower() != "y" && testcaseEnabled.ToString().ToLower() != "yes"))
                            {
                                continue;                                 // this testcase is NOT enabled, so we skip processing
                            }
                            // get the testcase name
                            testCase           = new TestCase();
                            testCase.GroupName = val.ToString();
                        }
                        if (x > 1 && val != null && testCase != null)
                        {
                            int sequencePosition   = -1;
                            var sequencesPositions = val.ToString().Split(',');
                            foreach (var sPosition in sequencesPositions)
                            {
                                if (int.TryParse(sPosition, out sequencePosition))
                                {
                                    // get the ordered sequences for the test case
                                    var seq = sequenceList[x - (dataProvider.StartColumn + 1)];
                                    //testCase.CommandGroups.Sequences.Add(seq.Name,new UICommandContainer(seq.Name, seq.Commands.ToArray()));
                                    orderedSequences.Add(sequencePosition, seq);
                                }
                            }
                        }
                    }
                    // add testcase after constructed.  Skip test suites
                    if (testCase != null && !string.IsNullOrEmpty(testCase.GroupName))
                    {
                        foreach (var uiCommandContainer in orderedSequences.OrderBy(x => x.Key))
                        {
                            testCase.CommandGroups.Sequences.Add(uiCommandContainer.Value.Name + "(" + uiCommandContainer.Key.ToString() + ")", uiCommandContainer.Value);
                        }
                        orderedSequences = new SerializableDictionary <int, UICommandContainer>();
                        testSuite.Add(testCase.GroupName, testCase);
                        testCase = new TestCase();
                    }
                }
                // add the last test suite
                if (testSuite != null && testSuite.Count > 0)
                {
                    testSuites.Add(testSuite);
                }
            }
            return(testSuites.ToArray());
        }