public static CourseDay CourseDayDtoToModelEntity(CourseDayDto courseDayDto) { var courseDay = new CourseDay(); courseDay.Student = StudentDtoModelToEntity(courseDayDto.Student); courseDay.Absent = courseDayDto.Absent; courseDay.Present = courseDayDto.Present; courseDay.Allpresence = courseDayDto.Allpresence; courseDay.Course = CourseDtoToModelToEntity(courseDayDto.Course); return(courseDay); }
//TODO Wszystko co leci w dol do bazy public bool AddNewDay(CourseDayDto courseDayDto) { var courseDay = new CourseDay(); courseDay = DtoToEntityMapper.CourseDayDtoToModelEntity(courseDayDto); //var succes = _courseDayRepo.AddNewCourseDay(courseDay); var succes = _courseDayRepoService.AddNewCourseDay(courseDay); if (succes) { return(true); } return(false); }
public void CheckIfMethodGivingPoperHomeworkDto_() { //Arrange var courseDay = new CourseDay(); var courseDayDto = new CourseDayDto(); var CourseDayRepoMock = new Mock <ICourseDayRepo>(); var entityToDtoMapper = new Mock <IEntityToDtoMapper>(); CourseDayRepoMock.Setup(x => x.GetCourseDayFromD(It.IsAny <int>(), It.IsAny <int>())).Returns(courseDay); entityToDtoMapper.Setup(x => x.CourseDayModelToDto(courseDay)).Returns(courseDayDto); var courseDayService = new CourseDayService(CourseDayRepoMock.Object, entityToDtoMapper.Object); //Act var result = courseDayService.GetCourseDayByIds(1, 1); //Assert Assert.AreSame(result, courseDayDto); }
} //dodaj studenta private void AddNewDayOfCourse() { while (SelectedCourse == 0) { Console.WriteLine("Nie wybrales kursu dla ktorego chcesz dodac dzien!\n"); SelectCourse(); //SelectedCourse = SelectCourse(); } //sprawdzam czy zostal wybrany kurs dla ktorego chce sprawdzic obecnosc Console.Write("Lista obecnosci dla kursu: '" + SelectedCourse + "'" + "\n"); var studentListFromCourse = _courseService.GetStudentListFromDl(SelectedCourse); foreach (var student in studentListFromCourse) { var courseDayDto = new CourseDayDto(); //tworze dzien kursu courseDayDto.Student = student; courseDayDto.Course = _courseService.GetCourseById(SelectedCourse); //pobranie kursu Console.Write(" obecny = 1\n nieobecny = 0\n"); var answer = ConsoleReadHelper.GetInt("Czy " + student.Name + " " + student.Surname + " jest obecny?: "); if (answer == 1) { courseDayDto.Present++; courseDayDto.Allpresence++; courseDayDto.Absent = 0; } else if (answer == 0) { courseDayDto.Absent++; courseDayDto.Allpresence++; courseDayDto.Present = 0; } _courseDayService.AddNewDay(courseDayDto); } //metoda ktora wyciagnie ten kurs } //dodanie listy obecnosci na kursie
public CourseDayDto CourseDayModelToDto(CourseDay courseDay) { if (courseDay == null) { return(null); } CourseDayDto courseDayDto = new CourseDayDto(); courseDayDto.Id = courseDay.Id; courseDayDto.Present = courseDay.Present; courseDayDto.Absent = courseDay.Absent; courseDayDto.Allpresence = courseDay.Allpresence; if (courseDayDto.Student != null) { courseDayDto.Student.Id = courseDay.Student.Id; } if (courseDayDto.Course != null) { courseDayDto.Course.Id = courseDay.Course.Id; } return(courseDayDto); }
[TestMethod] //testowanie dnia obecnosci public void CourseDayDtoMapping_ProvideValidCourseDayDto_ReciveProperlyMappedCourseDay() { CourseDayDto courseDayDto = new CourseDayDto(); courseDayDto.Present = 1; courseDayDto.Absent = 1; courseDayDto.Allpresence = 2; StudentDto studentDto = new StudentDto(); studentDto.Id = 1; studentDto.Name = "Kuba"; studentDto.Surname = "Gerlee"; studentDto.Pesel = 94; studentDto.DateOfBirth = new DateTime(09 / 03 / 1994); studentDto.Sex = 1; courseDayDto.Student = studentDto; CourseDto courseDto = new CourseDto(); courseDto.Id = 1; courseDto.CourseTitle = "Matematyka"; courseDto.DateStart = new DateTime(2017 / 10 / 10); courseDto.PresenceThreshold = 70; courseDto.HomeworkThreshold = 70; courseDto.Teacher = "Kasia Gerlee"; courseDayDto.Course = courseDto; CourseDay courseDay = new CourseDay(); courseDay.Present = 1; courseDay.Absent = 1; courseDay.Allpresence = 2; Student student = new Student(); student.Id = 1; student.Name = "Kuba"; student.Surname = "Gerlee"; student.Pesel = 94; student.DateOfBirth = new DateTime(09 / 03 / 1994); student.Sex = 1; courseDay.Student = student; Course course = new Course(); course.Id = 1; course.CourseTitle = "Matematyka"; course.DateStart = new DateTime(2017 / 10 / 10); course.HomeworkThreshold = 70; course.PresenceThreshold = 70; course.Teacher = "Kasia Gerlee"; courseDay.Course = course; var resultOfMapping = Register.Business.Layer.Mappers.DtoToEntityMapper.CourseDayDtoToModelEntity(courseDayDto); Assert.AreEqual(courseDay.Present, resultOfMapping.Present); Assert.AreEqual(courseDay.Absent, resultOfMapping.Absent); Assert.AreEqual(courseDay.Allpresence, resultOfMapping.Allpresence); Assert.AreEqual(courseDay.Id, resultOfMapping.Id); Equals(courseDay, resultOfMapping); }
public void CourseDayMapping_ProvideValidCourseDay_ReceiveProperlyMappedCourseDayDto() { //PRZYPADEK 1 CourseDayDto courseDayDto = new CourseDayDto(); courseDayDto.Present = 1; courseDayDto.Absent = 1; courseDayDto.Allpresence = 2; courseDayDto.Student = null; courseDayDto.Course = null; CourseDay courseDay = new CourseDay(); courseDay.Present = 1; courseDay.Absent = 1; courseDay.Allpresence = 2; courseDay.Student = null; courseDay.Course = null; //PRZYPADEK 2 CourseDayDto courseDayDto2 = new CourseDayDto(); courseDayDto2.Present = 1; courseDayDto2.Absent = 1; courseDayDto2.Allpresence = 2; StudentDto studentDto2 = new StudentDto(); studentDto2.Id = 1; studentDto2.Name = "Kuba"; studentDto2.Surname = "Gerlee"; studentDto2.Pesel = 94; studentDto2.DateOfBirth = new DateTime(09 / 03 / 1994); studentDto2.Sex = 1; courseDayDto2.Student = studentDto2; CourseDto courseDto = new CourseDto(); courseDto.Id = 1; courseDto.CourseTitle = "Matematyka"; courseDto.DateStart = new DateTime(2017 / 10 / 10); courseDto.PresenceThreshold = 70; courseDto.HomeworkThreshold = 70; courseDto.Teacher = "Kasia Gerlee"; courseDayDto2.Course = courseDto; CourseDay courseDay2 = new CourseDay(); courseDay2.Present = 1; courseDay2.Absent = 1; courseDay2.Allpresence = 2; Student student = new Student(); student.Id = 1; student.Name = "Kuba"; student.Surname = "Gerlee"; student.Pesel = 94; student.DateOfBirth = new DateTime(09 / 03 / 1994); student.Sex = 1; courseDay2.Student = student; Course course = new Course(); course.Id = 1; course.CourseTitle = "Matematyka"; course.DateStart = new DateTime(2017 / 10 / 10); course.HomeworkThreshold = 70; course.PresenceThreshold = 70; course.Teacher = "Kasia Gerlee"; courseDay2.Course = course; //Przypadek 3 CourseDay courseDay3 = new CourseDay(); courseDay3 = null; CourseDayDto courseDayDto3 = new CourseDayDto(); courseDayDto3 = null; var entityToDtoMapper = new EntityToDtoMapper(); var resultOfMapping = entityToDtoMapper.CourseDayModelToDto(courseDay); var resultOfMapping2 = entityToDtoMapper.CourseDayModelToDto(courseDay2); var resultOfMapping3 = entityToDtoMapper.CourseDayModelToDto(courseDay3); Equals(courseDayDto, resultOfMapping); Equals(courseDayDto2, resultOfMapping2); Assert.AreEqual(courseDayDto3, resultOfMapping3); }