public void TestAttemptConstructorTest() { testAttempt = new TestAttempt(); Assert.NotNull(testAttempt); Assert.IsType <TestAttempt>(testAttempt); }
///------------------------------------------------------------------------------------------------- /// <summary> Saves a test result and calculates if the test is a pass or fail. </summary> /// /// <param name="sectionResults"> The section results. </param> /// <param name="testID"> Identifier for the test. </param> /// <param name="applicant"> The applicant. </param> ///------------------------------------------------------------------------------------------------- public void SaveTestResults(List <double> sectionResults, int testID, AppUser applicant) { var tempAppUser = db.Users.SingleOrDefault(user => user.Email == applicant.Email); bool testPass = false; int sectionPassCount = 0; for (int i = 0; i < sectionResults.Count(); i++) { if (sectionResults[i] >= 50) { sectionPassCount++; } } if (sectionPassCount == 3) { testPass = true; } TestAttempt testAttempt = new TestAttempt() { AppUserID = tempAppUser.Id, TestID = testID, Section1Result = sectionResults.ElementAt(0), Section2Result = sectionResults.ElementAt(1), Section3Result = sectionResults.ElementAt(2), IsPass = testPass }; db.TestAttempts.Add(testAttempt); }
public void TestIsPassFalseTest() { testAttempt = new TestAttempt() { IsPass = testPassFalse }; Assert.False(testAttempt.IsPass); }
public void TestIsPassTrueTest() { testAttempt = new TestAttempt() { IsPass = testPassTrue }; Assert.True(testAttempt.IsPass); }
public async Task <IActionResult> Update([FromBody] TestAttempt testAttempt) { var result = await _testAttemptCrudService.UpdateAsync(testAttempt); if (result) { return(Ok()); } return(NotFound()); }
public async Task <IActionResult> SaveAttempt(Guid userId, TestAttempt attempt) { var result = await _service.SaveAttempt(userId, attempt); if (result) { return(Ok()); } return(BadRequest()); }
public async Task AddUserAttempt(Guid userId, Guid testId) { var allUsers = await _userRepository.GetAllAsync(); var user = allUsers.First(x => x.Id == userId); var attempt = new TestAttempt { TestGrade = 0, TestId = testId, TestState = TestState.NotDone, UserId = user.Id }; await _tempAttemptRepository.CreateAsync(attempt); }
public void TestAttemptPropertiesTest() { testAttempt = new TestAttempt() { ID = validTestAttemptID, AppUserID = validAppUserID, TestID = validTestID, Section1Result = validSection1Result, Section2Result = validSection2Result, Section3Result = validSection3Result, }; Assert.Equal(validTestID, testAttempt.ID); Assert.Equal(validAppUserID, testAttempt.AppUserID); Assert.Equal(validTestID, testAttempt.TestID); Assert.Equal(validSection1Result, testAttempt.Section1Result); Assert.Equal(validSection2Result, testAttempt.Section2Result); Assert.Equal(validSection3Result, testAttempt.Section3Result); }
public async Task <bool> UpdateAsync(TestAttempt obj) { var testAttempt = await _context.TestAttempts.FindAsync(obj.Id); if (testAttempt == null) { return(false); } testAttempt.TestGrade = obj.TestGrade; testAttempt.TestId = obj.TestId; testAttempt.TestState = obj.TestState; testAttempt.UserId = obj.UserId; _context.TestAttempts.Update(testAttempt); await _context.SaveChangesAsync(); return(true); }
public async Task <bool> SaveAttempt(Guid userId, TestAttempt attempt) { var allAttempts = await _tempAttemptRepository.GetAllAsync(); var at = allAttempts.First(x => x.Id == attempt.Id); if (at.UserId != userId) { return(false); } at.TestState = attempt.TestState; at.TestGrade = attempt.TestGrade; at.TestId = attempt.TestId; await _tempAttemptRepository.UpdateAsync(at); return(true); }
public async Task <IActionResult> Create([FromBody] TestAttempt testAttempt) { await _testAttemptCrudService.CreateAsync(testAttempt); return(Ok()); }
public async Task CreateAsync(TestAttempt obj) { await _context.TestAttempts.AddAsync(obj); await _context.SaveChangesAsync(); }
public async Task CreateAsync(TestAttempt testAttempt) { await _testAttemptRepository.CreateAsync(testAttempt); }
public async Task <bool> UpdateAsync(TestAttempt testAttempt) { return(await _testAttemptRepository.UpdateAsync(testAttempt)); }