public void ExistingStudentSurname() { // Arrange var student = new Student { Name= "Bob Beatty", Class = null, Age=11, GPA =3.5, CreatedDate =DateTime.Now }; _mockStudentRepository.Setup(r => r.GetStudentBySurname("Bob Beatty")).Returns(student); var result = _schoolService.CreateStudent(1, "Bob Beatty", 11, 3.5); Assert.IsFalse(result); }
public bool CreateStudent(int ClassId, string studentName, int studentAge, double studentGPA) { string surname = studentName.Trim().Split(' ').LastOrDefault().Trim(); Student studentLookup = _studentRepository.GetStudentBySurname(surname); if (studentLookup != null) return false; Student student = new Student(); student.Name = studentName; student.Age = studentAge; student.GPA = studentGPA; student.CreatedDate = DateTime.Now; return _studentRepository.CreateStudent(ClassId, student); }
public bool CreateStudent(int ClassId, Student student) { try { Class studentClass = GetClass(ClassId); if (studentClass == null) return false; student.Class = studentClass; _dbContext.Student.Add(student); _dbContext.SaveChanges(); return true; } catch (Exception e) { DomainEventSource.Log.Failure(e.Message); return false; } }