示例#1
0
        private void testNetworkExecute()
        {
            TECControllerType type = new TECControllerType(bid.Catalogs.Manufacturers[0]);

            type.Name = "Controller Type";
            type.IO.Add(new TECIO(IOType.AI));

            bid.Catalogs.Add(type);

            TECProvidedController controller = new TECProvidedController(type);

            controller.Name        = "Test Server";
            controller.Description = "For testing.";
            controller.IsServer    = true;

            bid.AddController(controller);

            TECProvidedController child = new TECProvidedController(type);

            child.Name = "Child";

            bid.AddController(child);

            TECProvidedController emptyController = new TECProvidedController(type);

            emptyController.Name = "EmptyController";

            bid.AddController(emptyController);

            TECNetworkConnection connection = controller.AddNetworkConnection(bid.Catalogs.Protocols[0]);

            connection.AddChild(child);

            TECTypical   typical = new TECTypical();
            TECEquipment equip   = new TECEquipment();
            TECSubScope  ss      = new TECSubScope();

            ss.Name = "Test Subscope";
            ss.AddDevice(bid.Catalogs.Devices[0]);
            TECPoint point = new TECPoint();

            point.Type     = IOType.AI;
            point.Quantity = 1;
            ss.AddPoint(point);
            equip.SubScope.Add(ss);
            typical.Equipment.Add(equip);

            bid.Systems.Add(typical);
            typical.AddInstance();
        }
示例#2
0
        public void AddController()
        {
            //Arrange
            TECController controller = ModelCreation.TestProvidedController(bid.Catalogs, rand);

            controller.AssignRandomScopeProperties(bid.Catalogs, rand);

            MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw);

            //Act
            bid.AddController(controller);

            //Assert
            AssertMaterialVMMatchesCostBatch(matVM, controller.CostBatch);
        }
示例#3
0
        public void AddRemoveSystemInstanceWithBidConnection()
        {
            var bid = new TECBid();

            bid.Catalogs = ModelCreation.TestCatalogs(rand);
            var bidController = new TECProvidedController(bid.Catalogs.ControllerTypes.RandomElement(rand));

            bid.AddController(bidController);

            var system    = new TECTypical();
            var equipment = new TECEquipment();
            var subScope  = new TECSubScope();

            TECDevice dev = bid.Catalogs.Devices.First(x => x.HardwiredConnectionTypes.Count > 0);

            subScope.Devices.Add(dev);

            TECHardwiredProtocol hardProt = subScope.AvailableProtocols.First(x => x is TECHardwiredProtocol) as TECHardwiredProtocol;

            system.Equipment.Add(equipment);
            equipment.SubScope.Add(subScope);
            var instance         = system.AddInstance();
            var instanceSubScope = instance.GetAllSubScope().First();

            bidController.Connect(instanceSubScope, hardProt);

            Assert.AreEqual(1, bidController.ChildrenConnections.Count, "Connection not added");

            system.Instances.Remove(instance);

            Assert.AreEqual(0, bidController.ChildrenConnections.Count, "Connection not removed");
        }
示例#4
0
        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);
        }
示例#5
0
        public void AddControllerTest()
        {
            TECBid           bid        = new TECBid();
            TECFBOController controller = new TECFBOController(bid.Catalogs);

            bid.AddController(controller);

            Assert.IsTrue(bid.Controllers.Contains(controller));
            Assert.AreEqual(1, bid.Controllers.Count);
        }
        public void Bid_AddController()
        {
            TECControllerType controllerType = new TECControllerType(manufacturer);

            controllerType.Price = 100;
            TECController controller = new TECProvidedController(controllerType);

            bid.AddController(controller);

            Assert.AreEqual(100, costs.GetCost(CostType.TEC));
            Assert.AreEqual(0, costs.GetCost(CostType.Electrical));
        }
示例#7
0
        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);
        }
示例#8
0
        public void CopyControllerTest()
        {
            Random rand = new Random(0);

            TECBid bid = ModelCreation.TestBid(rand);
            TECProvidedController controller = ModelCreation.TestProvidedController(bid.Catalogs, rand);

            bid.AddController(controller);

            TECProvidedController copy = controller.CopyController(new Dictionary <Guid, Guid>()) as TECProvidedController;

            Assert.AreEqual(controller.Type, copy.Type);
            Assert.IsTrue(controller.IOModules.SequenceEqual(copy.IOModules));
            Assert.AreEqual(controller.ChildrenConnections.Count, copy.ChildrenConnections.Count);
        }
        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);
        }
示例#10
0
        public static void AddBidConnections(TECBid bid, IEnumerable <TECTypical> typicals, TECCatalogs catalogs, Random rand)
        {
            var typ    = typicals.Where(x => x.Instances.Count > 0).RandomElement(rand);
            var system = typ.Instances.RandomElement(rand);

            var hardwiredDevice = catalogs.Devices.Where(x => x.HardwiredConnectionTypes.Count > 0).RandomElement(rand) ??
                                  new TECDevice(catalogs.ConnectionTypes.RandomElements(rand, false), new List <TECProtocol>(), catalogs.Manufacturers.RandomElement(rand));

            if (!catalogs.Devices.Contains(hardwiredDevice))
            {
                catalogs.Add(hardwiredDevice);
            }
            var networkDevice = catalogs.Devices.Where(x => x.PossibleProtocols.Count > 0 && x != hardwiredDevice).RandomElement(rand) ??
                                new TECDevice(new List <TECConnectionType>(), new List <TECProtocol> {
                catalogs.Protocols.RandomElement(rand)
            }, catalogs.Manufacturers.RandomElement(rand));

            var hardwiredSubScope = new TECSubScope();

            hardwiredSubScope.Devices.Add(hardwiredDevice);
            hardwiredSubScope.AddPoint(TestPoint(rand));

            var hardwiredProtocol = hardwiredSubScope.AvailableProtocols.Where(x => x is TECHardwiredProtocol).RandomElement(rand) as TECHardwiredProtocol;

            var networkSubScope = new TECSubScope();

            networkSubScope.Devices.Add(networkDevice);
            networkSubScope.AddPoint(TestPoint(rand));

            var networkProtocol = networkSubScope.AvailableProtocols.Where(x => x is TECProtocol).RandomElement(rand) as TECProtocol;

            typ.Equipment.RandomElement(rand).SubScope.Add(hardwiredSubScope);
            typ.Equipment.RandomElement(rand).SubScope.Add(networkSubScope);

            networkSubScope   = system.GetAllSubScope().First(x => typ.GetInstancesFromTypical(networkSubScope).Contains(x));
            hardwiredSubScope = system.GetAllSubScope().First(x => typ.GetInstancesFromTypical(hardwiredSubScope).Contains(x));

            var hardwiredControllerType = catalogs.ControllerTypes.Where(x => new TECProvidedController(x).AvailableIO.Contains((hardwiredSubScope as IConnectable).HardwiredIO)).RandomElement(rand) ??
                                          new TECControllerType(catalogs.Manufacturers.RandomElement(rand));

            if (!catalogs.ControllerTypes.Contains(hardwiredControllerType))
            {
                catalogs.Add(hardwiredControllerType);
                hardwiredControllerType.IO.AddRange((hardwiredSubScope as IConnectable).HardwiredIO.ToList());
            }
            var hardwiredController = bid.Controllers.Where(x => x is TECProvidedController y && y.Type == hardwiredControllerType).RandomElement(rand) ??
                                      new TECProvidedController(hardwiredControllerType);

            if (!bid.Controllers.Contains(hardwiredController))
            {
                bid.AddController(hardwiredController);
            }

            var networkControllerType = catalogs.ControllerTypes.Where(x => new TECProvidedController(x).AvailableProtocols.Any(y => y == networkProtocol)).RandomElement(rand) ??
                                        new TECControllerType(catalogs.Manufacturers.RandomElement(rand));

            if (!catalogs.ControllerTypes.Contains(networkControllerType))
            {
                catalogs.Add(networkControllerType);
                networkControllerType.IO.Add(new TECIO(networkProtocol));
            }
            var networkController = bid.Controllers.Where(x => x is TECProvidedController y && y.Type == networkControllerType && y.AvailableProtocols.Contains(networkProtocol)).RandomElement(rand) ??
                                    new TECProvidedController(networkControllerType);

            if (!bid.Controllers.Contains(networkController))
            {
                bid.AddController(networkController);
            }

            var hardwiredConnection = hardwiredController.Connect(hardwiredSubScope, hardwiredProtocol);
            var networkConnection   = networkController.Connect(networkSubScope, networkProtocol);

            hardwiredConnection.AssignRandomConnectionProperties(catalogs, rand);
            networkConnection.AssignRandomConnectionProperties(catalogs, rand);
        }
示例#11
0
        public static TECBid TestBid(Random rand, int maxEachItem = 3)
        {
            TECBid bid = new TECBid();

            //Bid Info
            bid.Name        = "Randomized Test Bid";
            bid.BidNumber   = string.Format("{0}-{1}", rand.Next(1000, 9999), rand.Next(1000, 9999));
            bid.DueDate     = new DateTime(rand.Next(2000, 3000), rand.Next(1, 12), rand.Next(1, 28));
            bid.Salesperson = string.Format("Salesperson #{0}", rand.Next(1, 100));
            bid.Estimator   = string.Format("Estimator #{0}", rand.Next(1, 100));

            //Bid Objects
            bid.ExtraLabor = TestLabor(rand, bid);
            bid.Parameters = TestParameters(rand, bid);
            bid.Catalogs   = TestCatalogs(rand, maxEachItem);
            bid.Templates  = TestScopeTemplates(bid.Catalogs, rand);

            //Locations
            int numFloors = rand.Next(1, maxEachItem);

            for (int floor = 1; floor <= numFloors; floor++)
            {
                bid.Locations.Add(new TECLocation()
                {
                    Name  = string.Format("Level {0}", floor),
                    Label = floor.ToString(),
                });
            }

            //Scope Branches
            rand.RepeatAction(() => bid.ScopeTree.Add(TestScopeBranch(rand, maxEachItem)), maxEachItem);

            //Notes
            rand.RepeatAction(() => bid.Notes.Add(TestLabel(rand)), maxEachItem);

            //Internal Notes
            rand.RepeatAction(() => bid.InternalNotes.Add(TestInternalNote(rand)), maxEachItem);

            //Exclusions
            rand.RepeatAction(() => bid.Exclusions.Add(TestLabel(rand)), maxEachItem);

            //Misc Costs
            rand.RepeatAction(() => bid.MiscCosts.Add(TestMisc(bid.Catalogs, rand, CostType.TEC)), maxEachItem);
            rand.RepeatAction(() => bid.MiscCosts.Add(TestMisc(bid.Catalogs, rand, CostType.Electrical)), maxEachItem);

            //Controllers
            rand.RepeatAction(() => bid.AddController(TestProvidedController(bid.Catalogs, rand)), maxEachItem);
            rand.RepeatAction(() => bid.AddController(TestFBOController(bid.Catalogs, rand)), maxEachItem);

            //Panels
            rand.RepeatAction(() => bid.Panels.Add(TestPanel(bid.Catalogs, rand)), maxEachItem);

            //Systems
            rand.RepeatAction(() => bid.Systems.Add(TestTypical(bid.Catalogs, rand)), maxEachItem);
            foreach (TECTypical typ in bid.Systems)
            {
                rand.RepeatAction(() => typ.AddInstance(), maxEachItem);
            }

            //Connections
            rand.RepeatAction(() => AddBidConnections(bid, bid.Systems, bid.Catalogs, rand), 5);


            //Assign Locations
            foreach (TECController controller in bid.Controllers)
            {
                setLocation(controller, rand);
            }
            foreach (TECPanel panel in bid.Panels)
            {
                setLocation(panel, rand);
            }
            foreach (TECTypical typ in bid.Systems)
            {
                setLocation(typ, rand);
            }

            void setLocation(TECLocated located, Random randNum)
            {
                //if (randNum.NextBool())
                //{
                //    located.Location = bid.Locations.RandomElement(randNum);
                //}
                located.Location = bid.Locations.RandomElement(randNum);
                foreach (TECLocated child in located.GetDirectChildren().Where(x => x is TECLocated))
                {
                    setLocation(child, randNum);
                }
            }

            return(bid);
        }