public void RemoveInstanceWithGlobalConnectionToController() { TECBid bid = new TECBid(); bid.Catalogs = ModelCreation.TestCatalogs(rand); TECControllerType type = bid.Catalogs.ControllerTypes.RandomElement(rand); TECController controller = new TECProvidedController(type); bid.AddController(controller); TECTypical typical = new TECTypical(); TECController typicalController = new TECProvidedController(type); typical.AddController(typicalController); bid.Systems.Add(typical); TECSystem system = typical.AddInstance(); TECController instanceController = typical.GetInstancesFromTypical(typicalController).First(); Assert.IsTrue(controller.CanConnect(instanceController)); IControllerConnection connection = controller.Connect(instanceController, instanceController.AvailableProtocols.First()); Assert.IsTrue(connection is TECNetworkConnection); typical.Instances.Remove(system); Assert.IsTrue((connection as TECNetworkConnection).Children.Count == 0); }
private static void linkSystemToCatalogs(TECSystem system, TECCatalogs catalogs) { //Should assume linking a typical system with potential instances, controllers and panels. linkScopeChildrenToCatalogs(system, catalogs); if (system is TECTypical typical) { foreach (TECSystem instance in typical.Instances) { linkSystemToCatalogs(instance, catalogs); } } foreach (TECController controller in system.Controllers) { linkControllerToCatalogs(controller, catalogs); } foreach (TECPanel panel in system.Panels) { linkPanelToCatalogs(panel, catalogs); } foreach (TECEquipment equip in system.Equipment) { linkEquipmentToCatalogs(equip, catalogs); } }
public void GetConnectablesTest() { TECSystem system = new TECSystem(); TECEquipment equipment = new TECEquipment(); system.Equipment.Add(equipment); TECSubScope first = new TECSubScope(); TECSubScope second = new TECSubScope(); equipment.SubScope.Add(first); equipment.SubScope.Add(second); TECProvidedController controller = new TECProvidedController(new TECControllerType(new TECManufacturer())); system.AddController(controller); var connectables = ConnectionHelper.GetConnectables(system, obj => true); Assert.IsTrue(connectables.Count == 3); Assert.IsTrue(connectables.Contains(first)); Assert.IsTrue(connectables.Contains(second)); Assert.IsTrue(connectables.Contains(controller)); connectables = ConnectionHelper.GetConnectables(system, obj => obj is TECSubScope); Assert.IsTrue(connectables.Count == 2); Assert.IsTrue(connectables.Contains(first)); Assert.IsTrue(connectables.Contains(second)); }
public void AddElectricalCostToSystem() { //Arrange TECAssociatedCost cost = null; foreach (TECAssociatedCost assoc in bid.Catalogs.AssociatedCosts) { if (assoc.Type == CostType.Electrical) { cost = assoc; break; } } if (cost == null) { Assert.Fail("No electrical cost in catalogs."); } TECTypical typical = new TECTypical(); bid.Systems.Add(typical); TECSystem instance = typical.AddInstance(); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); //Act typical.AssociatedCosts.Add(cost); //Assert AssertMaterialVMMatchesCostBatch(matVM, cost.CostBatch); }
public AddMiscVM(TECSystem parentSystem, TECScopeManager scopeManager) : base(scopeManager) { this.scopeManager = scopeManager; parent = parentSystem; ToAdd = new TECMisc(CostType.TEC); AddCommand = new RelayCommand(addExecute, addCanExecute); }
public AddSystemVM(TECScopeManager scopeManager) : base(scopeManager) { Quantity = 1; parent = scopeManager; toAdd = new TECSystem(); AddCommand = new RelayCommand(addExecute, addCanExecute); }
private void addExecute() { for (int x = 0; x < Quantity; x++) { if (parent is TECBid bid) { TECTypical typical = new TECTypical(toAdd, bid); bid.Systems.Add(typical); typical.AddInstance(); Added?.Invoke(typical); } else if (parent is TECTemplates) { TECSystem system = null; if (underlyingTemplate != null) { system = new TECSystem(underlyingTemplate, synchronizers: new Tuple <TemplateSynchronizer <TECEquipment>, TemplateSynchronizer <TECSubScope> >(templates.EquipmentSynchronizer, templates.SubScopeSynchronizer)); system.CopyPropertiesFromScope(ToAdd); } else { system = ToAdd; } parent.Templates.SystemTemplates.Add(system); Added?.Invoke(system); } } }
public void TemplateEquipmentRemoved() { //Arrange TECTemplates templates = new TECTemplates(); TemplateSynchronizer <TECEquipment> synchronizer = templates.EquipmentSynchronizer; TECEquipment templateEquip = new TECEquipment(); templateEquip.Name = "First Name"; templates.Templates.EquipmentTemplates.Add(templateEquip); TECSystem templateSys = new TECSystem(); templates.Templates.SystemTemplates.Add(templateSys); TECEquipment equip1 = synchronizer.NewItem(templateEquip); TECEquipment equip2 = synchronizer.NewItem(templateEquip); templateSys.Equipment.Add(equip1); templateSys.Equipment.Add(equip2); //Act templates.Templates.EquipmentTemplates.Remove(templateEquip); equip2.Name = "Second Name"; //Assert Assert.IsFalse(synchronizer.Contains(templateEquip)); Assert.IsFalse(synchronizer.Contains(equip1)); Assert.IsFalse(synchronizer.Contains(equip2)); Assert.AreEqual("First Name", equip1.Name); Assert.AreEqual("Second Name", equip2.Name); }
private CostBatch removeSystem(TECSystem system) { CostBatch deltas = new CostBatch(); foreach (TECEquipment equip in system.Equipment) { deltas += removeEquipment(equip); } foreach (TECController controller in system.Controllers) { deltas += removeController(controller); } foreach (TECPanel panel in system.Panels) { deltas += removePanel(panel); } foreach (TECMisc misc in system.MiscCosts) { deltas += (MiscSummaryVM.RemoveCost(misc)); } foreach (ICost cost in system.AssociatedCosts) { deltas += (MiscSummaryVM.RemoveCost(cost)); } return(deltas); }
public static TECSystem TestSystem(TECCatalogs catalogs, Random rand) { TECSystem sys = new TECSystem(); sys.Description = "Test System"; sys.AssignRandomSystemProperties(catalogs, rand); return(sys); }
private void setupAddRemoveMethods(TECSystem system) { deleteControllerMethod = controller => { system.RemoveController(controller); }; deletePanelMethod = panel => { system.Panels.Remove(panel); }; }
public AddInstanceVM(TECTypical typical, TECBid bid) : base(bid) { toAdd = new TECSystem(typical); parent = typical; this.bid = bid; Locations = this.bid.Locations; AddCommand = new RelayCommand(addExecute, canAdd); AddPatternCommand = new RelayCommand(addPatternExecute, canAddPattern); }
public ValveSelectionVM(TECSystem system, IEnumerable <TECValve> valveCatalog) { catalog = new List <TECValve>(valveCatalog); Valves = getValveItems(system); Results = new List <TECValve>(catalog); ReplaceValveCommand = new RelayCommand <TECValve>(replaceValveExecute, canReplaceValve); SearchCatalogCommand = new RelayCommand(searchCatalogExecute, canSearchCatalog); ResetCatalogCommand = new RelayCommand(resetCatalogExecute, canResetCatalog); }
public void DeleteDeviceUserInputNo() { //Arrange TECTemplates templatesManager = new TECTemplates(); TECScopeTemplates templates = templatesManager.Templates; TECManufacturer man = new TECManufacturer(); templatesManager.Catalogs.Add(man); TECDevice dev = new TECDevice(new List <TECConnectionType>(), new List <TECProtocol>(), man); templatesManager.Catalogs.Add(dev); TECSystem sys = new TECSystem(); templates.SystemTemplates.Add(sys); TECEquipment sysEquip = new TECEquipment(); sys.Equipment.Add(sysEquip); TECSubScope sysSS = new TECSubScope(); sysEquip.SubScope.Add(sysSS); sysSS.Devices.Add(dev); TECEquipment equip = new TECEquipment(); templates.EquipmentTemplates.Add(equip); TECSubScope equipSS = new TECSubScope(); equip.SubScope.Add(equipSS); equipSS.Devices.Add(dev); TECSubScope ss = new TECSubScope(); templates.SubScopeTemplates.Add(ss); ss.Devices.Add(dev); //Act Mock <IUserConfirmable> mockMessageBox = new Mock <IUserConfirmable>(); mockMessageBox .Setup(x => x.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButton>(), It.IsAny <MessageBoxImage>())) .Returns(MessageBoxResult.No); DeleteEndDeviceVM vm = new DeleteEndDeviceVM(dev, templatesManager); vm.messageBox = mockMessageBox.Object; vm.DeleteCommand.Execute(null); //Assert Assert.IsTrue(templatesManager.Catalogs.Devices.Contains(dev), "Device not removed from device templates properly."); Assert.IsTrue(sysSS.Devices.Contains(dev), "Device not removed from system template properly."); Assert.IsTrue(equipSS.Devices.Contains(dev), "Device not removed from equipment template properly."); Assert.IsTrue(ss.Devices.Contains(dev), "Device not removed from subscope template properly."); }
public AddControllerVM(TECSystem parentSystem, IEnumerable <TECControllerType> controllerTypes, TECScopeManager scopeManager) : base(scopeManager) { setup(controllerTypes); parent = parentSystem; isTypical = parent.IsTypical; add = controller => { parent.AddController(controller); }; }
public void RemoveEquipmentTest() { TECSystem system = new TECSystem(); TECEquipment equipment = new TECEquipment(); system.Equipment.Add(equipment); system.ProposalItems.Add(new TECProposalItem(equipment)); system.Equipment.Remove(equipment); Assert.IsTrue(system.ProposalItems.Count == 0); }
public static void AssignRandomSystemProperties(this TECSystem sys, TECCatalogs catalogs, Random rand) { sys.AssignRandomScopeProperties(catalogs, rand); rand.RepeatAction(() => sys.Equipment.Add(ModelCreation.TestEquipment(catalogs, rand)), 5); rand.RepeatAction(() => sys.AddController(ModelCreation.TestProvidedController(catalogs, rand)), 5); rand.RepeatAction(() => sys.Panels.Add(ModelCreation.TestPanel(catalogs, rand)), 5); rand.RepeatAction(() => sys.MiscCosts.Add(ModelCreation.TestMisc(catalogs, rand, CostType.TEC)), 5); rand.RepeatAction(() => sys.MiscCosts.Add(ModelCreation.TestMisc(catalogs, rand, CostType.Electrical)), 5); rand.RepeatAction(() => sys.ScopeBranches.Add(ModelCreation.TestScopeBranch(rand, 3)), 5); rand.RepeatAction(() => ModelCreation.AddSystemConnections(sys, catalogs, rand), 5); rand.RepeatAction(() => sys.Panels.RandomElement(rand).Controllers.Add(sys.Controllers.RandomElement(rand)), 2); }
public AddPanelVM(TECSystem parentSystem, IEnumerable <TECPanelType> panelTypes, TECScopeManager scopeManager) : base(scopeManager) { Quantity = 1; parent = parentSystem; add = panel => { parent.Panels.Add(panel); }; PanelTypes = new List <TECPanelType>(panelTypes); toAdd = new TECPanel(PanelTypes[0]); AddCommand = new RelayCommand(addExecute, addCanExecute); }
public void GetAllSubScopeTest() { Random rand = new Random(0); TECBid bid = ModelCreation.TestBid(rand); TECSystem system = ModelCreation.TestSystem(bid.Catalogs, rand); var allSubScope = system.GetAllSubScope(); foreach (var subScope in system.Equipment.SelectMany(e => e.SubScope)) { Assert.IsTrue(allSubScope.Contains(subScope)); } }
public void Refresh(TECSystem system) { QuantityVisibility = Visibility.Visible; if (_bid != null) { system.MiscCosts.CollectionChanged -= MiscCosts_CollectionChanged; } system.MiscCosts.CollectionChanged += MiscCosts_CollectionChanged; _system = system; sourceCollection = system.MiscCosts; populateCollections(); }
public static void ClassInitialize(TestContext TestContext) { rand = new Random(0); //Arrange expectedTemplates = ModelCreation.TestTemplates(rand); ModelCreation.AddSyncronizerItems(expectedTemplates); expectedSystem = expectedTemplates.Templates.SystemTemplates.First(); expectedEquipment = expectedTemplates.Templates.EquipmentTemplates.First(); expectedSubScope = expectedTemplates.Templates.SubScopeTemplates.First(); expectedDevice = expectedTemplates.Catalogs.Devices.First(); expectedManufacturer = expectedTemplates.Catalogs.Manufacturers.First(); expectedTag = expectedTemplates.Catalogs.Tags[0]; expectedController = (TECProvidedController)expectedTemplates.Templates.ControllerTemplates.First(sys => sys is TECProvidedController); expectedAssociatedCost = expectedTemplates.Catalogs.AssociatedCosts[0]; expectedConnectionType = expectedTemplates.Catalogs.ConnectionTypes[0]; expectedConduitType = expectedTemplates.Catalogs.ConduitTypes[0]; path = Path.GetTempFileName(); //Act DatabaseManager <TECTemplates> manager = new DatabaseManager <TECTemplates>(path); bool success = manager.New(expectedTemplates); Assert.IsTrue(success, "New method in DatabaseManager returned false."); actualTemplates = manager.Load(); if (actualTemplates.Templates.SystemTemplates.Count == 0) { string failDirectory = Path.GetTempPath() + "Estimating Tools\\"; Directory.CreateDirectory(failDirectory); string failPath = failDirectory + "SaveNewTemplatesTestFailed.tdb"; if (File.Exists(failPath)) { File.Delete(failPath); } File.Copy(path, failPath); Assert.Fail(string.Format("No systems loaded into templates. File saved at: {0}", failPath)); } actualSystem = actualTemplates.Templates.SystemTemplates.First(x => x.Guid == expectedSystem.Guid); actualEquipment = actualTemplates.Templates.EquipmentTemplates.First(x => x.Guid == expectedEquipment.Guid); actualSubScope = actualTemplates.Templates.SubScopeTemplates.First(x => x.Guid == expectedSubScope.Guid); actualDevice = actualTemplates.Catalogs.Devices.First(x => x.Guid == expectedDevice.Guid); actualManufacturer = actualTemplates.Catalogs.Manufacturers.First(x => x.Guid == expectedManufacturer.Guid); actualTag = actualTemplates.Catalogs.Tags.First(x => x.Guid == expectedTag.Guid); actualController = actualTemplates.Templates.ControllerTemplates.First(x => x.Guid == expectedController.Guid) as TECProvidedController; actualAssociatedCost = actualTemplates.Catalogs.AssociatedCosts.First(x => x.Guid == expectedAssociatedCost.Guid); actualConnectionType = actualTemplates.Catalogs.ConnectionTypes.First(x => x.Guid == expectedConnectionType.Guid); actualConduitType = actualTemplates.Catalogs.ConduitTypes.First(x => x.Guid == expectedConduitType.Guid); }
public void RemoveInstanceWithGlobalConnectionToSubScope() { TECBid bid = new TECBid(); bid.Catalogs = ModelCreation.TestCatalogs(rand); TECController controller = ModelCreation.TestProvidedController(bid.Catalogs, rand); bid.AddController(controller); TECTypical typical = new TECTypical(); TECEquipment equipment = new TECEquipment(); TECSubScope subScope = new TECSubScope(); TECDevice device = null; foreach (TECDevice item in bid.Catalogs.Devices) { foreach (TECProtocol prot in item.PossibleProtocols) { if (controller.AvailableProtocols.Contains(prot)) { device = item; break; } } if (device != null) { break; } } if (device == null) { throw new NullReferenceException("Device is Null"); } subScope.Devices.Add(device); equipment.SubScope.Add(subScope); typical.Equipment.Add(equipment); bid.Systems.Add(typical); TECSystem system = typical.AddInstance(); TECSubScope instanceSubScope = typical.GetInstancesFromTypical(subScope).First(x => x.AvailableProtocols.Any(y => y is TECProtocol && controller.AvailableProtocols.Contains(y))); IControllerConnection connection = controller.Connect(instanceSubScope, instanceSubScope.AvailableProtocols.First(y => controller.AvailableProtocols.Contains(y))); Assert.IsTrue(connection is TECNetworkConnection); typical.Instances.Remove(system); Assert.IsTrue((connection as TECNetworkConnection).Children.Count == 0); }
public ControllersPanelsVM(TECSystem system, TECScopeManager manager, bool canSelectPanel = true) : this(system, system.Controllers, system.Panels) { if (manager is TECBid) { _bid = manager as TECBid; } else { _templates = manager as TECTemplates; } PanelSelectionReadOnly = !canSelectPanel; PanelSelectionVisibility = Visibility.Visible; SelectedSystem = system; }
public static void LinkSystem(TECSystem system, Dictionary <Guid, Guid> guidDictionary) { linkSubScopeConnections(system.Controllers, system.GetAllSubScope(), guidDictionary); List <IConnectable> allChildren = new List <IConnectable>(); allChildren.AddRange(system.Controllers); allChildren.AddRange(system.GetAllSubScope()); linkNetworkConnections(system.Controllers, allChildren, guidDictionary); linkPanelsToControllers(system.Panels, system.Controllers, guidDictionary); linkProposalItmes(system.ProposalItems, system.Equipment, guidDictionary); if (system is TECTypical typical) { typical.RefreshRegistration(); } }
public void GetObjectPathTest() { //Arrange TECBid bid = ModelCreation.TestBid(rand); TECSystem sys = bid.Systems[0]; TECEquipment equip = sys.Equipment[0]; TECSubScope ss = equip.SubScope[0]; TECPoint point = ss.Points[0]; TECController bidController = bid.Controllers[0]; TECController sysController = sys.Controllers[0]; //Act List <ITECObject> bidToPointPath = bid.GetObjectPath(point); List <ITECObject> bidToBidControllerPath = bid.GetObjectPath(bidController); List <ITECObject> bidToSysControllerPath = bid.GetObjectPath(sysController); List <ITECObject> sysToControllerPath = sys.GetObjectPath(sysController); List <ITECObject> noPath = sys.GetObjectPath(bidController); //Assert //Bid to Point Path Assert.AreEqual(bid, bidToPointPath[0]); Assert.AreEqual(sys, bidToPointPath[1]); Assert.AreEqual(equip, bidToPointPath[2]); Assert.AreEqual(ss, bidToPointPath[3]); Assert.AreEqual(point, bidToPointPath[4]); Assert.AreEqual(5, bidToPointPath.Count); //Bid to Bid Controller Path Assert.AreEqual(bid, bidToBidControllerPath[0]); Assert.AreEqual(bidController, bidToBidControllerPath[1]); Assert.AreEqual(2, bidToBidControllerPath.Count); //Bid to System Controller Path Assert.AreEqual(bid, bidToSysControllerPath[0]); Assert.AreEqual(sys, bidToSysControllerPath[1]); Assert.AreEqual(sysController, bidToSysControllerPath[2]); Assert.AreEqual(3, bidToSysControllerPath.Count); //System to Controller Path Assert.AreEqual(sys, sysToControllerPath[0]); Assert.AreEqual(sysController, sysToControllerPath[1]); Assert.AreEqual(2, sysToControllerPath.Count); }
public void AddInstanceTest() { Random rand = new Random(0); TECCatalogs catalogs = ModelCreation.TestCatalogs(rand); TECTypical typical = ModelCreation.TestTypical(catalogs, rand); TECSystem system = typical.AddInstance(); Assert.AreEqual(typical.Equipment.Count, system.Equipment.Count); Assert.AreEqual(typical.ScopeBranches.Count, system.ScopeBranches.Count); Assert.AreEqual(typical.ProposalItems.Count, system.ProposalItems.Count); Assert.AreEqual(typical.Controllers.Count, system.Controllers.Count); Assert.AreEqual(typical.Panels.Count, system.Panels.Count); Assert.AreEqual(typical.MiscCosts.Count, system.MiscCosts.Count); Assert.AreEqual(typical.Controllers.Aggregate(0, (total, next) => total += next.GetAll <TECConnection>().Count), system.GetAll <TECConnection>().Count); }
public void TECSystemTest() { Random rand = new Random(0); TECBid bid = ModelCreation.TestBid(rand); TECSystem originalSystem = ModelCreation.TestSystem(bid.Catalogs, rand); var copy = new TECSystem(originalSystem); //Not fully covered Assert.AreEqual(originalSystem.Name, copy.Name); Assert.AreEqual(originalSystem.CostBatch.GetCost(CostType.TEC), copy.CostBatch.GetCost(CostType.TEC), 0.000001); Assert.AreEqual(originalSystem.CostBatch.GetCost(CostType.Electrical), copy.CostBatch.GetCost(CostType.Electrical), 0.000001); Assert.AreEqual(originalSystem.CostBatch.GetLabor(CostType.TEC), copy.CostBatch.GetLabor(CostType.TEC), 0.000001); Assert.AreEqual(originalSystem.CostBatch.GetLabor(CostType.Electrical), copy.CostBatch.GetLabor(CostType.Electrical), 0.000001); }
private static void linkLocation(TECSystem system, IEnumerable <TECLocation> locations) { linkLocation(system as TECLocated, locations); if (system is TECTypical typical) { foreach (TECSystem instance in typical.Instances) { linkLocation(instance, locations); } } foreach (TECEquipment equip in system.Equipment) { linkLocation(equip, locations); } }
public void AddInstanceSystem() { //Arrange TECTypical typical = ModelCreation.TestTypical(bid.Catalogs, rand); typical.AssignRandomScopeProperties(bid.Catalogs, rand); bid.Systems.Add(typical); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); //Act TECSystem instance = typical.AddInstance(); //Assert AssertMaterialVMMatchesCostBatch(matVM, instance.CostBatch); }
public static void LinkScopeItem(TECSystem scope, TECBid bid) { linkScopeChildrenToCatalogs(scope, bid.Catalogs); linkLocation(scope, bid.Locations); if (scope is TECTypical typical) { foreach (TECSystem instance in typical.Instances) { LinkScopeItem(instance, bid); } } foreach (TECEquipment equip in scope.Equipment) { LinkScopeItem(equip, bid); } }