Example #1
0
        public void SaveAs_Bid_Note()
        {
            //Arrange
            TECBid     bid          = new TECBid();
            TECLabeled expectedNote = new TECLabeled();

            expectedNote.Label = "test";
            bid.Notes.Add(expectedNote);

            path = Path.GetTempFileName();

            //Act
            DatabaseManager <TECBid> manager = new DatabaseManager <TECBid>(path);

            manager.New(bid);
            TECBid loadedBid = manager.Load() as TECBid;

            TECLabeled actualNote = null;

            foreach (TECLabeled note in loadedBid.Notes.Where(item => item.Guid == expectedNote.Guid))
            {
                actualNote = note;
            }

            //Assert
            Assert.AreEqual(expectedNote.Label, actualNote.Label);
        }
Example #2
0
        public static TECLabeled TestLabel(Random rand)
        {
            TECLabeled labeled = new TECLabeled();

            labeled.AssignTestLabel();
            return(labeled);
        }
Example #3
0
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value == null)
     {
         var location = new TECLabeled();
         location.Label = "None";
         return(location);
     }
     else
     {
         return(value);
     }
 }
        public void DragDropCopyTest()
        {
            TECBid bid = new TECBid();

            TECLabeled labeled = new TECLabeled();

            labeled.Label = "test";

            TECLabeled copy = labeled.DropData() as TECLabeled;

            Assert.AreNotEqual(labeled.Guid, copy.Guid);
            Assert.AreEqual(labeled.Label, copy.Label);
        }
        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 Load_Templates_Tag()
        {
            Guid   expectedGuid   = new Guid("09fd531f-94f9-48ee-8d16-00e80c1d58b9");
            string expectedString = "Test Tag";

            TECLabeled actualTag = null;

            foreach (TECTag tag in actualTemplates.Catalogs.Tags)
            {
                if (tag.Guid == expectedGuid)
                {
                    actualTag = tag;
                    break;
                }
            }

            Assert.AreEqual(expectedString, actualTag.Label, "Tag text didn't load properly.");
        }
Example #7
0
        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);
        }
 public static void AssignTestLabel(this TECLabeled labeled)
 {
     labeled.Label = labeled.Guid.ToString().Substring(0, 5);
 }