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"); } }
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); }