示例#1
0
        public void TestAttemptConstructorTest()
        {
            testAttempt = new TestAttempt();

            Assert.NotNull(testAttempt);
            Assert.IsType <TestAttempt>(testAttempt);
        }
示例#2
0
        ///-------------------------------------------------------------------------------------------------
        /// <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);
        }
示例#3
0
        public void TestIsPassFalseTest()
        {
            testAttempt = new TestAttempt()
            {
                IsPass = testPassFalse
            };

            Assert.False(testAttempt.IsPass);
        }
示例#4
0
        public void TestIsPassTrueTest()
        {
            testAttempt = new TestAttempt()
            {
                IsPass = testPassTrue
            };

            Assert.True(testAttempt.IsPass);
        }
示例#5
0
        public async Task <IActionResult> Update([FromBody] TestAttempt testAttempt)
        {
            var result = await _testAttemptCrudService.UpdateAsync(testAttempt);

            if (result)
            {
                return(Ok());
            }
            return(NotFound());
        }
示例#6
0
        public async Task <IActionResult> SaveAttempt(Guid userId, TestAttempt attempt)
        {
            var result = await _service.SaveAttempt(userId, attempt);

            if (result)
            {
                return(Ok());
            }

            return(BadRequest());
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        public async Task <IActionResult> Create([FromBody] TestAttempt testAttempt)
        {
            await _testAttemptCrudService.CreateAsync(testAttempt);

            return(Ok());
        }
示例#12
0
        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));
 }