public void AddSemester(Semester semester)
        {
            Contract.Requires<ArgumentNullException>(semester != null, "The semester must be non-null!");

            using (var context = new SchoolContext())
            {
                context.Semesters.Add(semester);

                if (context.SaveChanges() != 0)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The semester: " + semester + " was successfully inserted!", "General", 2, 2, TraceEventType.Information);
                    } */
                }/*
                else
                {
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The semester: " + semester + " was not inserted!", "Important", 1, 1,
                            TraceEventType.Error);
                    }
                }*/
            }
        }
 /// <summary>
 /// Adds the semester.
 /// </summary>
 /// <param name="semester">The semester.</param>
 public void AddSemester(Semester semester)
 {
     using (var context = new MyApplicationContext())
     {
         context.Semesters.Add(semester);
         context.SaveChanges();
     }
 }
        public void TestSemesterAdd()
        {
            Semester semester = new Semester() { Id = 15 };

            semesterDataService.Expect(dao => dao.AddSemester(semester));

            semesterService.AddSemester(semester);

            semesterDataService.VerifyAllExpectations();
        }
 internal void ValidateDates(Semester semester, DateTime startDate, DateTime endDate, ValidationResults results)
 {
     if (startDate > endDate)
     {
         results.AddResult(new ValidationResult
         (
           "The end date cannot be before the start date", semester, "ValidationMethod", "error", null)
         );
     }
 }
 public void SetUp()
 {
     // a valid semester
     semester = new Semester()
     {
         MinCredit = 20,
         Number = 2,
         Courses = {new Course { Credit = 10}, new Course { Credit = 10} }
     };
 }
 internal void ValidateEndOfSemester(Semester semester, ValidationResults results)
 {
     if (semester.EndDate < DateTime.Now.Date)
     {
         results.AddResult(new ValidationResult
             (
             "You semester is already finished", semester, "ValidationMethod", "error", null)
             );
     }
 }
        public void TestSemesterUpdate()
        {
            Semester semester = new Semester() { Id = 14 };

            semesterDataService.Expect(dao => dao.UpdateSemester(semester));

            semesterService.UpdateSemester(semester);

            semesterDataService.VerifyAllExpectations();
        }
 /// <summary>
 /// Deletes the semester.
 /// </summary>
 /// <param name="semester">The semester.</param>
 public void DeleteSemester(Semester semester)
 {
     using (var context = new MyApplicationContext())
     {
         var newProd = new Semester { Id = semester.Id };
         context.Semesters.Attach(newProd);
         context.Semesters.Remove(newProd);
         context.SaveChanges();
     }
 }
        public void TestSemesterGetById()
        {
            int id = 15;
            Semester semester = new Semester() { Id = id };

            semesterDataService.Stub(dao => dao.GetSemesterById(id)).Return(semester);

            Semester result = semesterService.GetSemesterById(id);

            Assert.AreEqual(id, result.Id);
        }
 /// <summary>
 /// Updates the semester.
 /// </summary>
 /// <param name="semester">The semester.</param>
 /// <exception cref="System.Collections.Generic.KeyNotFoundException"></exception>
 public void UpdateSemester(Semester semester)
 {
     using (var context = new MyApplicationContext())
     {
         Semester semesterRef = context.Semesters.Where(c => c.Id == semester.Id).SingleOrDefault();
         if (semesterRef != null)
         {
             semesterRef = semester;
             context.SaveChanges();
         }
         else
             throw new KeyNotFoundException();
     }
 }
        // Create
        public void AddSemester(Semester semester)
        {
            if (!ValidateSemester(semester))
            {
                var sb = new StringBuilder();
                foreach (var error in Errors)
                {
                    sb.Append(error);
                }

                throw new ValidationException(sb.ToString());
            }

            DataMapperFactory.GetMapperFactory().SemesterMapper.AddSemester(semester);
        }
        public void DeleteSemester(Semester semester)
        {
            Contract.Requires<ArgumentNullException>(semester != null, "The semester must be non-null!");

            using (var context = new SchoolContext())
            {
                try
                {
                    var semesterToBeDeleted = new Semester()
                    {
                        SemesterId = semester.SemesterId
                    };
                    context.Semesters.Attach(semesterToBeDeleted);
                    context.Semesters.Remove(semesterToBeDeleted);

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The semester " + semester + " was successfully removed!", "General", 2, 2,
                                TraceEventType.Information);
                        }*/
                    }/*
                else
                {
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The semester " + semester + " was not removed!", "Important", 1, 1,
                            TraceEventType.Error);
                    }
                }*/
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
        }
        public void ValidateCourseCreditsTotal(Semester semester, ValidationResults results)
        {
            //var minimumCredistsTresholdPerSemester = int.Parse(ConfigurationManager.AppSettings["MinimumCreditTreshold"]);

            var minimumCredistsTresholdPerSemester = semester.MinimumCreditTreshold;

            if (!(minimumCredistsTresholdPerSemester >= 0))
            {
                results.AddResult(new ValidationResult
                (
                  "The MinimumCreditTreshold property value is not >= 0", semester, "ValidationMethod", "error", null)
                );
            }

            if (!(semester.Courses.Sum(c => c.Credits) >= minimumCredistsTresholdPerSemester))
            {
                results.AddResult(new ValidationResult
                (
                  "The courses' credits in the semester don't add up to at least MinimumCreditTreshold: " + minimumCredistsTresholdPerSemester, semester, "ValidationMethod", "error", null)
                );
            }
        }
 internal void ValidateMinimumNumberOfCoursesPerSemester(Semester semester, ValidationResults results)
 {
     if (!(semester.Courses.Count >= 5))
     {
         results.AddResult(new ValidationResult
            (
                "The number of courses in the semester must be >= 5", semester, "ValidationMethod", "error", null)
            );
     }
 }
        public void TestUpdateSemester2()
        {
            var semester = new Semester
            {
                Name = "Test99",
                StartDate = DateTime.Now.AddDays(10),
                EndDate = DateTime.Now.AddMonths(2).AddDays(2)
            };

            var c1 = new Course
            {
                Name = "C# 1",
                Description = "Programming in .NET Framework With C#",
                Credits = 8,
                Cost = 80,
                Currency = "EUR",
                LowerBound = 10,
                UpperBound = 100,
                Semesters = new[] { semester }
            };

            var c2 = new Course
            {
                Name = "C# 1",
                Description = "Programming in .NET Framework With C#",
                Credits = 8,
                Cost = 80,
                Currency = "EUR",
                LowerBound = 10,
                UpperBound = 100,
                Semesters = new[] { semester }
            };

            var c3 = new Course
            {
                Name = "C# 1",
                Description = "Programming in .NET Framework With C#",
                Credits = 8,
                Cost = 80,
                Currency = "EUR",
                LowerBound = 10,
                UpperBound = 100,
                Semesters = new[] { semester }
            };

            var c4 = new Course
            {
                Name = "C# 1",
                Description = "Programming in .NET Framework With C#",
                Credits = 8,
                Cost = 80,
                Currency = "EUR",
                LowerBound = 10,
                UpperBound = 100,
                Semesters = new[] { semester }
            };

            var c5 = new Course
            {
                Name = "C# 1",
                Description = "Programming in .NET Framework With C#",
                Credits = 8,
                Cost = 80,
                Currency = "EUR",
                LowerBound = 10,
                UpperBound = 100,
                Semesters = new[] { semester }
            };
            semester.Courses = new[] { c1, c2, c3, c4, c5 };

            _semesterService.AddSemester(semester);
            semester.Name = "Test100";
            _semesterService.UpdateSemester(semester.SemesterId, semester.Name, semester.StartDate, semester.EndDate);
            var updated = _semesterService.GetSemesterById(semester.SemesterId);
            Assert.AreEqual("Test100", updated.Name);
        }
 public void TestCourseCoursesCreditHigh()
 {
     semester = new Semester() { MinCredit = 5, Number = 2, Courses = { new Course() { Credit = 10 } } };
     ValidationResults validationResults = Validation.Validate<Semester>(semester);
     Assert.AreEqual(0, validationResults.Count);
 }
        public void DeleteSemester(int semesterId)
        {
            Contract.Requires<ArgumentOutOfRangeException>(semesterId > 0, "The semesterId must be > 0!");

            using (var context = new SchoolContext())
            {
                var semesterToBeDeleted = new Semester
                {
                    SemesterId = semesterId
                };

                context.Semesters.Attach(semesterToBeDeleted);
                context.Semesters.Remove(semesterToBeDeleted);

                try
                {
                    if (context.SaveChanges() != 0)
                    {
                        /*
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The semester " + semesterToBeDeleted + " was successfully removed!", "General",
                                2, 2, TraceEventType.Information);
                        }*/
                    }/*
                    else
                    {
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The semester " + semesterToBeDeleted + " was not removed!", "Important", 1, 1,
                                TraceEventType.Error);
                        }
                    }*/
                }
                catch
                {
                    throw new NoSuchEntityException("The semester with the id=" + semesterToBeDeleted + " does not exist in the database");
                }

            }
        }
 public void TestSemesterCoursesNotNull()
 {
     semester = new Semester();
     Assert.AreNotEqual(null, semester.Courses);
 }
 public void DeleteSemester(Semester semester)
 {
     semesterDataService.DeleteSemester(semester);
 }
 // Update
 public void UpdateSemester(int semesterId, Semester semester)
 {
     DataMapperFactory.GetMapperFactory().SemesterMapper.UpdateSemester(semesterId, semester);
 }
 private bool ValidateSemester(Semester course)
 {
     var result = Validation.Validate(course);
      if (!result.IsValid)
      {
          var firstOrDefault = result.FirstOrDefault();
          if (firstOrDefault != null) Errors.Add(firstOrDefault.Message);
      }
      return result.IsValid;
 }
 public void TestSemesterNegativeTreshold()
 {
     var semester = new Semester
     {
         Name = "Spring",
         StartDate = DateTime.Now.AddMonths(-2),
         EndDate = DateTime.Now.AddMonths(1)
     };
     semester.MinimumCreditTreshold = -1;
     var res = Validation.Validate(semester);
     Assert.AreEqual(res.IsValid, false);
 }
 public void TestSemesterCoursesEmpty()
 {
     semester = new Semester();
     Assert.AreEqual(0, semester.Courses.Count);
 }
 public void UpdateSemester(Semester semester)
 {
     semesterDataService.UpdateSemester(semester);
 }
        public void TestSemesterWithStartBeforeEnd()
        {
            var semester = new Semester
            {
                Name = "Spring",
                StartDate = DateTime.Now.AddMonths(2),
                EndDate = DateTime.Now.AddMonths(1)
            };

            var res = Validation.Validate(semester);
            Assert.AreEqual(res.IsValid, false);
        }
        public void UpdateSemester(int semesterId, Semester semester)
        {
            Contract.Requires<ArgumentOutOfRangeException>(semesterId > 0, "The semesterId must be > 0!");
            Contract.Requires<ArgumentNullException>(semester != null, "The semester must be non-null!");

            using (var context = new SchoolContext())
            {
                var semesterToBeUpdated = context.Semesters.SingleOrDefault(s => s.SemesterId == semesterId);

                if (semesterToBeUpdated != null)
                {
                    semesterToBeUpdated.Name = semester.Name;
                    semesterToBeUpdated.StartDate = semester.StartDate;
                    semesterToBeUpdated.EndDate = semester.EndDate;
                    semesterToBeUpdated.Courses = semester.Courses;

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The semester " + semesterToBeUpdated + " was successfully updated!", "General",
                                2, 2, TraceEventType.Information);
                        }*/
                    }/*
                    else
                    {

                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The semester " + semesterToBeUpdated + " was not updated!", "Important", 1, 1,
                                TraceEventType.Error);
                        }
                    }*/
                }
                else
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The semester with id: " + semesterId + " doesn't exist in the database!",
                            "Important", 1, 1, TraceEventType.Error);
                    }*/

                    throw new NoSuchEntityException("The semester with id: " + semesterId +
                                                    " doesn't exist in the database!");
                }
            }
        }
        public void TestSemesterExpired()
        {
            var semester = new Semester
            {
                Name = "Spring",
                StartDate = DateTime.Now.AddMonths(-2),
                EndDate = DateTime.Now.AddMonths(-1)
            };

            var res = Validation.Validate(semester);
            Assert.AreEqual(false,res.IsValid);
        }
 public void AddSemester(Semester semester)
 {
     semesterDataService.AddSemester(semester);
 }
        public void TestSemesterGetListOfSemesters()
        {
            Semester semester1 = new Semester()
            {
                Id = 11
            };
            Semester semester2 = new Semester()
            {
                Id = 12
            };
            IList<Semester> semesters = new List<Semester>() { semester1, semester2 };

            semesterDataService.Stub(dao => dao.GetAllSemesters()).Return(semesters);

            var result = semesterService.GetListOfSemesters();

            Assert.AreEqual(result.Count, semesters.Count);
        }
 public void DeleteSemester(Semester semester)
 {
     DataMapperFactory.GetMapperFactory().SemesterMapper.DeleteSemester(semester);
 }