public DataSet SelectCostCenterTest(ICostCenter costCenter)
        {
            DataSet tableVerify = new DataSet();

            tableVerify = dbEntity.SelectObject(costCenter) as DataSet;
            return(tableVerify);
        }
        protected override void InitializeObject(IGenericEntity ent)
        {
            if (ent is ICostCenter)
            {
                ICostCenter       CostCenter = (ICostCenter)ent;
                DBStoredProcedure spInsert   = new DBStoredProcedure();
                spInsert.ProcedureName = "catInsertCostCenter";
                spInsert.AddParameter(new DBParameter("@IdDepartment", DbType.Int32, ParameterDirection.Input, CostCenter.IdDepartment));
                spInsert.AddParameter(new DBParameter("@IdInergyLocation", DbType.Int32, ParameterDirection.Input, CostCenter.IdInergyLocation));
                spInsert.AddParameter(new DBParameter("@Name", DbType.String, ParameterDirection.Input, CostCenter.Name));
                spInsert.AddParameter(new DBParameter("@Code", DbType.String, ParameterDirection.Input, CostCenter.Code));
                spInsert.AddParameter(new DBParameter("@IsActive", DbType.Byte, ParameterDirection.Input, CostCenter.IsActive));

                DBStoredProcedure spUpdate = new DBStoredProcedure();
                spUpdate.ProcedureName = "catUpdateCostCenter";
                spUpdate.AddParameter(new DBParameter("@Id", DbType.Int32, ParameterDirection.Input, CostCenter.Id));
                spUpdate.AddParameter(new DBParameter("@IdDepartment", DbType.Int32, ParameterDirection.Input, CostCenter.IdDepartment));
                spUpdate.AddParameter(new DBParameter("@IdInergyLocation", DbType.Int32, ParameterDirection.Input, CostCenter.IdInergyLocation));
                spUpdate.AddParameter(new DBParameter("@Name", DbType.String, ParameterDirection.Input, CostCenter.Name));
                spUpdate.AddParameter(new DBParameter("@Code", DbType.String, ParameterDirection.Input, CostCenter.Code));
                spUpdate.AddParameter(new DBParameter("@IsActive", DbType.Boolean, ParameterDirection.Input, CostCenter.IsActive));

                DBStoredProcedure spDelete = new DBStoredProcedure();
                spDelete.ProcedureName = "catDeleteCostCenter";
                spDelete.AddParameter(new DBParameter("@Id", DbType.Int32, ParameterDirection.Input, CostCenter.Id));

                this.AddStoredProcedure("InsertObject", spInsert);
                this.AddStoredProcedure("UpdateObject", spUpdate);
                this.AddStoredProcedure("DeleteObject", spDelete);

                DBStoredProcedure spSelect = new DBStoredProcedure();
                spSelect.ProcedureName = "catSelectCostCenter";
                spSelect.AddParameter(new DBParameter("@Id", DbType.Int32, ParameterDirection.Input, CostCenter.Id));
                spSelect.AddParameter(new DBParameter("@IdInergyLocation", DbType.Int32, ParameterDirection.Input, CostCenter.IdInergyLocation));
                this.AddStoredProcedure("SelectObject", spSelect);

                DBStoredProcedure spSelectCurrency = new DBStoredProcedure();
                spSelectCurrency.ProcedureName = "catSelectCostCenterCurrency";
                spSelectCurrency.AddParameter(new DBParameter("@Id", DbType.Int32, ParameterDirection.Input, CostCenter.Id));
                this.AddStoredProcedure("SelectCostCenterCurrency", spSelectCurrency);
            }
        }
        public void VerifyCostCenter()
        {
            Random random = new Random();

            ICostCenter costCenter = BusinessObjectInitializer.CreateCostCenter();

            costCenter.Name             = DATestUtils.GenerateString(50, true, false);
            costCenter.Code             = DATestUtils.GenerateString(10, true, true);
            costCenter.IdDepartment     = random.Next(1, 1);
            costCenter.IdInergyLocation = random.Next(1, 2);
            costCenter.IsActive         = true;

            int newId = InsertCostCenterTest(costCenter);

            Assert.Greater(newId, 0);

            int rowsAffected = UpdateCostCenterTest(costCenter);

            Assert.AreEqual(1, rowsAffected);

            DataTable resultTable = SelectCostCenterTest(costCenter).Tables[0];

            //Verifies that the table contains the correct column names and order
            StringCollection columns = new StringCollection();

            columns.AddRange(new string[] { "InergyLocation",
                                            "Code",
                                            "Name",
                                            "IsActive",
                                            "DepartmentName",
                                            "FunctionName",
                                            "Id",
                                            "IdInergyLocation",
                                            "IdDepartment",
                                            "IdFunction" });
            DATestUtils.CheckTableStructure(resultTable, columns);

            int rowCount = DeleteCostCenterTest(costCenter);

            Assert.AreEqual(1, rowCount);
        }
        public int DeleteCostCenterTest(ICostCenter costCenter, DBGenericEntity dbGenericEntity)
        {
            int rowCount = dbGenericEntity.DeleteObject(costCenter);

            return(rowCount);
        }
 public int InsertCostCenterTest(ICostCenter costCenter, DBGenericEntity dbGenericEntity)
 {
     costCenter.Id = dbGenericEntity.InsertObject(costCenter);
     return(costCenter.Id);
 }
        public void VerifyInitialBudget()
        {
            IInitialBudget         initialBudget   = BusinessObjectInitializer.CreateInitialBudget();
            ICostCenter            costCenter      = BusinessObjectInitializer.CreateCostCenter();
            IWorkPackage           workPackage     = BusinessObjectInitializer.CreateWorkPackage();
            IProject               project         = BusinessObjectInitializer.CreateProject();
            IProjectCoreTeamMember coreTeamMembers = BusinessObjectInitializer.CreateProjectCoreTeamMember();

            DBInitialBudget         dbInitialBudget     = new DBInitialBudget(connManager);
            DBGenericEntity         dbCostCenterEntity  = new DBCostCenter(connManager);
            DBGenericEntity         dbWorkPackageEntity = new DBWorkPackage(connManager);
            DBGenericEntity         dbProjectEntity     = new DBProject(connManager);
            DBProjectCoreTeamMember dbCoreteamMember    = new DBProjectCoreTeamMember(connManager);

            Random random = new Random();

            initialBudget.IdAssociate   = DATestUtils.DEFAULT_ASSOCIATE;
            initialBudget.IdPhase       = random.Next(1, 9);
            costCenter.Id               = random.Next(1000, 2000);
            costCenter.Name             = DATestUtils.GenerateString(50, true, false);
            costCenter.Code             = DATestUtils.GenerateString(10, true, true);
            costCenter.IdDepartment     = random.Next(1, 1);
            costCenter.IdInergyLocation = random.Next(1, 2);
            costCenter.IsActive         = true;

            workPackage.IdPhase          = initialBudget.IdPhase;
            workPackage.Code             = DATestUtils.GenerateString(3, true, true);
            workPackage.Name             = DATestUtils.GenerateString(30, true, false);
            workPackage.Rank             = random.Next(1, 100);
            workPackage.IsActive         = true;
            workPackage.StartYearMonth   = random.Next(2000, 2079) * 100 + random.Next(1, 12);
            workPackage.EndYearMonth     = random.Next(2000, 2079) * 100 + random.Next(1, 12);
            workPackage.LastUpdate       = DateTime.Today;
            workPackage.IdLastUserUpdate = DATestUtils.DEFAULT_ASSOCIATE;
            project.Name          = DATestUtils.GenerateString(50, true, false);
            project.Code          = DATestUtils.GenerateString(10, true, true);
            project.IdProgram     = random.Next(1, 2);
            project.IdProjectType = random.Next(1, 2);
            project.IsActive      = true;

            initialBudget.Sales       = random.Next(50000, 1000000);
            initialBudget.TotalHours  = random.Next(1, 100);
            initialBudget.ValuedHours = random.Next(1, 100);
            initialBudget.YearMonth   = DATestUtils.DEFAULT_YEAR_MONTH;

            int newId = InsertCostCenterTest(costCenter, dbCostCenterEntity);

            //Verifies that the id returned by the insert method is greater than 0
            Assert.Greater(newId, 0);
            initialBudget.IdCostCenter = newId;

            newId = InsertProjectTest(project, dbProjectEntity);
            //Verifies that the id returned by the insert method is greater than 0
            Assert.Greater(newId, 0);
            initialBudget.IdProject   = newId;
            workPackage.IdProject     = initialBudget.IdProject;
            coreTeamMembers.IdProject = initialBudget.IdProject;

            newId = InsertWorkPackageTest(workPackage, dbWorkPackageEntity);
            //Verifies that the id returned by the insert method is greater than 0
            Assert.Greater(newId, 0);
            initialBudget.IdWP = newId;

            InsertInitialBudgetMasterTest(initialBudget, dbInitialBudget);

            coreTeamMembers.IdAssociate = DATestUtils.DEFAULT_ASSOCIATE;
            coreTeamMembers.IdFunction  = DATestUtils.DEFAULT_PROJECT_FUNCTION;

            //verify if have core team member
            DataTable dsCoreMember = SelectProjectCoreTeamMemberTest(coreTeamMembers, dbCoreteamMember).Tables[0];

            if (dsCoreMember.Rows.Count == 0)
            {
                int IdCoreteammember = InsertProjectCoreTeamMemberTest(coreTeamMembers, dbCoreteamMember);
            }

            InsertInitialBudgetTest(initialBudget, dbInitialBudget);

            UpdateInitialBudgetTest(initialBudget, dbInitialBudget);

            DBWPPreselection tempTable = new DBWPPreselection(connManager);

            tempTable.BulkInsert("CREATE TABLE #BUDGET_PRESELECTION_TEMP (IdProject INT NOT NULL, IdPhase INT NOT NULL, IdWP INT NOT NULL)");
            tempTable.BulkInsert("INSERT  INTO #BUDGET_PRESELECTION_TEMP (IdProject,IdPhase,IdWP) VALUES (" + initialBudget.IdProject.ToString() + "," + initialBudget.IdPhase.ToString() + "," + initialBudget.IdWP.ToString() + ")");

            DataSet InitialBudgetDS = SelectInitialBudgetTest(initialBudget, dbInitialBudget);
            //Verifies that the table is not null
            DataTable tableVerifyPhases       = InitialBudgetDS.Tables[0];
            DataTable tableVerifyWorkPackages = InitialBudgetDS.Tables[1];
            DataTable tableVerifyCostCenters  = InitialBudgetDS.Tables[2];

            Assert.IsNotNull(tableVerifyPhases, "The table returned should not be null");
            Assert.IsNotNull(tableVerifyWorkPackages, "The table returned should not be null");
            Assert.IsNotNull(tableVerifyCostCenters, "The table returned should not be null");
            //Verifies that the first table is not null
            Assert.IsNotNull(tableVerifyPhases, "The table returned should not be null");
            //Verifies that the table returns the correcty columns
            DATestUtils.CheckColumn(tableVerifyPhases, 0, "IdProject");
            DATestUtils.CheckColumn(tableVerifyPhases, 1, "IdPhase");
            DATestUtils.CheckColumn(tableVerifyPhases, 2, "PhaseName");
            DATestUtils.CheckColumn(tableVerifyPhases, 3, "TotalHours");
            DATestUtils.CheckColumn(tableVerifyPhases, 4, "Averate");
            DATestUtils.CheckColumn(tableVerifyPhases, 5, "ValuedHours");
            DATestUtils.CheckColumn(tableVerifyPhases, 6, "OtherCosts");
            DATestUtils.CheckColumn(tableVerifyPhases, 7, "Sales");
            DATestUtils.CheckColumn(tableVerifyPhases, 8, "NetCosts");
            //Verifies that the second table is not null
            Assert.IsNotNull(tableVerifyWorkPackages, "The table returned should not be null");
            //Verifies that the table returns the correcty columns
            DATestUtils.CheckColumn(tableVerifyWorkPackages, 0, "IdProject");
            DATestUtils.CheckColumn(tableVerifyWorkPackages, 1, "IdPhase");
            DATestUtils.CheckColumn(tableVerifyWorkPackages, 2, "IdWP");
            DATestUtils.CheckColumn(tableVerifyWorkPackages, 3, "WPName");
            DATestUtils.CheckColumn(tableVerifyWorkPackages, 4, "StartYearMonth");
            DATestUtils.CheckColumn(tableVerifyWorkPackages, 5, "EndYearMonth");
            DATestUtils.CheckColumn(tableVerifyWorkPackages, 6, "TotalHours");
            DATestUtils.CheckColumn(tableVerifyWorkPackages, 7, "Averate");
            DATestUtils.CheckColumn(tableVerifyWorkPackages, 8, "ValuedHours");
            DATestUtils.CheckColumn(tableVerifyWorkPackages, 9, "OtherCosts");
            DATestUtils.CheckColumn(tableVerifyWorkPackages, 10, "Sales");
            DATestUtils.CheckColumn(tableVerifyWorkPackages, 11, "NetCosts");
            //Verifies that the third table is not null
            Assert.IsNotNull(tableVerifyWorkPackages, "The table returned should not be null");
            //Verifies that the table returns the correcty columns
            DATestUtils.CheckColumn(tableVerifyCostCenters, 0, "IdProject");
            DATestUtils.CheckColumn(tableVerifyCostCenters, 1, "IdPhase");
            DATestUtils.CheckColumn(tableVerifyCostCenters, 2, "IdWP");
            DATestUtils.CheckColumn(tableVerifyCostCenters, 3, "IdCostCenter");
            DATestUtils.CheckColumn(tableVerifyCostCenters, 4, "CostCenterName");
            DATestUtils.CheckColumn(tableVerifyCostCenters, 5, "TotalHours");
            DATestUtils.CheckColumn(tableVerifyCostCenters, 6, "Averate");
            DATestUtils.CheckColumn(tableVerifyCostCenters, 7, "ValuedHours");
            DATestUtils.CheckColumn(tableVerifyCostCenters, 8, "OtherCosts");
            DATestUtils.CheckColumn(tableVerifyCostCenters, 9, "Sales");
            DATestUtils.CheckColumn(tableVerifyCostCenters, 10, "NetCosts");
            DATestUtils.CheckColumn(tableVerifyCostCenters, 11, "IdCurrency");
            DATestUtils.CheckColumn(tableVerifyCostCenters, 12, "CurrencyCode");

            DeleteInitialBudgetTest(initialBudget, dbInitialBudget);

            int rowCount = DeleteCostCenterTest(costCenter, dbCostCenterEntity);

            //Verifies that one and only one row is affected by the delete
            Assert.AreEqual(1, rowCount);

            rowCount = DeleteWorkPackageTest(workPackage, dbWorkPackageEntity);
            //Verifies that one and only one row is affected by the delete
            Assert.AreEqual(1, rowCount);

            //Verifies that one and only one row is affected by the delete
            rowCount = DeleteProjectCoreTeamMemberTest(coreTeamMembers, dbCoreteamMember);
            Assert.AreEqual(1, rowCount);

            rowCount = DeleteProjectTest(project, dbProjectEntity);
            //Verifies that one and only one row is affected by the delete
            Assert.AreEqual(1, rowCount);
        }
        public int DeleteCostCenterTest(ICostCenter costCenter)
        {
            int rowCount = dbEntity.DeleteObject(costCenter);

            return(rowCount);
        }
 public int InsertCostCenterTest(ICostCenter costCenter)
 {
     costCenter.Id = dbEntity.InsertObject(costCenter);
     return(costCenter.Id);
 }
 public CostCentersController(ICostCenter _costCenter)
 {
     iCostCenter = _costCenter;
 }