Пример #1
0
        public CostBatch RemoveHardware(TECHardware hardware)
        {
            bool containsItem = hardwareDictionary.ContainsKey(hardware.Guid);

            if (containsItem)
            {
                CostBatch           deltas = new CostBatch();
                HardwareSummaryItem item   = hardwareDictionary[hardware.Guid];
                CostBatch           delta  = item.Decrement();
                deltas        += delta;
                HardwareCost  += delta.GetCost(hardware.Type);
                HardwareLabor += delta.GetLabor(hardware.Type);

                if (item.Quantity < 1)
                {
                    _hardwareItems.Remove(item);
                    hardwareDictionary.Remove(hardware.Guid);
                }
                foreach (ICost cost in hardware.AssociatedCosts)
                {
                    deltas += RemoveCost(cost);
                }
                return(deltas);
            }
            else
            {
                logger.Error("Hardware not present. Cannot remove hardware. Hardware: {0}", hardware.Name);
                return(new CostBatch());
            }
        }
Пример #2
0
        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 void CostBatchTest4()
        {
            CostBatch cost = new CostBatch(10, 11, CostType.TEC);

            Assert.AreEqual(10, cost.GetCost(CostType.TEC));
            Assert.AreEqual(11, cost.GetLabor(CostType.TEC));
        }
Пример #4
0
        protected virtual CostBatch getCosts()
        {
            CostBatch costs = new CostBatch();

            this.AssociatedCosts.ForEach(item => costs += item.CostBatch);
            return(costs);
        }
Пример #5
0
        public CostBatch AddHardware(TECHardware hardware)
        {
            CostBatch deltas       = new CostBatch();
            bool      containsItem = hardwareDictionary.ContainsKey(hardware.Guid);

            if (containsItem)
            {
                HardwareSummaryItem item  = hardwareDictionary[hardware.Guid];
                CostBatch           delta = item.Increment();
                HardwareCost  += delta.GetCost(hardware.Type);
                HardwareLabor += delta.GetLabor(hardware.Type);
                deltas        += delta;
            }
            else
            {
                HardwareSummaryItem item = new HardwareSummaryItem(hardware);
                hardwareDictionary.Add(hardware.Guid, item);
                _hardwareItems.Add(item);
                HardwareCost  += item.TotalCost;
                HardwareLabor += item.TotalLabor;
                deltas        += new CostBatch(item.TotalCost, item.TotalLabor, hardware.Type);
            }
            foreach (ICost cost in hardware.AssociatedCosts)
            {
                deltas += AddCost(cost);
            }
            return(deltas);
        }
Пример #6
0
        public void CollectionChangedHandlerTest_Typical()
        {
            bool      notifiedTEC     = false;
            CostBatch notifiedCost    = null;
            int       notifiedPoint   = 0;
            bool      notifiedAdd     = false;
            bool      notifiedRemoved = false;

            NotifyMockParent parent = new NotifyMockParent();

            parent.IsTypical = true;
            parent.Collection.CollectionChanged += Collection_CollectionChanged;


            void Collection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
            {
                CollectionChangedHandlers.CollectionChangedHandler(sender, e, "Collection", parent,
                                                                   (change, prop, par, obj, item) => notifiedTEC = true,
                                                                   cost => notifiedCost    = cost,
                                                                   points => notifiedPoint = points,
                                                                   obj => notifiedAdd      = true,
                                                                   obj => notifiedRemoved  = true);
            }

            parent.Collection.Add(new NotifyMock());

            Assert.IsTrue(notifiedTEC);
            Assert.IsTrue(new CostBatch().CostsEqual(notifiedCost));
            Assert.AreEqual(0, notifiedPoint);
            Assert.IsTrue(notifiedAdd);

            parent.Collection.Remove(parent.Collection.First());

            Assert.IsTrue(notifiedRemoved);
        }
Пример #7
0
        private CostBatch removeSubScope(TECSubScope ss)
        {
            CostBatch deltas = new CostBatch();

            foreach (IEndDevice endDev in ss.Devices)
            {
                if (endDev is TECDevice dev)
                {
                    deltas += (DeviceSummaryVM.RemoveHardware(dev));
                }
                else if (endDev is TECValve valve)
                {
                    deltas += (ValveSummaryVM.RemoveValve(valve));
                }
                else
                {
                    logger.Error("IEndDevice isn't recognized. Not valve or device. " +
                                 "MaterialSummaryVM cannot add IEndDevice. IEndDevice: {0}", endDev.Name);
                }
            }
            foreach (ICost cost in ss.AssociatedCosts)
            {
                deltas += (MiscSummaryVM.RemoveCost(cost));
            }
            return(deltas);
        }
        public CostBatch AddLength(TECElectricalMaterial material, double length)
        {
            if (length < 0)
            {
                logger.Error("Length needs to be greater than 0 when adding to length summary. " +
                             "Failed to add length. Obj: {0}", material.Name);
                return(new CostBatch());
            }

            CostBatch deltas       = new CostBatch();
            bool      containsItem = lengthDictionary.ContainsKey(material.Guid);

            if (containsItem)
            {
                LengthSummaryItem item  = lengthDictionary[material.Guid];
                CostBatch         delta = item.AddLength(length);
                LengthCostTotal  += delta.GetCost(CostType.Electrical);
                LengthLaborTotal += delta.GetLabor(CostType.Electrical);
                deltas           += delta;
            }
            else
            {
                LengthSummaryItem item = new LengthSummaryItem(material, length);
                lengthDictionary.Add(material.Guid, item);
                _lengthSummaryItems.Add(item);
                LengthCostTotal  += item.TotalCost;
                LengthLaborTotal += item.TotalLabor;
                deltas           += new CostBatch(item.TotalCost, item.TotalLabor, CostType.Electrical);
            }
            foreach (ICost cost in material.RatedCosts)
            {
                deltas += addRatedCost(cost, length);
            }
            return(deltas);
        }
Пример #9
0
        public void SaveAs_Bid_Controller()
        {
            //Assert
            Assert.AreEqual(expectedController.Name, actualController.Name);
            Assert.AreEqual(expectedController.Description, actualController.Description);
            Assert.AreEqual(expectedController.Type.Guid, actualController.Type.Guid);

            foreach (TECIO expectedIO in expectedController.Type.IO)
            {
                bool ioExists = false;
                foreach (TECIO actualIO in actualController.Type.IO)
                {
                    if ((expectedIO.Type == actualIO.Type) && (expectedIO.Quantity == actualIO.Quantity))
                    {
                        ioExists = true;
                        break;
                    }
                }
                Assert.IsTrue(ioExists);
            }
            CostBatch expectedBatch = expectedController.CostBatch;
            CostBatch actualBatch   = actualController.CostBatch;

            Assert.IsTrue(compareCosts(expectedBatch, actualBatch));
        }
Пример #10
0
        public void RemoveValve()
        {
            //Arrange
            bid.Catalogs.Add(ModelCreation.TestValve(bid.Catalogs, rand));
            ChangeWatcher cw = new ChangeWatcher(bid);

            TECTypical typical = new TECTypical();

            bid.Systems.Add(typical);

            TECEquipment typEquip = new TECEquipment();

            typical.Equipment.Add(typEquip);

            TECSubScope typSS = new TECSubScope();

            typEquip.SubScope.Add(typSS);

            TECValve valve = bid.Catalogs.Valves[0];

            valve.AssignRandomScopeProperties(bid.Catalogs, rand);
            typSS.Devices.Add(valve);

            typical.AddInstance();

            MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw);

            CostBatch initial = MatVMToCostBatch(matVM);

            //Act
            typSS.Devices.Remove(valve);

            //Assert
            AssertMaterialVMMatchesCostBatch(matVM, initial - valve.CostBatch);
        }
Пример #11
0
        public void RemoveSubScope()
        {
            //Arrange

            TECTypical typical = new TECTypical();

            bid.Systems.Add(typical);

            TECEquipment typEquip = new TECEquipment();

            typical.Equipment.Add(typEquip);

            TECSubScope subScope = ModelCreation.TestSubScope(bid.Catalogs, rand);

            subScope.AssignRandomScopeProperties(bid.Catalogs, rand);
            typEquip.SubScope.Add(subScope);

            typical.AddInstance();

            MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw);

            CostBatch initial = MatVMToCostBatch(matVM);

            //Act
            typEquip.SubScope.Remove(subScope);

            //Assert
            AssertMaterialVMMatchesCostBatch(matVM, initial - subScope.CostBatch);
        }
Пример #12
0
        public void RemoveTECCost()
        {
            //Arrange
            TECAssociatedCost cost = null;
            int x = 0;

            while (cost == null)
            {
                TECAssociatedCost randomCost = bid.Catalogs.AssociatedCosts[x];
                if (randomCost.Type == CostType.TEC)
                {
                    cost = randomCost;
                }
                x++;
            }
            TECTypical system = new TECTypical();

            bid.Systems.Add(system);
            system.AddInstance();
            system.AssociatedCosts.Add(cost);

            MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw);

            CostBatch initial = MatVMToCostBatch(matVM);

            //Act
            system.AssociatedCosts.Remove(cost);

            //Assert
            AssertMaterialVMMatchesCostBatch(matVM, initial - cost.CostBatch);
        }
Пример #13
0
        public void RemoveDevice()
        {
            //Arrange
            TECTypical typical = new TECTypical();

            bid.Systems.Add(typical);

            TECEquipment typEquip = new TECEquipment();

            typical.Equipment.Add(typEquip);

            TECSubScope typSS = new TECSubScope();

            typEquip.SubScope.Add(typSS);

            TECDevice device = bid.Catalogs.Devices[0];

            device.AssignRandomScopeProperties(bid.Catalogs, rand);
            typSS.Devices.Add(device);

            typical.AddInstance();

            MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw);

            CostBatch initial = MatVMToCostBatch(matVM);

            //Act
            typSS.Devices.Remove(device);

            //Assert
            AssertMaterialVMMatchesCostBatch(matVM, initial - device.CostBatch);
        }
        protected CostBatch addAssocCost(ICost cost)
        {
            CostBatch deltas       = new CostBatch();
            bool      containsItem = assocCostDictionary.ContainsKey(cost.Guid);

            if (containsItem)
            {
                CostSummaryItem item  = assocCostDictionary[cost.Guid];
                CostBatch       delta = item.AddQuantity(1);
                AssocTECCostTotal   += delta.GetCost(CostType.TEC);
                AssocTECLaborTotal  += delta.GetLabor(CostType.TEC);
                AssocElecCostTotal  += delta.GetCost(CostType.Electrical);
                AssocElecLaborTotal += delta.GetLabor(CostType.Electrical);
                deltas += delta;
            }
            else
            {
                CostSummaryItem item = new CostSummaryItem(cost);
                assocCostDictionary.Add(cost.Guid, item);
                if (cost.Type == CostType.TEC)
                {
                    _assocTECItems.Add(item);
                    AssocTECCostTotal  += item.TotalCost;
                    AssocTECLaborTotal += item.TotalLabor;
                }
                else if (cost.Type == CostType.Electrical)
                {
                    _assocElecItems.Add(item);
                    AssocElecCostTotal  += item.TotalCost;
                    AssocElecLaborTotal += item.TotalLabor;
                }
                deltas += new CostBatch(item.TotalCost, item.TotalLabor, cost.Type);
            }
            return(deltas);
        }
        public void RemoveTest()
        {
            TECAssociatedCost aCost1 = new TECAssociatedCost(CostType.TEC);

            aCost1.Cost  = 10;
            aCost1.Labor = 11;

            TECAssociatedCost aCost2 = new TECAssociatedCost(CostType.Electrical);

            aCost2.Cost  = 12;
            aCost2.Labor = 13;

            CostBatch cost = new CostBatch(new List <ICost>()
            {
                aCost1, aCost2
            });

            cost.Remove(CostType.TEC, 10, 11);
            Assert.AreEqual(0, cost.GetCost(CostType.TEC));
            Assert.AreEqual(0, cost.GetLabor(CostType.TEC));

            cost.Remove(CostType.Electrical, 12, 13);
            Assert.AreEqual(0, cost.GetCost(CostType.Electrical));
            Assert.AreEqual(0, cost.GetLabor(CostType.Electrical));
        }
        public CostBatch RemoveValve(TECValve valve)
        {
            bool containsItem = valveDictionary.ContainsKey(valve.Guid);

            if (containsItem)
            {
                CostBatch        deltas = new CostBatch();
                ValveSummaryItem item   = valveDictionary[valve.Guid];
                CostBatch        delta  = item.Decrement();
                deltas     += delta;
                ValveCost  += delta.GetCost(valve.Type);
                ValveLabor += delta.GetLabor(valve.Type);

                if (item.Quantity < 1)
                {
                    _valveItems.Remove(item);
                    valveDictionary.Remove(valve.Guid);
                }

                deltas += RemoveActuator(valve.Actuator);
                foreach (ICost cost in valve.AssociatedCosts)
                {
                    deltas += RemoveCost(cost);
                }
                return(deltas);
            }
            else
            {
                logger.Error("Valve not present. Cannot remove valve. Valve: {0}", valve.Name);
                return(new CostBatch());
            }
        }
Пример #17
0
 protected override void notifyCostChanged(CostBatch costs)
 {
     if (!IsTypical)
     {
         base.notifyCostChanged(costs);
     }
 }
        public CostBatch AddValve(TECValve valve)
        {
            CostBatch deltas       = new CostBatch();
            bool      containsItem = valveDictionary.ContainsKey(valve.Guid);

            if (containsItem)
            {
                ValveSummaryItem item  = valveDictionary[valve.Guid];
                CostBatch        delta = item.Increment();
                ValveCost  += delta.GetCost(valve.Type);
                ValveLabor += delta.GetLabor(valve.Type);
                deltas     += delta;
            }
            else
            {
                ValveSummaryItem item = new ValveSummaryItem(valve);
                valveDictionary.Add(valve.Guid, item);
                _valveItems.Add(item);
                ValveCost  += item.TotalCost;
                ValveLabor += item.TotalLabor;
                deltas     += new CostBatch(item.TotalCost, item.TotalLabor, valve.Type);
            }

            deltas += AddActuator(valve.Actuator);
            foreach (ICost cost in valve.AssociatedCosts)
            {
                deltas += AddCost(cost);
            }
            return(deltas);
        }
        public void CostBatchTest3()
        {
            TECAssociatedCost aCost1 = new TECAssociatedCost(CostType.TEC);

            aCost1.Cost  = 10;
            aCost1.Labor = 11;

            TECAssociatedCost aCost2 = new TECAssociatedCost(CostType.TEC);

            aCost2.Cost  = 10;
            aCost2.Labor = 11;

            TECAssociatedCost aCost3 = new TECAssociatedCost(CostType.Electrical);

            aCost3.Cost  = 10;
            aCost3.Labor = 11;

            CostBatch ogCost = new CostBatch(new List <ICost>()
            {
                aCost1, aCost2, aCost3
            });


            CostBatch cost = new CostBatch(ogCost);

            Assert.AreEqual(20, cost.GetCost(CostType.TEC));
            Assert.AreEqual(22, cost.GetLabor(CostType.TEC));

            Assert.AreEqual(10, cost.GetCost(CostType.Electrical));
            Assert.AreEqual(11, cost.GetLabor(CostType.Electrical));
        }
Пример #20
0
        private static CostBatch MatVMToCostBatch(MaterialSummaryVM vm)
        {
            CostBatch cb = new CostBatch();

            cb.Add(CostType.TEC, vm.TotalTECCost, vm.TotalTECLabor);
            cb.Add(CostType.Electrical, vm.TotalElecCost, vm.TotalElecLabor);
            return(cb);
        }
Пример #21
0
        protected override CostBatch getCosts()
        {
            CostBatch costs = base.getCosts();

            foreach (TECSubScope subScope in SubScope)
            {
                costs += subScope.CostBatch;
            }
            return(costs);
        }
        public CostBatch RemoveRun(TECElectricalMaterial material, double length)
        {
            CostBatch deltas = RemoveLength(material, length);

            foreach (ICost cost in material.AssociatedCosts)
            {
                deltas += removeAssocCost(cost);
            }
            return(deltas);
        }
        public void GetLaborTest()
        {
            CostBatch cost = new CostBatch(0, 11, CostType.TEC);

            Assert.AreEqual(11, cost.GetLabor(CostType.TEC));

            cost = new CostBatch(0, 11, CostType.Electrical);

            Assert.AreEqual(11, cost.GetLabor(CostType.Electrical));
        }
Пример #24
0
        protected override CostBatch getCosts()
        {
            CostBatch costs = new CostBatch();

            foreach (TECSystem instance in Instances)
            {
                costs += instance.CostBatch;
            }
            return(costs);
        }
        public void CostBatchTest()
        {
            CostBatch cost = new CostBatch();

            foreach (CostType item in Enum.GetValues(typeof(CostType)))
            {
                Assert.AreEqual(0, cost.GetCost(item));
                Assert.AreEqual(0, cost.GetLabor(item));
            }
        }
        public CostBatch GetCosts(double length, bool isPlenum)
        {
            CostBatch outCosts = base.GetCosts(length);

            if (isPlenum)
            {
                outCosts.Add(CostType.Electrical, (length * PlenumCost), (length * PlenumLabor));
            }
            return(outCosts);
        }
        public void GetCostTest()
        {
            CostBatch cost = new CostBatch(10, 0, CostType.TEC);

            Assert.AreEqual(10, cost.GetCost(CostType.TEC));

            cost = new CostBatch(10, 0, CostType.Electrical);

            Assert.AreEqual(10, cost.GetCost(CostType.Electrical));
        }
Пример #28
0
        private void addCost(CostBatch costsToAdd)
        {
            allCosts += costsToAdd;

            raiseMaterial();
            raiseTECLabor();

            raiseElectricalMaterial();
            raiseElectricalLabor();
        }
Пример #29
0
        private CostBatch removePanel(TECPanel panel)
        {
            CostBatch deltas = new CostBatch();

            deltas += (PanelSummaryVM.RemoveHardware(panel.Type));
            foreach (ICost cost in panel.AssociatedCosts)
            {
                deltas += (PanelSummaryVM.RemoveCost(cost));
            }
            return(deltas);
        }
Пример #30
0
 private static void AssertMaterialVMMatchesCostBatch(MaterialSummaryVM vm, CostBatch cb)
 {
     Assert.AreEqual(vm.TotalTECCost, cb.GetCost(CostType.TEC),
                     GeneralTestingUtilities.DELTA, "Total tec cost didn't update properly.");
     Assert.AreEqual(vm.TotalTECLabor, cb.GetLabor(CostType.TEC),
                     GeneralTestingUtilities.DELTA, "Total tec labor didn't update properly.");
     Assert.AreEqual(vm.TotalElecCost, cb.GetCost(CostType.Electrical),
                     GeneralTestingUtilities.DELTA, "Total elec cost didn't update properly.");
     Assert.AreEqual(vm.TotalElecLabor, cb.GetLabor(CostType.Electrical),
                     GeneralTestingUtilities.DELTA, "Total elec labor didn't update properly.");
 }