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