public void Setup() { this._student = StudentTestUtils.GetStudent(); this._studentDetailsDto = StudentTestUtils.GetStudentDetailsDto(this._student.Id); this._studentCreationDto = StudentTestUtils.GetStudentCreationDto(); this._studentMapper = new StudentMapper(); }
public void Cleanup() { this._student = null; this._studentDetailsDto = null; this._studentCreationDto = null; this._studentMapper = null; }
public string Handle(CreateStudentCommand request) { try { var student = new Student(request.FirstName, request.LastName, request.BirthDate, request.Gpi); _context.Student.Add(student); _context.SaveChanges(); var studentDetails = new StudentDetailsDto(student.Id, student.FirstName, student.LastName, student.BirthDate, student.Gpi); _context.StudentDetails.Add(studentDetails); _context.SaveChangesAsync(); return("succeded"); } catch (DbEntityValidationException exception) { return(exception.GetValidations()); } catch (Exception exception) { return(exception.Message); } }
public async Task <StudentDetailsDto> DetailsAsync(int?id) { Validator.IsIntegerBiggerThanZero(id); var dbQueryEntiti = await this.dbContext.Students .Include(s => s.Enrollments) .Include("Enrollments.Course") .AsNoTracking() .FirstOrDefaultAsync(m => m.Id == id); Validator.IsObjectNull(dbQueryEntiti); var serviceDto = new StudentDetailsDto() { Id = dbQueryEntiti.Id, EnrollmentDate = dbQueryEntiti.EnrollmentDate, FirstMidName = dbQueryEntiti.FirstMidName, LastName = dbQueryEntiti.LastName, Enrollments = dbQueryEntiti.Enrollments.Select(e => new EnrollmentsDto() { Course_Title = e.Course.Title, Enrolment_Grade = e.Grade.ToString() }).ToList() }; return(serviceDto); }
public async Task <IActionResult> GetStudentDetails(int studentId) { StudentDetailsDto studentDetailsDto = await _studentService.GetStudentDetailsAsync(studentId); StudentDetailsModel studentDetailsModel = _mapper.Map <StudentDetailsModel>(studentDetailsDto); return(Ok(studentDetailsModel)); }
public async Task GetDetailsDtoById_ShouldReturnInstanceOfStudentDetailsDto() { // Arrange _mockReadRepository.Setup(repo => repo.GetByIdAsync <Student>(_student1.Id)).ReturnsAsync(_student1); _mockStudentMapper.Setup(mapper => mapper.Map(_student1)).Returns(_studentDto1); // Act StudentDetailsDto actualStudent = await _studentService.GetDetailsDtoById(_student1.Id); // AssertB actualStudent.Should().BeEquivalentTo(_studentDto1); }
public async Task Create_ShouldReturnInstanceOfStudentDetailsDto() { // Arrange _mockStudentMapper.Setup(mapper => mapper.Map(_student1)).Returns(_studentDto1); _mockStudentMapper.Setup(mapper => mapper.Map(_studentCreationDto)).Returns(_student1); _mockWriteRepository.Setup(repo => repo.AddNewAsync <Student>(_student1)).Returns(() => Task.FromResult(_student1)); // Act StudentDetailsDto actualStudent = await _studentService.Create(_studentCreationDto); // Assert actualStudent.Should().BeEquivalentTo(_studentDto1); }
public void TestInitialize() { this._student1 = StudentTestUtils.GetStudent(); this._student2 = StudentTestUtils.GetStudent(); this._studentDto1 = StudentTestUtils.GetStudentDetailsDto(_student1.Id); this._studentDto2 = StudentTestUtils.GetStudentDetailsDto(_student2.Id); this._studentCreationDto = StudentTestUtils.GetStudentCreationDto(); this._mockReadRepository = new Mock <IReadRepository>(); this._mockWriteRepository = new Mock <IWriteRepository>(); this._mockStudentMapper = new Mock <IStudentMapper>(); _studentService = new StudentService(_mockReadRepository.Object, _mockWriteRepository.Object, _mockStudentMapper.Object); }
public async Task GetStudentById_ShouldReturnStudentWithGivenId() { //Act var response = await client.GetAsync("api/students/" + student1.Id); //Assert response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); StudentDetailsDto studentDetailsDtoReturned = JsonConvert.DeserializeObject <StudentDetailsDto>(responseString); studentDetailsDtoReturned.Should().BeEquivalentTo(studentDetailsDto1); }
public void Setup() { client = new CustomWebApplicationFactory <Startup>().CreateClient(); student1 = StudentTestUtils.GetStudent(); student2 = StudentTestUtils.GetStudent2(); studentDetailsDto1 = StudentTestUtils.GetStudentDetailsDto(student1.Id); studentDetailsDto2 = StudentTestUtils.GetStudentDetailsDto(student2.Id); studentCreationDto = StudentTestUtils.GetStudentCreationDto(); course1 = CourseTestUtils.GetCourse(); course2 = CourseTestUtils.GetCourse2(); courseDetailsDto = CourseTestUtils.GetCourseDetailsDto(course1.Id); studentCourseCreationDto = StudentCourseTestUtils.GetStudentCourseCreationDto(course2.Id); }
public StudentModel Prepare(StudentDetailsDto details, List <Course> courses) { var model = new StudentModel(); Id = details.StudentId; FirstName = details.FirstName; LastName = details.LastName; BirthDate = details.BirthDate; if (courses?.Any() ?? true) { model.CourseModel = courses.Select(course => new StudentCourseModel() { CourseName = course.Name }).ToList(); } return(model); }
public async Task PostStudent_ShouldReturnStudentCreatedFromGivenBody() { //Arrange var contents = new StringContent(JsonConvert.SerializeObject(studentCreationDto), Encoding.UTF8, "application/json"); //Act var response = await client.PostAsync("api/students", contents); //Assert response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); StudentDetailsDto studentsDetailsDtoReturned = JsonConvert.DeserializeObject <StudentDetailsDto>(responseString); studentsDetailsDtoReturned.Should().BeEquivalentTo(studentCreationDto, options => options.ExcludingMissingMembers()); }
public async Task <StudentDetailsDto> GetStudentDetailsAsync(int studentId) { Expression <Func <Student, StudentDetailsDto> > selectExpression = e => new StudentDetailsDto { StudentId = e.StudentId, StudentName = e.StudentName, CountryId = e.CountryId, CountryName = e.Country.CountryName, DateOfBirth = e.DateOfBirth, Email = e.Email, PhoneNumber = e.PhoneNumber, SpokenLanguage = e.SpokenLanguage, IsActive = e.IsActive, CreatedAtUtc = e.CreatedAtUtc, LastModifiedAtUtc = e.LastModifiedAtUtc }; StudentDetailsDto studentDetailsDto = await _unitOfWork.Repository <Student>() .GetProjectedEntityByIdAsync(studentId, selectExpression); return(studentDetailsDto); }
protected override async Task OnInitAsync() { Student = await Client.GetDetails(StudentId); StateHasChanged(); }
public StudentDetailsViewModel(StudentDetailsDto student) { Student = student; Title = $"Student - {student.FirstName} {student.LastName}"; }