public static TECTypical CreateTestTypical(TECCatalogs catalogs) { TECTypical outScope = new TECTypical(); outScope.Tags.Add(catalogs.Tags[0]); outScope.ProposeEquipment = true; var panel = CreateTestPanel(true, catalogs); outScope.Panels.Add(panel); var equipment = CreateTestEquipment(true, catalogs); outScope.Equipment.Add(equipment); var controller = CreateTestController(true, catalogs); outScope.AddController(controller); ConnectEquipmentToController(equipment, controller); panel.Controllers.Add(controller); var scopeBranch = new TECScopeBranch(true); outScope.ScopeBranches.Add(scopeBranch); var tecMisc = CreateTestMisc(CostType.TEC, true); var elecMisc = CreateTestMisc(CostType.Electrical, true); outScope.MiscCosts.Add(tecMisc); outScope.MiscCosts.Add(elecMisc); outScope.AssociatedCosts.Add(catalogs.AssociatedCosts[0]); return(outScope); }
public void TECScopeBranchTest() { Random rand = new Random(0); TECScopeBranch ogBranch = ModelCreation.TestScopeBranch(rand, 3); TECScopeBranch branch = new TECScopeBranch(ogBranch); Assert.AreEqual(ogBranch.Label, branch.Label); Assert.AreEqual(ogBranch.Branches.Count, branch.Branches.Count); }
private void addScopBranchExecute(TECScopeBranch obj) { if (obj == null) { Bid.ScopeTree.Add(new TECScopeBranch()); } else { obj.Branches.Add(new TECScopeBranch()); } }
public static TECScopeBranch TestScopeBranch(Random rand, int maxDepth) { TECScopeBranch branch = new TECScopeBranch(); branch.AssignTestLabel(); if (maxDepth > 0) { int nextMaxDepth = rand.Next(maxDepth); if (nextMaxDepth >= maxDepth) { throw new Exception("This may cause an infinite loop."); } rand.RepeatAction(() => branch.Branches.Add(TestScopeBranch(rand, nextMaxDepth)), rand.Next(1, 5)); } return(branch); }
private static void addScopeBranch(TECScopeBranch branch, Document document, Paragraph paragraph, int tabs, string tabChar = "• ") { string scopeString = branch.Label; for (int i = 0; i < tabs; i++) { paragraph.AddTab(); } paragraph.AddFormattedText(tabChar); if (tabChar != "• ") { paragraph.AddSpace(2); } paragraph.AddFormattedText(scopeString); foreach (TECScopeBranch childBranch in branch.Branches) { paragraph = document.LastSection.AddParagraph(); addScopeBranch(childBranch, document, paragraph, (tabs + 1)); } }
public void Load_Templates_ScopeBranch() { Guid expectedGuid = new Guid("814710f1-f2dd-4ae6-9bc4-9279288e4994"); string expectedName = "System Scope Branch"; Guid childGuid = new Guid("542802f6-a7b1-4020-9be4-e58225c433a8"); TECScopeBranch actualBranch = null; foreach (TECSystem system in actualTemplates.Templates.SystemTemplates) { foreach (TECScopeBranch branch in system.ScopeBranches) { if (branch.Guid == expectedGuid) { actualBranch = branch; break; } } if (actualBranch != null) { break; } } bool foundChildBranch = false; foreach (TECScopeBranch branch in actualBranch.Branches) { if (branch.Guid == childGuid) { foundChildBranch = true; break; } } Assert.AreEqual(expectedName, actualBranch.Label, "Scope branch name didn't load properly."); Assert.IsTrue(foundChildBranch, "Child branch didn't load properly into scope branch."); }
public void Load_Templates_SystemTemplates_ScopeTree() { Guid expectedParentGuid = new Guid("814710f1-f2dd-4ae6-9bc4-9279288e4994"); string expectedParentName = "System Scope Branch"; Guid expectedChildGuid = new Guid("542802f6-a7b1-4020-9be4-e58225c433a8"); string expectedChildName = "System Child Branch"; TECScopeBranch actualParent = null; TECScopeBranch actualChild = null; foreach (TECSystem typical in actualTemplates.Templates.SystemTemplates) { foreach (TECScopeBranch branch in typical.ScopeBranches) { if (branch.Guid == expectedParentGuid) { actualParent = branch; foreach (TECScopeBranch child in branch.Branches) { if (child.Guid == expectedChildGuid) { actualChild = child; break; } } break; } } if (actualParent != null) { break; } } Assert.AreEqual(expectedParentName, actualParent.Label, "Parent scope branch name didn't load properly."); Assert.AreEqual(expectedChildName, actualChild.Label, "Child scope branch name didn't load properly."); }
public static void ClassInitialize(TestContext TestContext) { rand = new Random(0); //Arrange expectedBid = ModelCreation.TestBid(rand); expectedLabor = expectedBid.ExtraLabor; expectedParameters = expectedBid.Parameters; expectedSystem = expectedBid.Systems.First(x => x.Location != null); expectedSystem1 = expectedBid.Systems.First(x => x != expectedSystem); expectedEquipment = expectedSystem.Equipment.First(x => x.SubScope.Count > 0 && x.Location != null); expectedSubScope = expectedEquipment.SubScope.First(x => x.Location != null); expectedDevice = expectedBid.Catalogs.Devices.Where(x => x.Tags.Count > 0).First(); expectedManufacturer = expectedDevice.Manufacturer; expectedPoint = expectedSubScope.Points[0]; expectedBranch = expectedBid.ScopeTree.First(x => x.Branches.Count > 0 && x.Branches[0].Branches.Count > 0); expectedNote = expectedBid.Notes[0]; expectedExclusion = expectedBid.Exclusions[0]; expectedTag = expectedBid.Catalogs.Tags[0]; expectedController = (TECProvidedController)expectedBid.Controllers.First(item => item is TECProvidedController); path = Path.GetTempFileName(); //Act DatabaseManager <TECBid> manager = new DatabaseManager <TECBid>(path); manager.New(expectedBid); actualBid = manager.Load(); if (actualBid.Systems.Count == 0) { string failDirectory = Path.GetTempPath() + "Estimating Tools\\"; Directory.CreateDirectory(failDirectory); string failPath = failDirectory + "SaveNewBidTestFailed.edb"; if (File.Exists(failPath)) { File.Delete(failPath); } File.Copy(path, failPath); Assert.Fail(string.Format("No systems loaded into bid. File saved at: {0}", failPath)); } actualLabor = actualBid.ExtraLabor; actualBid.Parameters = actualBid.Parameters; actualSystem = actualBid.FindChild(expectedSystem.Guid) as TECTypical; actualSystem1 = actualBid.FindChild(expectedSystem1.Guid) as TECTypical; actualEquipment = actualBid.FindChild(expectedEquipment.Guid) as TECEquipment; actualSubScope = actualBid.FindChild(expectedSubScope.Guid) as TECSubScope; actualDevices = actualSubScope.Devices; actualDevice = actualBid.FindChild(expectedDevice.Guid) as TECDevice; actualPoint = actualBid.FindChild(expectedPoint.Guid) as TECPoint; actualManufacturer = actualBid.FindChild(expectedManufacturer.Guid) as TECManufacturer; actualBranch = actualBid.FindChild(expectedBranch.Guid) as TECScopeBranch; actualNote = actualBid.FindChild(expectedNote.Guid) as TECLabeled; actualExclusion = actualBid.FindChild(expectedExclusion.Guid) as TECLabeled; actualTag = actualBid.FindChild(expectedTag.Guid) as TECTag; actualController = actualBid.FindChild(expectedController.Guid) as TECProvidedController; }
public static TECBid CreateTestBid() { TECBid bid = new TECBid(); //Bid Info bid.Name = "Bid Name"; bid.BidNumber = "1701-117"; bid.DueDate = DateTime.Now; bid.Salesperson = "Mrs. Test"; bid.Estimator = "Mr. Test"; //Bid Objects bid.ExtraLabor = CreateTestExtraLabor(bid.Guid); bid.Parameters = CreateTestParameters(bid.Guid); bid.Catalogs = CreateTestCatalogs(); //Internal Notes TECInternalNote internalNote = new TECInternalNote(); internalNote.Label = "Test internal"; internalNote.Body = "Test body"; bid.InternalNotes.Add(internalNote); //Locations var cellar = new TECLocation(); cellar.Name = "Cellar"; cellar.Label = "C"; var location1 = new TECLocation(); location1.Name = "1st Floor"; location1.Label = "1"; var location2 = new TECLocation(); location2.Name = "2nd Floor"; location2.Label = "2"; var location3 = new TECLocation(); location3.Name = "3rd Floor"; location3.Label = "3"; bid.Locations.Add(cellar); bid.Locations.Add(location1); bid.Locations.Add(location2); bid.Locations.Add(location3); //Scope Branches var branch1 = new TECScopeBranch(false); branch1.Label = "Branch 1"; var branch2 = new TECScopeBranch(false); branch2.Label = "Branch 2"; var branch3 = new TECScopeBranch(false); branch3.Label = "Branch 3"; bid.ScopeTree.Add(branch1); branch1.Branches.Add(branch2); branch2.Branches.Add(branch3); //Notes var note1 = new TECLabeled(); note1.Label = "Note 1"; bid.Notes.Add(note1); //Exclusions var exclusion1 = new TECLabeled(); exclusion1.Label = "Exclusion 1"; bid.Exclusions.Add(exclusion1); //Controller TECController expectedController = new TECProvidedController(Guid.NewGuid(), bid.Catalogs.ControllerTypes[0], false); expectedController.Name = "Test Controller"; expectedController.Description = "Test description"; bid.AddController(expectedController); //Misc Cost TECMisc cost = new TECMisc(CostType.TEC, false); cost.Name = "Test Cost"; cost.Cost = 69.69; cost.Quantity = 69; bid.MiscCosts.Add(cost); //Misc wiring TECMisc wiring = new TECMisc(CostType.Electrical, false); wiring.Name = "Test Wiring"; wiring.Cost = 69.69; wiring.Quantity = 69; bid.MiscCosts.Add(wiring); //Panels TECPanel panel = new TECPanel(bid.Catalogs.PanelTypes[0], false); panel.Name = "Test Panel"; panel.Controllers.Add(expectedController); panel.AssociatedCosts.Add(bid.Catalogs.AssociatedCosts[0]); panel.AssociatedCosts.Add(bid.Catalogs.AssociatedCosts[0]); bid.Panels.Add(panel); //Systems var system1 = CreateTestTypical(bid.Catalogs); system1.Name = "System 1"; system1.Description = "Locations all the way"; system1.Location = cellar; var system2 = CreateTestTypical(bid.Catalogs); system2.Name = "System 2"; system2.Description = "Description 2"; var system3 = CreateTestTypical(bid.Catalogs); system3.Name = "System 3"; system3.Description = ""; bid.Systems.Add(system1); bid.Systems.Add(system2); bid.Systems.Add(system3); system1.AddInstance(bid); system2.AddInstance(bid); system3.AddInstance(bid); system1.AddInstance(bid); system2.AddInstance(bid); system3.AddInstance(bid); //Equipment var equipment1 = new TECEquipment(true); equipment1.Name = "Equipment 1"; equipment1.Description = "Description 1"; var equipment2 = new TECEquipment(true); equipment2.Name = "Equipment 2"; equipment2.Description = "Description 2"; system1.Equipment.Add(equipment1); system3.Equipment.Add(equipment2); //SubScope var subScope1 = new TECSubScope(true); subScope1.Name = "SubScope 1"; subScope1.Description = "Description 1"; subScope1.AssociatedCosts.Add(bid.Catalogs.AssociatedCosts[0]); subScope1.AssociatedCosts.Add(bid.Catalogs.AssociatedCosts[0]); subScope1.AssociatedCosts.Add(bid.Catalogs.AssociatedCosts[0]); var subScope2 = new TECSubScope(true); subScope2.Name = "Empty SubScope"; subScope2.Description = "Description 2"; subScope2.AssociatedCosts.Add(bid.Catalogs.AssociatedCosts[0]); equipment1.SubScope.Add(subScope1); equipment2.SubScope.Add(subScope2); //Points var point1 = new TECPoint(true); point1.Label = "Point 1"; point1.Type = IOType.AI; point1.Quantity = 2; subScope1.Points.Add(point1); var point2 = new TECPoint(true); point2.Label = "Point 2"; point2.Type = IOType.AI; point2.Quantity = 2; subScope2.Points.Add(point2); //Devices subScope1.Devices.Add(bid.Catalogs.Devices[0]); //Connections TECSubScope instanceSubScope = system1.GetInstancesFromTypical(subScope1)[0]; IControllerConnection testConnection = expectedController.Connect(instanceSubScope, (instanceSubScope as IConnectable).AvailableProtocols.First()); testConnection.ConduitType = bid.Catalogs.ConduitTypes[0]; testConnection.Length = 42; AssignAllSecondaryProperties(bid); TECTypical noLocation = new TECTypical(); noLocation.Name = "No Location"; noLocation.Equipment.Add(new TECEquipment(true)); noLocation.Equipment[0].SubScope.Add(new TECSubScope(true)); bid.Systems.Add(noLocation); return(bid); }