Ejemplo n.º 1
0
 public void ConstructorWithName()
 {
     Site site = new Site("Site 4");
     Assert.That(site.Name, Is.EqualTo("Site 4"));
     Assert.That(site.id, Is.Null);
     Assert.That(site.Area, Is.InstanceOf<AreaCollection>());
 }
Ejemplo n.º 2
0
 public void Default()
 {
     Site site = new Site();
     Assert.That(site.name, Is.EqualTo("Site 1"));
     Assert.That(site.id, Is.Null);
     Assert.That(site.Area, Is.Empty);
 }
Ejemplo n.º 3
0
        public void TestToString()
        {
            Site site = new Site("My Site");
            Assert.That(site.ToString(), Is.EqualTo("Site 'My Site'"));

            site.Area.AddArea("Area 1");
            Assert.That(site.ToString(), Is.EqualTo("Site 'My Site'"));
        }
        public void AddArea()
        {
            Site site = new Site("Site 1");
            Area area = site.Area.AddArea("Area 1");

            Assert.That(area, Is.Not.Null);
            Assert.That(site.Area, Contains.Item(area));
            Assert.That(area.FullName, Is.EqualTo("Site 1.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;
        }
Ejemplo n.º 6
0
        public void AddItemArea()
        {
            Site site = new Site("Site 1");
            site.AddItem(new Area("Area 1"));

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

            site.AddItem(new Area("Area 2"));

            Assert.That(site.Area.Count, Is.EqualTo(2));
            Assert.That(site.Area[1].Name, Is.EqualTo("Area 2"));
        }
        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));
        }
        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;
        }
Ejemplo n.º 9
0
        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"));
        }
Ejemplo n.º 10
0
 public void ItemCollection()
 {
     Site site = new Site();
     Assert.That(site.Area, Is.InstanceOf<AreaCollection>());
 }
Ejemplo n.º 11
0
 public void AddItemWorkCentre()
 {
     Site site = new Site("Site 1");
     Assert.Throws<ArgumentException>(() => site.AddItem(new WorkCentre("Work Centre 1")));
 }
Ejemplo n.º 12
0
 public void AddItemNull()
 {
     Site site = new Site("Site 1");
     Assert.Throws<ArgumentNullException>(() => site.AddItem(null));
 }
Ejemplo n.º 13
0
 public void AddItemEnterprise()
 {
     Site site = new Site("Site 1");
     Assert.Throws<ArgumentException>(() => site.AddItem(new Enterprise("My Enterprise")));
 }