public void UpdateCourse_Test_Department() { var obj = CreateTestCourse(Repository); var originalDepartmentID = obj.DepartmentID; try { var newDepartment = DepartmentTest.CreateTestDepartment(Repository); obj.DepartmentID = newDepartment.DepartmentID; obj = Repository.UpdateCourse(obj); //confirm the object was updated. var updated = Repository.GetCourse(obj.CourseID); Assert.IsNotNull(updated); Assert.AreEqual(newDepartment.DepartmentID, updated.DepartmentID); } catch (Exception) { throw; } finally { //Remove the test data. CourseTest.DeleteTestObject(obj, Repository); var originalDepartment = Repository.GetDepartment(originalDepartmentID); DepartmentTest.DeleteTestObject(originalDepartment, Repository); } }
/// <summary> /// Creates the test course. /// </summary> /// <param name="_repository">The repository.</param> /// <returns></returns> public static CourseDTO CreateTestCourse(ISchoolData _repository) { var randomName = Guid.NewGuid().ToString(); var random = new Random(); var credits = random.Next(1, 4); var departmentID = DepartmentTest.CreateTestDepartment(_repository).DepartmentID; var obj = new CourseDTO(); obj.CourseID = 0; obj.Name = randomName; obj.Credits = credits; obj.DepartmentID = departmentID; obj = _repository.CreateCourse(obj); return(obj); }