public void OrganizationChartManager_GetByOrgCodeAndChartType()
        {
            const int        testOrgCodeID     = 15;
            int              newOrgChartID     = -1;
            int              primaryUserID     = 1;
            enumOrgChartType selectedChartType = enumOrgChartType.SingleOrg;

            try
            {
                OC.OrganizationChart chart = OC.OrganizationChartManager.Instance.GetByOrgCodeAndChartType(testOrgCodeID, selectedChartType);

                if (chart.OrganizationChartID == -1)
                {
                    newOrgChartID = CreateOrgChartNew("OrganizationChartManager_GetByOrgCodeAndChartType", testOrgCodeID, selectedChartType, primaryUserID);
                }
                else
                {
                    newOrgChartID = chart.OrganizationChartID;
                }

                chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);

                Assert.IsNotNull(chart, "Organization Chart is null");
                Assert.IsTrue(chart.OrganizationChartID == newOrgChartID, "Organization Chart not found");
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DeleteChart(newOrgChartID);
            }
        }
        public void OrganizationChartManager_CreateOrganizationChart_FromPublished()
        {
            const int primaryUserID = 1;

            OC.OrganizationChart newChart = new OC.OrganizationChart()
            {
                OrganizationChartTypeID = enumOrgChartType.SingleOrg,
                OrgCode = new OrganizationCode()
                {
                    OrganizationCodeID = 1357
                },
                CreatedBy = new ActionUser(primaryUserID)
            };

            int newOrgChartID = OC.OrganizationChartManager.Instance.CreateFromPublished(newChart, true);

            OC.OrganizationChart chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);

            Assert.IsNotNull(chart, "Organization Chart is null");
            Assert.IsTrue(chart.OrganizationChartID == newOrgChartID, "Organization Chart not found");

            // now delete it -- we don't need it anymore
            OC.OrganizationChartManager.Instance.Delete(newOrgChartID);

            // now try to find it one last time
            OC.OrganizationChart chartFinalCheck = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);
            Assert.IsNotNull(chartFinalCheck, "Organization Chart was not Deleted");
            Assert.IsTrue(chartFinalCheck.OrganizationChartID == -1);
        }
        public void OrganizationChartManager_DeleteOrganizationChart_SingleSet()
        {
            int newOrgChartID = 10073;

            // now delete
            OC.OrganizationChartManager.Instance.Delete(newOrgChartID);

            // now try to find it again
            OC.OrganizationChart chartFinalCheck = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);
            Assert.IsNotNull(chartFinalCheck, "Organization Chart was not Deleted");
            Assert.IsTrue(chartFinalCheck.OrganizationChartID == -1);
        }
        public void OrganizationChartPositionManager_Add()
        {
            const int        testOrgCodeID     = 15;
            int              newOrgChartID     = -1;
            int              primaryUserID     = 1;
            enumOrgChartType selectedChartType = enumOrgChartType.SingleOrg;

            try
            {
                OC.OrganizationChart chart = OC.OrganizationChartManager.Instance.GetByOrgCodeAndChartType(testOrgCodeID, selectedChartType);

                if (chart.OrganizationChartID == -1)
                {
                    newOrgChartID = CreateOrgChartNew("OrganizationChartPositionManager_Add", testOrgCodeID, selectedChartType, primaryUserID);
                }
                else
                {
                    newOrgChartID = chart.OrganizationChartID;
                }

                chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);

                Assert.IsNotNull(chart, "Organization Chart is null");
                Assert.IsTrue(chart.OrganizationChartID == newOrgChartID, "Organization Chart not found");

                // now add position
                OrganizationChartPosition newPosition = new OrganizationChartPosition()
                {
                    OrganizationChartID = newOrgChartID,
                    OrganizationCodeID  = testOrgCodeID,
                    CreatedByID         = primaryUserID,
                    PositionTitle       = "Generated Position Title"
                };

                OrganizationChartPositionManager.Instance.Add(newPosition);

                // try to find position
                OrganizationChartPosition position = OrganizationChartPositionManager.Instance.GetByID(newOrgChartID, newPosition.WFPPositionID);

                Assert.IsTrue(position.WFPPositionID != -1, "Position Not Created");

                WorkforcePlanningPositionManager.Instance.Delete(position.WFPPositionID, newOrgChartID, primaryUserID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DeleteChart(newOrgChartID);
            }
        }
        public void OrganizationChartManager_UpdateRoot()
        {
            int newOrgChartID = -1;

            try
            {
                const int primaryUserID = 1;

                OC.OrganizationChart newChart = new OC.OrganizationChart()
                {
                    OrganizationChartTypeID = enumOrgChartType.SingleOrg,
                    OrgCode = new OrganizationCode()
                    {
                        OrganizationCodeID = 1357
                    },
                    CreatedBy = new ActionUser(primaryUserID)
                };

                newOrgChartID = OC.OrganizationChartManager.Instance.CreateFromPublished(newChart, true);
                OC.OrganizationChart chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);

                Assert.IsNotNull(chart, "Organization Chart is null");
                Assert.IsTrue(chart.OrganizationChartID == newOrgChartID, "Organization Chart not found");
                Assert.IsTrue(chart.OrgWorkflowStatusID == enumOrgWorkflowStatus.Draft, "New Chart is not in Draft Mode");

                // now submit update root
                OC.OrganizationChart chart2 = new OC.OrganizationChart()
                {
                    OrganizationChartID     = newOrgChartID,
                    StartPointWFPPositionID = 1,
                    UpdatedBy = new ActionUser(1)
                };

                OC.OrganizationChartManager.Instance.UpdateRootNode(chart2);

                // reload
                OC.OrganizationChart chartNewRoot = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);
                Assert.IsNotNull(chartNewRoot, "Organization Chart is null");
                Assert.IsTrue(chartNewRoot.OrganizationChartID == newOrgChartID, "Organization Chart not found");
                Assert.IsTrue(chartNewRoot.StartPointWFPPositionID == 1, "Root Not Updated");
            }
            catch
            {
                throw;
            }
            finally
            {
                DeleteChart(newOrgChartID);
            }
        }
        protected void DeleteChart(int chartID)
        {
            // now delete it -- we don't need it anymore
            OC.OrganizationChartManager.Instance.Delete(chartID);

            Console.WriteLine(string.Format("Attempting to Delete Chart: {0}", chartID));

            // now try to find it one last time
            OC.OrganizationChart chartFinalCheck = OC.OrganizationChartManager.Instance.GetByID(chartID);
            Assert.IsNotNull(chartFinalCheck, "Organization Chart was not Deleted");
            Assert.IsTrue(chartFinalCheck.OrganizationChartID == -1);

            Console.WriteLine(string.Format("Final -- Chart: {0} Deleted", chartID));
        }
        public void OrganizationChartManager_DeleteOrganizationChart()
        {
            int newOrgChartID = CreateOrgChartNew("Test Generated -- Org Chart Creation", 1795, enumOrgChartType.SingleOrg, 1);

            // now try to find it
            OC.OrganizationChart chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);
            Assert.IsNotNull(chart, "Could not find Organization Chart");

            // now delete
            OC.OrganizationChartManager.Instance.Delete(newOrgChartID);

            // now try to find it again
            OC.OrganizationChart chartFinalCheck = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);
            Assert.IsNotNull(chartFinalCheck, "Organization Chart was not Deleted");
            Assert.IsTrue(chartFinalCheck.OrganizationChartID == -1);
        }
        public void OrganizationChartManager_CreateOrganizationChart()
        {
            int newOrgChartID = CreateOrgChartNew("Test Generated -- Org Chart Creation", 5, enumOrgChartType.SingleOrg, 1);

            OC.OrganizationChart chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);

            Assert.IsNotNull(chart, "Organization Chart is null");
            Assert.IsTrue(chart.OrganizationChartID == newOrgChartID, "Organization Chart not found");

            // now delete it -- we don't need it anymore
            OC.OrganizationChartManager.Instance.Delete(newOrgChartID);

            // now try to find it one last time
            OC.OrganizationChart chartFinalCheck = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);
            Assert.IsNotNull(chartFinalCheck, "Organization Chart was not Deleted");
            Assert.IsTrue(chartFinalCheck.OrganizationChartID == -1);
        }
        public void OrganizationChartManager_Publish_ApprovedAsFor()
        {
            const int primaryUserID = 1;
            const int testOrgCodeID = 263;
            int       newOrgChartID = CreateOrgChartNew("Test Generated -- Get By ID", testOrgCodeID, enumOrgChartType.SingleOrg, primaryUserID);

            OC.OrganizationChart chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);

            Assert.IsNotNull(chart, "Organization Chart is null");
            Assert.IsTrue(chart.OrganizationChartID == newOrgChartID, "Organization Chart not found");

            // Now attempt to publish chart
            OC.OrganizationChartManager.Instance.Publish(newOrgChartID, primaryUserID, primaryUserID, "James Gilligan");

            // Final check -- chart should not be found
            chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);

            Assert.IsNotNull(chart, "Organization Chart is null");
            Assert.IsTrue(chart.OrganizationChartID == -1, "Organization Chart not found");
        }
        public void OrganizationChartManager_Publish_SystemImportUser()
        {
            const int primaryUserID = 1;
            const int testOrgCodeID = 262;
            int       newOrgChartID = CreateOrgChartNew("Test Generated -- Get By ID", testOrgCodeID, enumOrgChartType.SingleOrg, primaryUserID);

            OC.OrganizationChart chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);

            Assert.IsNotNull(chart, "Organization Chart is null");
            Assert.IsTrue(chart.OrganizationChartID == newOrgChartID, "Organization Chart not found");

            // Now attempt to publish chart
            OC.OrganizationChartManager.Instance.Publish(newOrgChartID, primaryUserID, ConfigWrapper.SystemImportUserID, string.Empty);

            // Final check -- chart should not be found
            chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);

            Assert.IsNotNull(chart, "Organization Chart is null");
            Assert.IsTrue(chart.OrganizationChartID == -1, "Organization Chart not found");
        }
        protected int CreateOrgChartNew(string title, int orgCodeID, enumOrgChartType chartType, int createdByUserID)
        {
            OC.OrganizationChart newChart = new OC.OrganizationChart()
            {
                OrgCode = new OrganizationCode()
                {
                    OrganizationCodeID = orgCodeID
                },
                OrganizationChartTypeID = chartType,
                CreatedBy = new ActionUser(createdByUserID),
                Header1   = title,
                Header2   = string.Format("Generated on {0}", DateTime.Now)
            };

            int newOrgChartID = OC.OrganizationChartManager.Instance.CreateNew(newChart);

            Assert.IsTrue(newOrgChartID != -1, "Organization Chart not Created");
            Console.WriteLine(string.Concat("New Org Chart: ", newOrgChartID));

            return(newOrgChartID);
        }
        public void OrganizationChartManager_SubmitToReview_Approve()
        {
            const int primaryUserID = 1;

            OC.OrganizationChart newChart = new OC.OrganizationChart()
            {
                OrganizationChartTypeID = enumOrgChartType.SingleOrg,
                OrgCode = new OrganizationCode()
                {
                    OrganizationCodeID = 1357
                },
                CreatedBy = new ActionUser(primaryUserID)
            };

            int newOrgChartID = OC.OrganizationChartManager.Instance.CreateFromPublished(newChart, true);

            OC.OrganizationChart chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);

            Assert.IsNotNull(chart, "Organization Chart is null");
            Assert.IsTrue(chart.OrganizationChartID == newOrgChartID, "Organization Chart not found");
            Assert.IsTrue(chart.OrgWorkflowStatusID == enumOrgWorkflowStatus.Draft, "New Chart is not in Draft Mode");

            // now submit to review
            OC.OrganizationChartManager.Instance.SubmitToNextStatus(newOrgChartID, enumOrgWorkflowStatus.Approval, 1);

            // reload
            OC.OrganizationChart chartNewStatus = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);
            Assert.IsNotNull(chartNewStatus, "Organization Chart is null");
            Assert.IsTrue(chartNewStatus.OrganizationChartID == newOrgChartID, "Organization Chart not found");
            Assert.IsTrue(chartNewStatus.OrgWorkflowStatusID == enumOrgWorkflowStatus.Approval, "New Chart is not in Approval");

            // now delete it -- we don't need it anymore
            OC.OrganizationChartManager.Instance.Delete(newOrgChartID);

            // now try to find it one last time
            OC.OrganizationChart chartFinalCheck = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);
            Assert.IsNotNull(chartFinalCheck, "Organization Chart was not Deleted");
            Assert.IsTrue(chartFinalCheck.OrganizationChartID == -1);
        }
        public void OrganizationChartManager_SubmitToReview_WorkflowNotSupportedException()
        {
            int newOrgChartID = -1;

            try
            {
                const int primaryUserID = 1;

                OC.OrganizationChart newChart = new OC.OrganizationChart()
                {
                    OrganizationChartTypeID = enumOrgChartType.SingleOrg,
                    OrgCode = new OrganizationCode()
                    {
                        OrganizationCodeID = 1357
                    },
                    CreatedBy = new ActionUser(primaryUserID)
                };

                newOrgChartID = OC.OrganizationChartManager.Instance.CreateFromPublished(newChart, true);
                OC.OrganizationChart chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);

                Assert.IsNotNull(chart, "Organization Chart is null");
                Assert.IsTrue(chart.OrganizationChartID == newOrgChartID, "Organization Chart not found");
                Assert.IsTrue(chart.OrgWorkflowStatusID == enumOrgWorkflowStatus.Draft, "New Chart is not in Draft Mode");

                // now submit to review
                OC.OrganizationChartManager.Instance.SubmitToNextStatus(newOrgChartID, enumOrgWorkflowStatus.Published, 1);
            }
            catch
            {
                throw;
            }
            finally
            {
                DeleteChart(newOrgChartID);
            }
        }
        public void OrganizationChartManager_GetByID()
        {
            const int primaryUserID = 1;
            const int testOrgCodeID = 15;
            int       newOrgChartID = -1;

            try
            {
                newOrgChartID = CreateOrgChartNew("Test Generated -- Get By ID", testOrgCodeID, enumOrgChartType.SingleOrg, primaryUserID);

                OC.OrganizationChart chart = OC.OrganizationChartManager.Instance.GetByID(newOrgChartID);

                Assert.IsNotNull(chart, "Organization Chart is null");
                Assert.IsTrue(chart.OrganizationChartID == newOrgChartID, "Organization Chart not found");
            }
            catch
            {
                throw;
            }
            finally
            {
                DeleteChart(newOrgChartID);
            }
        }