예제 #1
0
        public void IsUserAuthorizedTest()
        {
            var dataAccess = new AccessService();
            // Make sure that these domains are not there
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));

            Guid userId = dataAccess.GetUserID("*****@*****.**");
            Assert.IsTrue(userId == Guid.Empty);

            // Make sure that you can add users
            Assert.IsTrue(dataAccess.AddUser("*****@*****.**", 0));
            Assert.IsTrue(dataAccess.AddUser("*****@*****.**", 1));
            Assert.IsTrue(dataAccess.AddUser("*****@*****.**", 2));

            // Check that the users are actually in the DB
            Assert.IsTrue(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsTrue(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsTrue(dataAccess.IsUserAuthorized("*****@*****.**"));

            Guid userIdCheck2 = dataAccess.GetUserID("*****@*****.**");
            Assert.IsFalse(userIdCheck2 == Guid.Empty);

            // Delete users
            Assert.IsTrue(dataAccess.DeleteUser("*****@*****.**"));
            Assert.IsTrue(dataAccess.DeleteUser("*****@*****.**"));
            Assert.IsTrue(dataAccess.DeleteUser("*****@*****.**"));
        }
예제 #2
0
 {/// <summary>
 ///  Getting all the vertical's name from Data Access layer . 
 /// No parameter need to get pass. This method is used in app.js to get the all verticals and
 /// feed the dropdown in nav bar.
 /// </summary>
 /// <returns>verticals in format of json</returns>
     
     public string GetAllVertical()
     {
         AccessService DataAccess = new AccessService();
         var verticals = DataAccess.GetAllVerticals();
         string result = JsonConvert.SerializeObject(verticals);
         return result;            
     }
예제 #3
0
        /// <summary>
        ///  Get function ,to get all the projects for specific vertical from data access layer.
        ///  It been used in project-list.js to show the project names on a ProjectList.html.
        /// </summary>
        /// <param name="VerticalId">VerticalId (int)index defined in the Verticals enum</param>
        /// <returns>List of Project objects in format of json</returns>
        public string GetVerticalProjects(int VerticalId)
        {
            AccessService DataAccess = new AccessService();
            var passProjectList = new List<StatusUpdatesModel.Project>();
            try {
                if (this.Session["username"].ToString() != null && DataAccess.IsUserAuthorized(this.Session["username"].ToString()))
                {
                   // AccessService DataAccess = new AccessService();
                    var VerticalProjects = DataAccess.GetAllProjectsForVertical(VerticalId);

                    foreach (StatusUpdatesModel.Project project in VerticalProjects)
                    {
                        StatusUpdatesModel.Project tempProject = new StatusUpdatesModel.Project();
                        tempProject.LatestUpdate = project.LatestUpdate;
                        tempProject.ProjectID = project.ProjectID;
                        tempProject.ProjectName = project.ProjectName;
                        passProjectList.Add(tempProject);

                    }
                }
            }
            catch (Exception)
            {
                // Probably not the best way to handle this
                string empty = JsonConvert.SerializeObject(passProjectList);
                return empty;
            }
            string result = JsonConvert.SerializeObject(passProjectList);
            return result;
        }
예제 #4
0
        public void AccessServiceConstructorTest()
        {
            try
            {
                var dataAccess = new AccessService();
                if (dataAccess == null) throw new Exception("AccessService constructor returned null");
            }
            catch (Exception e)
            {
                Assert.Fail("AccessService constructor threw exception: " + e.Message);

            }
        }
예제 #5
0
        public void GetProjectUpdatesTest()
        {
            AccessService dbService = new AccessService();
            //var projectUpdates = dbService.GetProjectUpdates("6a8a7e56-e9ac-4385-a8be-5be702c1f2e6");
            UpdatePackage package = new UpdatePackage();
            package.ProjectName = "Test Getting Project Updates";
            package.Subject = "Deployment";
            package.Body = "Environment:br549|Jimmy, toloose";

            package.Updates.Add("verticalID", "3");
            package.Updates.Add("Environment", "br549");
            package.Updates.Add("Author", "Samantha");
            package.Updates.Add("Manager", "Bocephus");

            //__Adding this package should create a new Project and return the ProjectID as string
            string stId = dbService.RecordUpdatePackage(package);
            List<ProjectUpdate> list = dbService.GetProjectUpdates(stId);
            Assert.AreEqual(list[0].StatusUpdates.Count, 4);
            Guid projectID = Guid.Parse(stId);

            dbService.DeleteProject(projectID);
        }
예제 #6
0
        /// <summary>
        /// Helper function for GetAllProjectsForVerticalTest - whatever number that gets passed in should
        /// not be between 0-8
        /// </summary>
        /// <param name="illVertNum"> Fake vertical ID which the access layer should return null</param>
        private void checkForGetAllProjectsForVerticalFailure(int illVertNum)
        {
            try
            {
                var dataAccess = new AccessService();
                List<Project> illegalVertical = dataAccess.GetAllProjectsForVertical(illVertNum);
                if ((illegalVertical != null && illegalVertical.Count > 0) && (illVertNum > 7 || illVertNum < 0))
                {
                    Assert.Fail("The vertical ID " + illVertNum + "exists and it should not!");
                }
            }
            catch (Exception e)
            {
                Assert.Fail("checkForGetAllProjectsForVerticalFailure in GetAppProjectsForVerticalAsync failed with this exception: " + e.Message);
            }

        }
예제 #7
0
        public void UpdateProjectVerticalTest()
        {
            AccessService dbService = new AccessService();
            //var projectUpdates = dbService.GetProjectUpdates("6a8a7e56-e9ac-4385-a8be-5be702c1f2e6");
            UpdatePackage package = new UpdatePackage();
            package.ProjectName = "Test Getting Project Updates";
            package.Subject = "Deployment";
            package.Body = "Environment:br549|Jimmy, toloose";

            package.Updates.Add("verticalID", "3");
            package.Updates.Add("Environment", "br549");
            package.Updates.Add("Author", "Samantha");
            package.Updates.Add("Manager", "Bocephus");

            //__Adding this package should create a new Project and return the ProjectID as string
            string stId = dbService.RecordUpdatePackage(package);
            Guid projectID = Guid.Parse(stId);
            // In theory there should be an easy way to check a project vertical, but there isn't
            

            //now the actual test
            dbService.UpdateProjectVertical(5, projectID);
            List<ProjectUpdate> pjUpdates = dbService.GetProjectUpdates(stId);
            Assert.IsTrue(pjUpdates[0].Project.VerticalID == 5);

            dbService.UpdateProjectVertical(7, projectID);
            List<ProjectUpdate> pjUpdates2 = dbService.GetProjectUpdates(stId);
            Assert.IsTrue(pjUpdates2[0].Project.VerticalID == 7);


            dbService.DeleteProject(projectID);
        }
예제 #8
0
        public void ChangeProjectUpdatePhaseTest1()
        {
            AccessService dbService = new AccessService();
            //var projectUpdates = dbService.GetProjectUpdates("6a8a7e56-e9ac-4385-a8be-5be702c1f2e6");
            UpdatePackage package = new UpdatePackage();
            package.ProjectName = "Test Getting Project Updates";
            package.Subject = "Deployment";
            package.Body = "Environment:br549|Jimmy, toloose";

            package.Updates.Add("verticalID", "3");
            package.Updates.Add("Environment", "br549");
            package.Updates.Add("Author", "Samantha");
            package.Updates.Add("Manager", "Bocephus");

            //__Adding this package should create a new Project and return the ProjectID as string
            string stId = dbService.RecordUpdatePackage(package);
            Guid projectID = Guid.Parse(stId);

            // Gotta convert this to a Project Update as opposed to a plain Update Project
            List<ProjectUpdate> pjUpdates = dbService.GetProjectUpdates(stId);
            pjUpdates[0].PhaseID = 4;
            pjUpdates[0].Phase = "Build_and_Test"; // Don't think this needs to be done
            dbService.ChangeProjectUpdatePhase(pjUpdates[0]);
            List<ProjectUpdate> pjUpdateChanges = dbService.GetProjectUpdates(stId);
            Assert.IsTrue(pjUpdateChanges[0].PhaseID == 4);
            pjUpdateChanges[0].PhaseID = 5;
            dbService.ChangeProjectUpdatePhase(pjUpdateChanges[0]);
            List<ProjectUpdate> pjUpdateChangesMore = dbService.GetProjectUpdates(stId);
            Assert.IsTrue(pjUpdateChangesMore[0].PhaseID == 5);
            dbService.DeleteProject(projectID);
        }
예제 #9
0
        public void GetAllUpdatesFromEmailTest()
        {
            AccessService dbService = new AccessService();
            UpdatePackage package = new UpdatePackage();
            package.ProjectName = "Test Get All Updates from Email";
            package.Subject = "Deployment";
            package.Body = "Environment:br549|Jimmy, toloose";

            package.Updates.Add("verticalID", "3");
            package.Updates.Add("Environment", "br549");
            package.Updates.Add("Author", "Samantha");
            package.Updates.Add("Manager", "Bocephus");

            //__Adding this package should create a new Project and return the ProjectID as string
            string stId = dbService.RecordUpdatePackage(package);
            Guid projectID = Guid.Parse(stId);
            List<ProjectUpdate> pUpdate = dbService.GetProjectUpdates(stId);
            
            Assert.AreEqual(dbService.GetAllUpdatesFromEmail(pUpdate[0].ProjectUpdateID).Count, 4);
            dbService.DeleteProject(projectID);
        }
예제 #10
0
        static void Main(string[] args)
        {

            if (inDebug)
            {
                AccessService dbService = new AccessService();
                //
                var projectUpdates = dbService.GetProjectUpdates("0a9514be-0e61-4ffc-9d7b-8e151a126038");
                UpdatePackage package = new UpdatePackage();
                package.ProjectName = "we done testing";
                package.Subject = "Deployment";
                package.Body = "Environment:br549|Jimmy, toloose";

                package.Updates.Add("VerticalID",  "-1");
                package.Updates.Add( "PhaseID", "0");
                package.Updates.Add( "Environment",  "Joe's Computer");
                package.Updates.Add("Some Key","Some Value" );

                dbService.RecordUpdatePackage(package);
                var db = 1;

            }

            //AccessService dataAccess = new AccessService();
            int actionOption = 1;
           

            while (actionOption > 0)
            {
                Console.WriteLine("Select action to take:");
                Console.WriteLine("--> 1) Clear all data");
                Console.WriteLine("--> 2) Create sample data");
                Console.WriteLine("--> 3) Delete Project by ID");
                Console.WriteLine("--> 4) Delete Project by Name");
                Console.WriteLine("--> 5) Exit application");
                Console.WriteLine("??\n");

                try
                {
                    string input = Console.ReadLine();
                    actionOption = Convert.ToInt16(input);
                }
                catch (Exception)
                {

                    Console.WriteLine("Integers only please");
                    Console.WriteLine("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-\n");
                    continue;
                }
                bool success = false;
                switch (actionOption)
                {
                    case 1:
                        success = deleteAllData();
                        if (!success)
                        {
                            Console.WriteLine("Problem deleting data: " + errorMessage);
                            errorMessage = "";
                        }
                        break;
                    case 2:
                        success = writeSampleData();
                        if (!success)
                        {
                            Console.WriteLine("Problem writing sample data: " + errorMessage);
                            errorMessage = "";
                        }
                        break;
                    case 3:
                        Console.WriteLine("Enter ProjectID Guid");
                        string projectID = Console.ReadLine();
                        try
                        {
                            deleteProject(projectID, null);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error deleting project, " + e.Message);
                            continue;
                        }
                        break;
                    case 4:
                        Console.WriteLine("Enter Project Name");
                        string projectName = Console.ReadLine();
                        try
                        {
                            deleteProject(null, projectName);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error deleting project, " + e.Message);
                            continue;
                        }
                        break;
                    case 5:
                        return;
                    default:
                        return;
                }
                success = false;
            }
        }
예제 #11
0
        public void DeleteProjectTest()
        {
            AccessService dbService = new AccessService();
            //var projectUpdates = dbService.GetProjectUpdates("6a8a7e56-e9ac-4385-a8be-5be702c1f2e6");
            UpdatePackage package = new UpdatePackage();
            package.ProjectName = "Test Project";
            package.Subject = "Deployment";
            package.Body = "Environment:br549|Jimmy, toloose";

            package.Updates.Add("verticalID", "3");
            package.Updates.Add("Environment", "br549");
            package.Updates.Add("Author", "Samantha");
            package.Updates.Add("Manager", "Bocephus");

            //__Adding this package should create a new Project and return the ProjectID as string
            string stId = dbService.RecordUpdatePackage(package);
            Assert.IsFalse(string.IsNullOrEmpty(stId));

            Guid projectID = Guid.Parse(stId);
            Assert.IsFalse(projectID == Guid.Empty);

            Guid recordedId = dbService.GetProjectIDbyName(package.ProjectName);
            Assert.AreEqual(projectID, recordedId);
            // This is the actual test - let's see if it actually deletes the project
            dbService.DeleteProject(projectID);

            // When we look for updates, it should be null or empty.
            // We will not test this part because the code crashes if you try and
            // delete a project that does not exist and we are in code freeze.
            // Assert.IsNull(dbService.GetAllUpdatesForProject(projectID.ToString()));
        }
예제 #12
0
        public void GetProjectIDsTest()
        {
            var dataAccess = new AccessService();
            List<Project> allProjectsList = dataAccess.GetAllProjectNames();

            // Got to make sure that the data is the same
            using (SqlConnection sqlConnection = new SqlConnection())
            {
                sqlConnection.ConnectionString = ConnectionString;

                SqlCommand sqlCommand = new SqlCommand("select * from Project", sqlConnection);
                sqlCommand.CommandTimeout = 30;


                sqlConnection.Open();
                SqlDataReader sqlReader = sqlCommand.ExecuteReader();
                int sqlCount = 0;

                while (sqlReader.Read())
                {
                    // could make this more efficient if i knew hot to cast a sql object into a type
                    bool isProjectThere = false;
                    Project currProject = new Project();
                    currProject.ProjectID = new Guid(sqlReader["ProjectID"].ToString());
                    currProject.ProjectName = sqlReader["ProjectName"].ToString();
                    foreach (Project testProject in allProjectsList)
                    {
                        if (testProject.ProjectID.Equals(currProject.ProjectID))
                        {
                            isProjectThere = true;
                        }
                    }

                    Assert.IsTrue(isProjectThere, "Project " + currProject.ProjectName + " does not exist in the list of projects");
                    sqlCount++;
                }
                sqlConnection.Close();
                Assert.AreEqual(sqlCount, allProjectsList.Count, "The number of projects are not equal. The database has " + sqlCount + " and the Access Service layer is returning " + allProjectsList.Count + " for this list of projects");
            }
        }
예제 #13
0
        public void RecordUpdatePackageTest()
        {
            AccessService dbService = new AccessService();
            //var projectUpdates = dbService.GetProjectUpdates("6a8a7e56-e9ac-4385-a8be-5be702c1f2e6");
            UpdatePackage package = new UpdatePackage();
            package.ProjectName = "Test Project";
            package.Subject = "Deployment";
            package.Body = "Environment:br549|Jimmy, toloose";

            package.Updates.Add("verticalID", "3");
            package.Updates.Add("Environment", "br549");
            package.Updates.Add("Author", "Samantha");
            package.Updates.Add("Manager", "Bocephus");

            //__Adding this package should create a new Project and return the ProjectID as string
            string stId = dbService.RecordUpdatePackage(package);
            Assert.IsFalse(string.IsNullOrEmpty(stId));

            Guid projectID = Guid.Parse(stId);
            Assert.IsFalse(projectID == Guid.Empty);

            Guid recordedId = dbService.GetProjectIDbyName(package.ProjectName);
            Assert.AreEqual(projectID, recordedId);



            dbService.DeleteProject(projectID);
        }
예제 #14
0
        public void GetUserIDTest()
        {
            var dataAccess = new AccessService();
            // Add a user
            Assert.IsTrue(dataAccess.AddUser("*****@*****.**", 0));

            // Check that the users are actually in the DB
            Assert.IsTrue(dataAccess.IsUserAuthorized("*****@*****.**"));

            // Here's the actual test - the GUID should not be empty
            Guid userIdCheck = dataAccess.GetUserID("*****@*****.**");
            Assert.IsFalse(userIdCheck == Guid.Empty);

            // Now delete and check again - if that was really the user's id, then it should return false after deleting
            Assert.IsTrue(dataAccess.DeleteUser("*****@*****.**"));
            Guid userIdCheck2 = dataAccess.GetUserID("*****@*****.**");
            Assert.IsTrue(userIdCheck2 == Guid.Empty);

        }
예제 #15
0
        public void UpdateUserEmailTest2()
        {
            var dataAccess = new AccessService();
            // Make sure that these domains are not there
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));

            // Make sure these updated email addresses do not exist
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));

            Guid userId = dataAccess.GetUserID("*****@*****.**");
            Assert.IsTrue(userId == Guid.Empty);

            // Make sure that you can add users
            Assert.IsTrue(dataAccess.AddUser("*****@*****.**", 0));
            Assert.IsTrue(dataAccess.AddUser("*****@*****.**", 1));
            Assert.IsTrue(dataAccess.AddUser("*****@*****.**", 2));

            // Check that the users are actually in the DB
            Assert.IsTrue(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsTrue(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsTrue(dataAccess.IsUserAuthorized("*****@*****.**"));

            Guid userIdCheck2 = dataAccess.GetUserID("*****@*****.**");
            Assert.IsFalse(userIdCheck2 == Guid.Empty);

            // Make sure these updated email addresses do not exist
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));

            // Now we are going to update these users - this is the main part
            Assert.IsTrue(dataAccess.UpdateUserEmail("*****@*****.**", "*****@*****.**"));
            Assert.IsTrue(dataAccess.UpdateUserEmail("*****@*****.**", "*****@*****.**"));
            // Update it in the overloaded way
            Guid userId3 = dataAccess.GetUserID("*****@*****.**");
            Assert.IsTrue(dataAccess.UpdateUserEmail(userId3, "*****@*****.**"));

            // Make sure that these domains are not there anymore
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsFalse(dataAccess.IsUserAuthorized("*****@*****.**"));

            // Make sure these updated email addresses exist
            Assert.IsTrue(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsTrue(dataAccess.IsUserAuthorized("*****@*****.**"));
            Assert.IsTrue(dataAccess.IsUserAuthorized("*****@*****.**"));

            // Clean up users
            Assert.IsTrue(dataAccess.DeleteUser("*****@*****.**"));
            Assert.IsTrue(dataAccess.DeleteUser("*****@*****.**"));
            Assert.IsTrue(dataAccess.DeleteUser("*****@*****.**"));

        }
예제 #16
0
        public void UpdateUserRoleTest()
        {
            var dataAccess = new AccessService();

            // Make sure that you can add users
            Assert.IsTrue(dataAccess.AddUser("*****@*****.**", 0));
            Assert.IsTrue(dataAccess.AddUser("*****@*****.**", 1));
            Assert.IsTrue(dataAccess.AddUser("*****@*****.**", 2));

            Guid userIdCheck2 = dataAccess.GetUserID("*****@*****.**");
            Assert.IsFalse(userIdCheck2 == Guid.Empty);

            // Check the user role
            Assert.IsTrue(dataAccess.GetUserRole("*****@*****.**") == 0);
            Assert.IsTrue(dataAccess.GetUserRole("*****@*****.**") == 1);
            Assert.IsTrue(dataAccess.GetUserRole("*****@*****.**") == 2);

            // Here's the actual test - update the user role:
            Assert.IsTrue(dataAccess.UpdateUserRole("*****@*****.**", 1));
            Assert.IsTrue(dataAccess.UpdateUserRole("*****@*****.**", 2));
            Assert.IsTrue(dataAccess.UpdateUserRole("*****@*****.**", 0));

            // Check that the user role has changed correctly
            Assert.IsFalse(dataAccess.GetUserRole("*****@*****.**") == 0);
            Assert.IsFalse(dataAccess.GetUserRole("*****@*****.**") == 1);
            Assert.IsFalse(dataAccess.GetUserRole("*****@*****.**") == 2);
            Assert.IsTrue(dataAccess.GetUserRole("*****@*****.**") == 1);
            Assert.IsTrue(dataAccess.GetUserRole("*****@*****.**") == 2);
            Assert.IsTrue(dataAccess.GetUserRole("*****@*****.**") == 0);

            // Delete users
            Assert.IsTrue(dataAccess.DeleteUser("*****@*****.**"));
            Assert.IsTrue(dataAccess.DeleteUser("*****@*****.**"));
            Assert.IsTrue(dataAccess.DeleteUser("*****@*****.**"));
        }
예제 #17
0
        public void GetUserRoleTest()
        {//__this covers AddUser, GetUserRole, DeleteUser, UpdateUserRole
            string emailAddy = "*****@*****.**";
            //string emailAddy2 = "*****@*****.**";
            int userRole = 1;
            AccessService dataAccess = new AccessService();
            try//__make sure we can back out in case of errors
            {

                bool userAdded = dataAccess.AddUser(emailAddy, userRole);

                //__test adding new user
                Assert.IsTrue(userAdded, "AddUser returned false for email " + emailAddy + ", UserRole=" + userRole);
                int recordedRole = dataAccess.GetUserRole(emailAddy);
                Assert.AreEqual(userRole, recordedRole);

                int newRole = 0;
                dataAccess.UpdateUserRole(emailAddy, newRole);
                recordedRole = dataAccess.GetUserRole(emailAddy);
                Assert.AreEqual(newRole, recordedRole, "User Role not properly Modified");

                bool userRemoved = dataAccess.DeleteUser(emailAddy);
                Assert.IsTrue(userRemoved, "userRemoved returned false");
            }
            finally
            {//__make sure to clean out our test data
                if (dataAccess.IsUserAuthorized(emailAddy))
                {
                    dataAccess.DeleteUser(emailAddy);
                }
            }
        }
예제 #18
0
        public void IsAppAuthorizedTest()
        {
            var dataAccess = new AccessService();

            // Make sure the authorized apps are authorized
            Assert.IsTrue(dataAccess.IsAppAuthorized("excelCostco"));
            Assert.IsTrue(dataAccess.IsAppAuthorized("emailCostco"));

            // Throw in some fake ones to be sure it's working
            Assert.IsFalse(dataAccess.IsAppAuthorized("junkApp"));
            Assert.IsFalse(dataAccess.IsAppAuthorized("1"));
            Assert.IsFalse(dataAccess.IsAppAuthorized("password"));
        }
예제 #19
0
        public void GetProjectNameForIDTest()
        {
            var dataAccess = new AccessService();
            // Grab a list of all the projects in the database
            List<Project> allProjects = dataAccess.GetAllProjectNames();

            // In case the database has just been wiped out...
            if (allProjects.Count != 0)
            {
                // Pick a random project and get the ID and the (correct) project name
                Random random = new Random();
                int randomNumber = random.Next(0, allProjects.Count);
                Guid randomProjectID = allProjects[randomNumber].ProjectID;
                string randomProjectName = allProjects[randomNumber].ProjectName;

                // Using the ID, use the function that we are testing to retrieve the projectname
                string checkThisName = dataAccess.GetProjectNameForID(randomProjectID);

                // Check if it is correct. boom.
                Assert.AreEqual(checkThisName, randomProjectName);
            }
            else
            {
                Assert.Inconclusive("Database might be empty, try rerunning with data");
            }
        }
예제 #20
0
        public void GetUpdatesForKeyTest()
        {
            AccessService dbService = new AccessService();
            //var projectUpdates = dbService.GetProjectUpdates("6a8a7e56-e9ac-4385-a8be-5be702c1f2e6");
            UpdatePackage package = new UpdatePackage();
            package.ProjectName = "Test retrieving key Project Updates";
            package.Subject = "Deployment";
            package.Body = "Environment:br549|Jimmy, toloose";

            package.Updates.Add("SuperDuperKeyTest", "13504");
            package.Updates.Add("SuperDuperKeyTest2", "hello world");

            //__Adding this package should create a new Project and return the ProjectID as string
            string stId = dbService.RecordUpdatePackage(package);
            //List<ProjectUpdate> list = dbService.GetProjectUpdates(stId);
            //Assert.AreEqual(list[0].StatusUpdates.Count, 4);
            Guid projectID = Guid.Parse(stId);
            List<StatusUpdate> statusUpdates = dbService.GetUpdatesForKey("SuperDuperKeyTest", projectID);
            Assert.IsTrue(statusUpdates[0].UpdateValue == "13504");
            dbService.DeleteProject(projectID);

        }
예제 #21
0
        private static void deleteProject(string projectIDstring = null, string projectName = null)
        {
            AccessService dataService = new AccessService();
            Guid projectID = new Guid();
            if (string.IsNullOrEmpty(projectIDstring) )
            {
                projectID = dataService.GetProjectIDbyName(projectName);
            }
            else
            {
                try
                {
                    projectID = new Guid(projectIDstring);
                }
                catch (Exception)
                {
                    Console.WriteLine("Problem creating Guid, delete has failed");
                    return;
                }
            }

            if (projectID == Guid.Empty)
            {
                Console.WriteLine("Problem getting ID for " + projectName);
                return;
            }

            projectName = dataService.GetProjectNameForID(projectID);
            int updatesRemoved = 0;
            var context = createContext();
            List<StatusUpdate> updatesToRemove = context.StatusUpdates.Where(u => u.ProjectID == projectID).ToList();
            updatesRemoved = updatesToRemove.Count;
            context.StatusUpdates.RemoveRange(updatesToRemove);
            context.SaveChanges();
            Console.WriteLine("Removed " + updatesRemoved + " updates from Status Update Table");

            List<ProjectPhase> projectPhases = context.ProjectPhases.Where(p => p.ProjectID == projectID).ToList();

            int phaseEntryCount = projectPhases.Count(p => p.ProjectID == projectID);
            context.ProjectPhases.RemoveRange(projectPhases);
            context.SaveChanges();
            Console.WriteLine("Removed " + phaseEntryCount + " ProjectPhase entries");

            Project projectToDelete = context.Projects.FirstOrDefault(p => p.ProjectID == projectID);
            context.Projects.Remove(projectToDelete);
            context.SaveChanges();
            Console.WriteLine("Project " + projectName + " with ID=" + projectID + " is removed");
        
        }
예제 #22
0
        public void GetAllVerticalsTest()
        {
            var dataAccess = new AccessService();
            List<KeyValuePair<int, string>> verticalsList = dataAccess.GetAllVerticals();
            // We can hardcode this because the verticals should never change. If it does,
            // it shouldn't be very frequent and is reasonable to change this relatively unimportant unit test.
            Assert.IsTrue(verticalsList[0].Key == 0);
            Assert.IsTrue(verticalsList[0].Value == "Warehouse_Solutions");
            Assert.IsTrue(verticalsList[1].Key == 1);
            Assert.IsTrue(verticalsList[1].Value == "Merchandising_Solutions");
            Assert.IsTrue(verticalsList[2].Key == 2);
            Assert.IsTrue(verticalsList[2].Value == "Membership_Solutions");
            Assert.IsTrue(verticalsList[3].Key == 3);
            Assert.IsTrue(verticalsList[3].Value == "Distribution_Solutions");
            Assert.IsTrue(verticalsList[4].Key == 4);
            Assert.IsTrue(verticalsList[4].Value == "International_Solutions");
            Assert.IsTrue(verticalsList[5].Key == 5);
            Assert.IsTrue(verticalsList[5].Value == "Ancillary_Solutions");
            Assert.IsTrue(verticalsList[6].Key == 6);
            Assert.IsTrue(verticalsList[6].Value == "eBusiness_Solutions");
            Assert.IsTrue(verticalsList[7].Key == 7);
            Assert.IsTrue(verticalsList[7].Value == "Corporate_Solutions");
            Assert.IsTrue(verticalsList[8].Key == -1);
            Assert.IsTrue(verticalsList[8].Value == "Not_Assigned");

        }
예제 #23
0
        private static bool writeSampleData()
        {
            try
            {
                int totalRecords = 0;
                DateTime start = DateTime.Now;
                AccessService dataAccess = new AccessService();
                List<ProjectUpdate> projects = UpdateGenerator.GenerateUpdates(numberOfProjectsToGenerate);
                int numberOfProjects = projects.Count;
                foreach (ProjectUpdate project in projects)
                {
                    List<StatusUpdate> updates = project.StatusUpdates.ToList();
                    totalRecords += updates.Count;
                    dataAccess.RecordStatusUpdate(updates);
                    Console.WriteLine("Recorded " + updates.Count + " updates for Project ");
                }
                int durationInMinutes = (DateTime.Now - start).Minutes;
                Console.WriteLine("Recorded " + totalRecords + " for " + numberOfProjects + " projects in " + durationInMinutes + "m");
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
                Console.Write("*******Error: " + errorMessage + "\n");
                Console.Write("*******InnerException: " + e.InnerException + "\n");
                Console.WriteLine("*********Detail: " + e.InnerException.Message + "\n");
                return false;
            }
            return true;

        }
예제 #24
0
        public void GetAllProjectsForVerticalTest()
        {
         var dataAccess = new AccessService();
         for (int verticalIter = -1; verticalIter < VERTICALENUM; verticalIter++)
         {
                    List<Project> allProjectsList = dataAccess.GetAllProjectsForVertical(verticalIter);

                    // Got to make sure that the data is the same
                    using (SqlConnection sqlConnection = new SqlConnection())
                    {
                        sqlConnection.ConnectionString = ConnectionString;


                        SqlCommand sqlCommand = new SqlCommand("select * from Project where VerticalID=\'" + verticalIter + "\'", sqlConnection);
                        sqlCommand.CommandTimeout = 30;


                        sqlConnection.Open();
                        SqlDataReader sqlReader = sqlCommand.ExecuteReader();
                        int sqlCount = 0;

                        while (sqlReader.Read())
                        {
                            // could make this more efficient if i knew hot to cast a sql object into a type
                            bool isProjectThere = false;
                            Project currProject = new Project();
                            currProject.ProjectID = new Guid(sqlReader["ProjectID"].ToString());
                            currProject.ProjectName = sqlReader["ProjectName"].ToString();
                            foreach (Project testProject in allProjectsList)
                            {
                                if (testProject.ProjectID.Equals(currProject.ProjectID))
                                {
                                    isProjectThere = true;
                                }
                            }

                            Assert.IsTrue(isProjectThere, "Project " + currProject.ProjectName + " does not exist in vertical " + verticalIter);
                            sqlCount++;
                        }
                        sqlConnection.Close();
                        Assert.AreEqual(sqlCount, allProjectsList.Count, "The number of projects are not equal. The database has " + sqlCount + " and the Access Service layer is returning " + allProjectsList.Count + " for vertical " + verticalIter);
                    } 

                Assert.AreNotEqual(allProjectsList, null);
                }

                // Boundary test #2: Vertical ID -2
                checkForGetAllProjectsForVerticalFailure(-2);

                // Boundary test #3: Vertical ID 8
                checkForGetAllProjectsForVerticalFailure(8);

                // Boundary test #4: Vertical ID 9
                checkForGetAllProjectsForVerticalFailure(9);

                // Random number test
                Random random = new Random();
                int randomNumber = random.Next(8, int.MaxValue);
                checkForGetAllProjectsForVerticalFailure(randomNumber);

        }