Beispiel #1
0
        public void IsEndOfData()
        {
            WriteTestValues();
            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.OpenReadOnly(Filename))
            {
                using (IWorksheetReader reader = spreadsheet.ReadWorksheet("UnitTests"))
                {
                    string[] falseAddresses = new[] { "A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3", "D1", "D2" };
                    string[] trueAddresses  = new [] { "A4", "A5", "B4", "B5", "C4", "C5", "D3", "D4", "D5" };
                    foreach (string address in falseAddresses)
                    {
                        reader.MoveTo(address);
                        Assert.That(reader.IsEndOfData(), Is.False, "EndOfData = false for {0}", address);
                    }

                    foreach (string address in trueAddresses)
                    {
                        reader.MoveTo(address);
                        Assert.That(reader.IsEndOfData(), Is.True, "EndOfData = true for {0}", address);
                    }
                }
            }
        }
Beispiel #2
0
 public void IsEndOfDataEmpty()
 {
     using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.CreateNew(Filename))
     {
         using (spreadsheet.WriteToWorksheet("UnitTests"))
         {
         }
     }
     using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.OpenReadOnly(Filename))
     {
         using (IWorksheetReader reader = spreadsheet.ReadWorksheet("UnitTests"))
         {
             Assert.That(reader.IsEndOfData(), Is.True);
         }
     }
 }
        private Item ReadFromRow(int row, IWorksheetReader reader, Item[] history, int maxDepth)
        {
            Item item = null;
            reader.MoveTo(row, 1);

            int depth = 1;
            string value = reader.Read();

            while (value == string.Empty && depth <= maxDepth)
            {
                depth++;
                value = reader.Read();
            }

            if (depth <= maxDepth)
            {
                string name = value;

                switch (depth)
                {
                    case 1:
                        {
                            item = new Enterprise(name);
                            break;
                        }
                    case 2:
                        {
                            item = new Site(name);
                            break;
                        }
                    case 3:
                        {
                            item = new Area(name);
                            break;
                        }
                    case 4:
                        {
                            item = new WorkCentre(name);
                            break;
                        }
                    default:
                        {
                            throw new InvalidOperationException("Maximum depth currently supported is 4");
                        }
                }
                history[depth] = item;
                Item parent = history[depth - 1];
                if (parent == null)
                {
                    string message = string.Format("Unable to add {0} at Level {1} as there is no parent.", item,
                                                   depth);
                    throw new InvalidOperationException(message);
                }
                parent.AddItem(item);
            }
            else
            {
                reader.MoveTo(row, 1);
                if (!reader.IsEndOfData())
                {
                    string message = string.Format("Unable to read item from row {0}", row);
                    throw new InvalidOperationException(message);
                }
            }

            return item;
        }
        private Item ReadFromRow(int row, IWorksheetReader reader, Item[] history, int maxDepth)
        {
            Item item = null;

            reader.MoveTo(row, 1);

            int    depth = 1;
            string value = reader.Read();

            while (value == string.Empty && depth <= maxDepth)
            {
                depth++;
                value = reader.Read();
            }

            if (depth <= maxDepth)
            {
                string name = value;

                switch (depth)
                {
                case 1:
                {
                    item = new Enterprise(name);
                    break;
                }

                case 2:
                {
                    item = new Site(name);
                    break;
                }

                case 3:
                {
                    item = new Area(name);
                    break;
                }

                case 4:
                {
                    item = new WorkCentre(name);
                    break;
                }

                default:
                {
                    throw new InvalidOperationException("Maximum depth currently supported is 4");
                }
                }
                history[depth] = item;
                Item parent = history[depth - 1];
                if (parent == null)
                {
                    string message = string.Format("Unable to add {0} at Level {1} as there is no parent.", item,
                                                   depth);
                    throw new InvalidOperationException(message);
                }
                parent.AddItem(item);
            }
            else
            {
                reader.MoveTo(row, 1);
                if (!reader.IsEndOfData())
                {
                    string message = string.Format("Unable to read item from row {0}", row);
                    throw new InvalidOperationException(message);
                }
            }


            return(item);
        }