public void AddItemBothAreaAndWorkCentre()
        {
            Area area = new Area("Area 1");

            Assert.That(area.GetCount(), Is.EqualTo(1));

            area.AddItem(new WorkCentre("Work Centre 1"));
            Assert.That(area.GetCount(), Is.EqualTo(2));

            Assert.That(area.WorkCentre.Count, Is.EqualTo(1));
            Assert.That(area.WorkCentre[0].Name, Is.EqualTo("Work Centre 1"));

            area.AddItem(new Area("Area 1a"));
            Assert.That(area.GetCount(), Is.EqualTo(3));

            Assert.That(area.Area1.Count, Is.EqualTo(1));
            Assert.That(area.Area1[0].Name, Is.EqualTo("Area 1a"));

            area.AddItem(new Area("Area 1b"));
            Assert.That(area.GetCount(), Is.EqualTo(4));

            Assert.That(area.Area1.Count, Is.EqualTo(2));
            Assert.That(area.Area1[1].Name, Is.EqualTo("Area 1b"));

            area.AddItem(new WorkCentre("Work Centre 2"));
            Assert.That(area.GetCount(), Is.EqualTo(5));

            Assert.That(area.WorkCentre.Count, Is.EqualTo(2));
            Assert.That(area.WorkCentre[1].Name, Is.EqualTo("Work Centre 2"));
        }
        public void AddWorkCentre()
        {
            Area area = new Area("Area 1");
            WorkCentre wc = area.WorkCentre.AddWorkCentre("WorkCentre 1");

            Assert.That(wc, Is.Not.Null);
            Assert.That(area.WorkCentre, Contains.Item(wc));
            Assert.That(wc.FullName, Is.EqualTo("Area 1.WorkCentre 1"));
        }
        public void AddItemWorkCentre()
        {
            Area area = new Area("Area 1");
            area.AddItem(new WorkCentre("Work Centre 1"));

            Assert.That(area.WorkCentre.Count, Is.EqualTo(1));
            Assert.That(area.WorkCentre[0].Name, Is.EqualTo("Work Centre 1"));

            area.AddItem(new WorkCentre("Work Centre 2"));

            Assert.That(area.WorkCentre.Count, Is.EqualTo(2));
            Assert.That(area.WorkCentre[1].Name, Is.EqualTo("Work Centre 2"));
        }
        public void AddItemArea()
        {
            Area area = new Area("Area 1");
            area.AddItem(new Area("Area 1a"));

            Assert.That(area.Area1.Count, Is.EqualTo(1));
            Assert.That(area.Area1[0].Name, Is.EqualTo("Area 1a"));

            area.AddItem(new Area("Area 1b"));

            Assert.That(area.Area1.Count, Is.EqualTo(2));
            Assert.That(area.Area1[1].Name, Is.EqualTo("Area 1b"));
        }
        public void FullNameCorrectWhenAdded()
        {
            Enterprise enterprise = new Enterprise {name = "Company"};
            ItemCollection<Area> areas = new ItemCollection<Area>(enterprise);

            Area area1 = new Area {name = "Area 1"};

            Assert.That(area1.FullName, Is.EqualTo("Area 1"));

            areas.Add(area1);

            Assert.That(areas.Count, Is.EqualTo(1));
            Assert.That(area1.FullName, Is.EqualTo("Company.Area 1"));

            areas.Remove(area1);
            Assert.That(areas.Count, Is.EqualTo(0));
            Assert.That(area1.FullName, Is.EqualTo("Area 1"));
        }
        public void SiteGetDescendants()
        {
            Site site = new Site();
            Assert.That(site.GetDescendants(), Is.Empty);

            Area area1 = new Area();
            site.Area.Add(area1);

            Assert.That(site.GetDescendants(), Is.Not.Empty);
            Assert.That(site.GetDescendants().Count, Is.EqualTo(1));
            Assert.That(site.GetDescendants()[0], Is.EqualTo(area1));

            WorkCentre wc2 = new WorkCentre { name = "WC2" };
            area1.WorkCentre.Add(wc2);

            Assert.That(site.GetDescendants(), Is.Not.Empty);
            Assert.That(site.GetDescendants().Count, Is.EqualTo(2));
            Assert.That(site.GetDescendants()[0], Is.EqualTo(area1));
            Assert.That(site.GetDescendants()[1], Is.EqualTo(wc2));
        }
        public void AreaGetDescendants()
        {
            Area area = new Area();
            Assert.That(area.GetDescendants(), Is.Empty);

            WorkCentre wc1 = new WorkCentre {name = "WC1"};
            area.WorkCentre.Add(wc1);

            Assert.That(area.GetDescendants(), Is.Not.Empty);
            Assert.That(area.GetDescendants().Count, Is.EqualTo(1));
            Assert.That(area.GetDescendants()[0], Is.EqualTo(wc1));

            WorkCentre wc2 = new WorkCentre { name = "WC2" };
            area.WorkCentre.Add(wc2);

            Assert.That(area.GetDescendants(), Is.Not.Empty);
            Assert.That(area.GetDescendants().Count, Is.EqualTo(2));
            Assert.That(area.GetDescendants()[0], Is.EqualTo(wc1));
            Assert.That(area.GetDescendants()[1], Is.EqualTo(wc2));
        }
        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;
        }
 public void Area()
 {
     Area area = new Area();
     Assert.That(area.name, Is.EqualTo("Area 1"));
     Assert.That(area.id, Is.Null);
     Assert.That(area.Area1, Is.Empty);
     Assert.That(area.WorkCentre, Is.Empty);
 }
 public void AddItemSite()
 {
     Area area = new Area("Area 1");
     Assert.Throws<ArgumentException>(() => area.AddItem(new Site("Site 2")));
 }
 public void AddItemNull()
 {
     Area area = new Area("Area 1");
     Assert.Throws<ArgumentNullException>(() => area.AddItem(null));
 }
 public void AddItemEnterprise()
 {
     Area area = new Area("Area 1");
     Assert.Throws<ArgumentException>(() => area.AddItem(new Enterprise("My Enterprise")));
 }
        public void TestToString()
        {
            Area area = new Area("My Area");
            Assert.That(area.ToString(), Is.EqualTo("Area 'My Area'"));

            area.Area1.AddArea("Area 1");
            Assert.That(area.ToString(), Is.EqualTo("Area 'My Area'"));

            area.WorkCentre.AddWorkCentre("Work Centre 1");
            Assert.That(area.ToString(), Is.EqualTo("Area 'My Area'"));
        }
 public void ItemCollection()
 {
     Area area = new Area();
     Assert.That(area.WorkCentre, Is.InstanceOf<ItemCollection<WorkCentre>>());
     Assert.That(area.Area1, Is.InstanceOf<ItemCollection<Area>>());
 }
        public void FullName()
        {
            Site site = new Site {name = "Site A"};
            Area area = new Area {name = "Area 1"};

            Assert.That(site.FullName, Is.EqualTo("Site A"));
            Assert.That(area.FullName, Is.EqualTo("Area 1"));
            site.Area.Add(area);
            Assert.That(site.FullName, Is.EqualTo("Site A"));
            Assert.That(area.FullName, Is.EqualTo("Site A.Area 1"));
        }
        private Item ReadFromRow(int row, IWorksheetReader reader, Item[] history)
        {
            Item item = null;
            reader.MoveTo(row, 1);
            string firstValue = reader.Read();
            if (firstValue != string.Empty)
            {
                int depth;
                int.TryParse(firstValue, out depth);
                string isa95Type = reader.Read();
                string isa95Class = reader.Read();

                if ((depth < 1) || (depth > 9))
                {
                    throw new InvalidOperationException("Depth must be between 1 and 9");
                }

                reader.MoveTo(row, depth + 3);
                string name = reader.Read();

                switch (isa95Type)
                {
                    case "Enterprise":
                        {
                            item = new Enterprise(name);
                            break;
                        }
                    case "Site":
                        {
                            item = new Site(name);
                            break;
                        }
                    case "Area":
                        {
                            item = new Area(name);
                            break;
                        }
                    case "WorkCentre":
                        {
                            item = new WorkCentre(name);
                            break;
                        }
                    default:
                        {
                            throw new InvalidOperationException("Invalid ISA95 type:" + isa95Type);
                        }
                }

                history[depth] = item;
                history[depth - 1].AddItem(item);
            }
            return item;
        }