public void SetUp() { _attemptService = new Mock <ICrudInterface <AttemptDto> >(); _attemptController = new AttemptController(_attemptService.Object); _attempt = new AttemptDto { Id = "attempt1", DateTime = DateTime.Now, Score = 100, StudentId = "student1", TopicId = "topic1" }; }
public static Attempt AdaptToAttempt(this AttemptDto p1) { return(p1 == null ? null : new Attempt() { StudentId = p1.StudentId, TopicId = p1.TopicId, Score = p1.Score, DateTime = p1.DateTime, Id = p1.Id }); }
public async Task <ActionResult> Update(AttemptDto attemptDto) { try { await _attemptService.UpdateEntity(attemptDto); } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok()); }
public async Task <ActionResult> Create([FromBody] AttemptDto attemptDto) { try { await _attemptService.CreateEntityAsync(attemptDto); } catch (Exception e) { return(BadRequest(e.Message)); } return(CreatedAtAction(nameof(Create), new { attemptDto.Id }, attemptDto)); }
public static AttemptDto AdaptTo(this Attempt p6, AttemptDto p7) { if (p6 == null) { return(null); } AttemptDto result = p7 ?? new AttemptDto(); result.StudentId = p6.StudentId; result.TopicId = p6.TopicId; result.Score = p6.Score; result.DateTime = p6.DateTime; result.Id = p6.Id; return(result); }
public static Attempt AdaptTo(this AttemptDto p2, Attempt p3) { if (p2 == null) { return(null); } Attempt result = p3 ?? new Attempt(); result.StudentId = p2.StudentId; result.TopicId = p2.TopicId; result.Score = p2.Score; result.DateTime = p2.DateTime; result.Id = p2.Id; return(result); }
public async Task <ActionResult <AttemptDto> > PostAttempt([FromRoute] int id, [FromBody] CreateAttemptCommand command) { if (id != command.TopicId) { return(BadRequestNonMatchingIds()); } if (command.UserId != _IdentityService.GetCurrentUserId()) { return(Forbid()); } AttemptDto result = await _Mediator.Send(command); return(Ok(result)); }
public AttemptDto SubmitAttempt(AttemptDto attemptDto, string userId) { if (_attemptRepository.GetAttempt(attemptDto.QuestionId, userId) != null) { //user cannot submit attempt for same question multiple times. return(null); } var attempt = _mapper.Map <Attempt>(attemptDto); var score = _attemptScoreCalculator.CalculateScore(attempt); attempt.UserId = userId; attempt.Score = score; _attemptRepository.InsertAttempt(attempt); return(_mapper.Map <AttemptDto>(attempt)); }
public async Task AttemptController_Create_CreatesAttempt() { var updatedAttempt = new AttemptDto { Id = "attempt2", DateTime = DateTime.Now, Score = 32, StudentId = "1", TopicId = "topic1" }; var payload = JsonConvert.SerializeObject(updatedAttempt); var content = new StringContent(payload, Encoding.UTF8, "application/json"); var httpResponse = await _client.PostAsync(RequestUri, content); var actual = await _client.GetAsync(RequestUri + "attempt2"); httpResponse.EnsureSuccessStatusCode(); var stringActualResponse = await actual.Content.ReadAsStringAsync(); var attempt = JsonConvert.DeserializeObject <AttemptDto>(stringActualResponse); attempt.Id.Should().Be("attempt2"); attempt.Score.Should().Be(32); }
public AttemptDto CreateAttempt(AttemptDto attemptDto) { return(_attemptSubmissionManager.SubmitAttempt(attemptDto, UserId)); }