/// <summary>
        ///     Update Test
        /// </summary>
        /// <param name="updatedTest">The Test to update</param>
        public void UpdateTest(Test updatedTest)
        {
            //check if the test to update is ok
            if (AllTests.All(test => test.Id != updatedTest.Id))
            {
                throw new Exception("Test doesn't exist");
            }
            if (AllTests.Any(test =>
                             test.Id == updatedTest.Id && (test.TesterId != updatedTest.TesterId ||
                                                           test.TraineeId != updatedTest.TraineeId ||
                                                           test.TestTime != updatedTest.TestTime)))
            {
                throw new Exception("Can't change this test details. please create new test");
            }
            if (updatedTest.Criteria.Count <= Configuration.MinimumCriteria)
            {
                throw new Exception("Not enough criterion");
            }
            if (updatedTest.ActualTestTime == DateTime.MinValue)
            {
                throw new Exception("Test date not updated");
            }
            if ((updatedTest.ActualTestTime - updatedTest.TestTime).Days < 0)
            {
                throw new Exception("Actual date can't be before test date time");
            }
            //update passed status
            updatedTest.UpdatePassedTest();

            //update test
            _dalImp.UpdateTest(updatedTest);
        }
Example #2
0
 public bool HasFile(string fullPath)
 {
     if (string.Equals(fullPath, FullPath, StringComparison.OrdinalIgnoreCase))
     {
         return(true);
     }
     return(AllTests.Any(t => t.Source != null && string.Equals(fullPath, t.Source.FullPath, StringComparison.OrdinalIgnoreCase)));
 }
Example #3
0
        private void GotoSelectionButtonClicked(object sender, EventArgs e)
        {
            var handler = OnGoToSelectedTest;

            if (handler != null && AllTests.Any())
            {
                var selectionIndex = testOutputGridView.SelectedRows[0].Index;
                handler(this, new SelectedTestEventArgs(AllTests[selectionIndex]));
            }
        }
 /// <summary>
 ///     Remove a Tester
 /// </summary>
 /// <param name="testerToDelete">The Tester to remove</param>
 public void RemoveTester(Tester testerToDelete)
 {
     if (AllTesters.All(tester => tester.Id != testerToDelete.Id))
     {
         throw new Exception("Tester doesn't exist");
     }
     if (AllTests.Any(x => x.TesterId == testerToDelete.Id))
     {
         throw new Exception("Tester Has " + AllTests.Count(x => x.TesterId == testerToDelete.Id) +
                             " Tests. Please Delete Them First.");
     }
     _dalImp.RemoveTester(testerToDelete);
 }
 /// <summary>
 ///     Remove Trainee
 /// </summary>
 /// <param name="traineeToDelete">The Trainee to remove</param>
 public void RemoveTrainee(Trainee traineeToDelete)
 {
     if (AllTrainees.All(trainee => trainee.Id != traineeToDelete.Id))
     {
         throw new Exception("Trainee doesn't exist");
     }
     if (AllTests.Any(x => x.TraineeId == traineeToDelete.Id))
     {
         throw new Exception("Trainee Has " + AllTests.Count(x => x.TraineeId == traineeToDelete.Id) +
                             " Tests. Please Delete Them First.");
     }
     _dalImp.RemoveTrainee(traineeToDelete);
 }
Example #6
0
        private void RunSelectedTestMenuItemClicked(object sender, EventArgs e)
        {
            var handler = OnRunSelectedTestButtonClick;

            if (handler != null && AllTests.Any())
            {
                var selection = AllTests.Where(test => testOutputGridView.SelectedRows
                                               .Cast <DataGridViewRow>()
                                               .Select(row => row.DataBoundItem as TestExplorerItem)
                                               .Select(item => item.GetTestMethod())
                                               .Contains(test.GetTestMethod()))
                                .ToList();                                           //ToList forces immediate execution so clearing the gui of previous results won't cause us to lose the selection.

                handler(this, new SelectedTestEventArgs(selection));
            }
        }
        /// <summary>
        ///     Add a Test
        /// </summary>
        /// <param name="newTest">The Test to add</param>
        public void AddTest(Test newTest)
        {
            //check if the test is ok
            var testMissingDate = newTest.TestTime == DateTime.MinValue;

            var testerExist = AllTesters.Any(tester => tester.Id == newTest.TesterId);

            var traineeExist = AllTrainees.Any(trainee => trainee.Id == newTest.TraineeId);

            var twoTestesTooClose = AllTests.Any(test =>
                                                 test.TraineeId == newTest.TraineeId && test.LicenseType == newTest.LicenseType &&
                                                 Math.Abs((newTest.TestTime - test.TestTime).TotalDays) < Configuration.MinTimeBetweenTests);

            // the trainee didn't the minimum number of lessens before test
            var lessThenMinLessons = AllTrainees.Any(trainee =>
                                                     trainee.Id == newTest.TraineeId && trainee.LicenseTypeLearning.Any(l =>
                                                                                                                        l.License == newTest.LicenseType && l.NumberOfLessons < Configuration.MinLessons));

            var traineeIsLearningLicense = AllTrainees.Any(trainee =>
                                                           trainee.Id == newTest.TraineeId &&
                                                           trainee.LicenseTypeLearning.Any(l => l.License == newTest.LicenseType));

            var testerIsTeachingLicense = AllTesters.Any(tester =>
                                                         tester.Id == newTest.TesterId && tester.LicenseTypeTeaching.Any(l => l == newTest.LicenseType));

            var tooManyTestInWeek =
                AllTests.Count(test =>
                               test.TesterId == newTest.TesterId && Tools.DatesAreInTheSameWeek(newTest.TestTime, test.TestTime)) +
                1 >
                AllTesters.First(tester => tester.Id == newTest.TesterId).MaxWeekExams;

            var traineeHasTestInSameTime = AllTests.Any(test =>
                                                        test.TraineeId == newTest.TraineeId && newTest.TestTime == test.TestTime);
            var testerHasTestInSameTime =
                AllTests.Any(test => test.TesterId == newTest.TesterId && newTest.TestTime == test.TestTime);

            var traineeHasLicenseAlready = AllTests.Any(y =>
                                                        y.TraineeId == newTest.TraineeId && y.Passed == true && y.LicenseType == newTest.LicenseType);

            var traineePassedTestAlready = AllTests.Any(test =>
                                                        test.TraineeId == newTest.TraineeId && test.LicenseType == newTest.LicenseType && test.Passed == true);

            if (testMissingDate)
            {
                throw new Exception("Enter a valid date");
            }
            if (tooManyTestInWeek)
            {
                throw new Exception("To many tests for tester");
            }
            if (!traineeExist)
            {
                throw new Exception("This trainee doesn't exist");
            }
            if (!testerExist)
            {
                throw new Exception("This tester doesn't exist");
            }
            if (twoTestesTooClose)
            {
                throw new Exception(
                          "The trainee has a already a test in " + Configuration.MinTimeBetweenTests + " days");
            }
            if (lessThenMinLessons)
            {
                throw new Exception("The trainee learned less then " + Configuration.MinLessons +
                                    " lessons which is the minimum");
            }
            if (!traineeIsLearningLicense)
            {
                throw new Exception("The trainee is not learning for this license");
            }
            if (!testerIsTeachingLicense)
            {
                throw new Exception("Tester is not qualified for this license type");
            }
            if (traineeHasTestInSameTime)
            {
                throw new Exception("The trainee has already another test in the same time");
            }
            if (testerHasTestInSameTime)
            {
                throw new Exception("The tester has already another test in the same time");
            }
            if (traineeHasLicenseAlready)
            {
                throw new Exception("The trainee has already a license with same type");
            }
            if (traineePassedTestAlready)
            {
                throw new Exception("The trainee already passed the test");
            }


            //add the test
            _dalImp.AddTest(newTest);
        }