public void Default() { Enterprise enterprise = new Enterprise(); Assert.That(enterprise.name, Is.EqualTo("Enterprise")); Assert.That(enterprise.id, Is.Null); Assert.That(enterprise.Site, Is.Empty); }
public void ConstructorWithName() { Enterprise enterprise = new Enterprise("My Enterprise"); Assert.That(enterprise.Name, Is.EqualTo("My Enterprise")); Assert.That(enterprise.id, Is.Null); Assert.That(enterprise.Site, Is.InstanceOf<SiteCollection>()); }
public void TestToString() { Enterprise enterprise = new Enterprise("My Enterprise"); Assert.That(enterprise.ToString(), Is.EqualTo("Enterprise 'My Enterprise'")); enterprise.Site.AddSite("Site 1"); Assert.That(enterprise.ToString(), Is.EqualTo("Enterprise 'My Enterprise'")); }
public void AddSite() { Enterprise enterprise = new Enterprise("Enterprise 1"); Site site = enterprise.Site.AddSite("Site 1"); Assert.That(site, Is.Not.Null); Assert.That(enterprise.Site, Contains.Item(site)); Assert.That(site.FullName, Is.EqualTo("Enterprise 1.Site 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; }
public void AddItemSite() { Enterprise enterprise = new Enterprise(); enterprise.AddItem(new Site("Site 1")); Assert.That(enterprise.Site.Count, Is.EqualTo(1)); Assert.That(enterprise.Site[0].Name, Is.EqualTo("Site 1")); enterprise.AddItem(new Site("Site 2")); Assert.That(enterprise.Site.Count, Is.EqualTo(2)); Assert.That(enterprise.Site[1].Name, Is.EqualTo("Site 2")); }
/// <summary> /// Adds the item. /// </summary> /// <param name="item">The item.</param> /// <exception cref="System.ArgumentException"></exception> /// <exception cref="System.InvalidOperationException">Only one Enterprise allowed.</exception> public override void AddItem(Item item) { ArgumentCheck.IsNotNull(item); Enterprise enterprise = item as Enterprise; if (enterprise == null) { string message = string.Format("Unable to add {0} to Hierarchy.", item); throw new ArgumentException(message); } if (Enterprise != null) { throw new InvalidOperationException("Only one Enterprise allowed."); } Enterprise = enterprise; }
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 ItemCollection() { Enterprise enterprise = new Enterprise(); Assert.That(enterprise.Site, Is.InstanceOf <SiteCollection>()); }
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 ItemCollection() { Enterprise enterprise = new Enterprise(); Assert.That(enterprise.Site, Is.InstanceOf<SiteCollection>()); }
public void AddItemArea() { Enterprise enterprise = new Enterprise(); Assert.Throws <ArgumentException>(() => enterprise.AddItem(new Area("My Area"))); }
public void AddItemNull() { Enterprise enterprise = new Enterprise(); Assert.Throws <ArgumentNullException>(() => enterprise.AddItem(null)); }
public void AddItemWorkCentre() { Enterprise enterprise = new Enterprise(); Assert.Throws<ArgumentException>(() => enterprise.AddItem(new WorkCentre("My Work Centre"))); }
public void AddItemNull() { Enterprise enterprise = new Enterprise(); Assert.Throws<ArgumentNullException>(() => enterprise.AddItem(null)); }
public void AddItemArea() { Enterprise enterprise = new Enterprise(); Assert.Throws<ArgumentException>(() => enterprise.AddItem(new Area("My Area"))); }
public void AddItemWorkCentre() { Enterprise enterprise = new Enterprise(); Assert.Throws <ArgumentException>(() => enterprise.AddItem(new WorkCentre("My Work Centre"))); }