コード例 #1
0
        public void ConstructorWithName()
        {
            WorkCentre workCentre = new WorkCentre("WorkCentre A");

            Assert.That(workCentre.Name, Is.EqualTo("WorkCentre A"));
            Assert.That(workCentre.id, Is.Null);
        }
コード例 #2
0
        public void Default()
        {
            WorkCentre workCentre = new WorkCentre();

            Assert.That(workCentre.Name, Is.EqualTo("WorkCentre 1"));
            Assert.That(workCentre.id, Is.Null);
        }
コード例 #3
0
        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"));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        public override void AddItem(Item item)
        {
            ArgumentCheck.IsNotNull(item);

            Area       area = item as Area;
            WorkCentre wc   = item as WorkCentre;

            if (area == null && wc == null)
            {
                string message = string.Format("Unable to add {0} to Area.", item);
                throw new ArgumentException(message);
            }
            if (area != null)
            {
                Area1.Add(area);
            }

            if (wc != null)
            {
                WorkCentre.Add(wc);
            }
        }
コード例 #7
0
        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;
        }
コード例 #8
0
        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;
        }
コード例 #9
0
        public void TestToString()
        {
            WorkCentre wc = new WorkCentre("My Work Centre");

            Assert.That(wc.ToString(), Is.EqualTo("WorkCentre 'My Work Centre'"));
        }
コード例 #10
0
        public void AddItemWorkCentre()
        {
            WorkCentre workCentre = new WorkCentre("Work Centre");

            Assert.Throws <ArgumentException>(() => workCentre.AddItem(new WorkCentre("My Work Centre")));
        }
コード例 #11
0
        public void AddItemNull()
        {
            WorkCentre workCentre = new WorkCentre("Work Centre");

            Assert.Throws <ArgumentNullException>(() => workCentre.AddItem(null));
        }
コード例 #12
0
 public void WorkCentreGetDescendants()
 {
     WorkCentre workCentre = new WorkCentre();
     Assert.That(workCentre.GetDescendants(), Is.Empty);
 }