예제 #1
0
 public async Task <IActionResult> SetTestCopiedNumberAsync([FromRoute] string testName)
 {
     return(Ok(await _testRepository.SetTestCopiedNumberAsync(testName)));
 }
예제 #2
0
        public async Task DuplicateTest()
        {
            var category1         = CreateCategory("Aptitude");
            var questiontoCreate1 = "Question1";
            var question1         = CreateSingleAnswerQuestion(category1, questiontoCreate1);
            var category2         = CreateCategory("Logical");
            var questiontoCreate2 = "Question2";
            var question2         = CreateSingleAnswerQuestion(category1, questiontoCreate2);
            var oldTest           = CreateTest("Maths");
            var testIp            = new TestIpAddress();

            testIp.IpAddress = "127.0.0.1";
            testIp.TestId    = oldTest.Id;
            string          userName = "******";
            ApplicationUser user     = new ApplicationUser()
            {
                Email = userName, UserName = userName
            };
            await _userManager.CreateAsync(user);

            var applicationUser = await _userManager.FindByEmailAsync(user.Email);

            await _testRepository.CreateTestAsync(oldTest, applicationUser.Id);

            var testCategoryObject1 = new TestCategory()
            {
                CategoryId = category1.Id,
                TestId     = oldTest.Id,
                Test       = oldTest
            };
            var testCategoryObject2 = new TestCategory()
            {
                CategoryId = category2.Id,
                TestId     = oldTest.Id,
                Test       = oldTest
            };
            var testCategoryList = new List <TestCategory>();

            testCategoryList.Add(testCategoryObject1);
            testCategoryList.Add(testCategoryObject2);
            await _trappistDbContext.TestCategory.AddRangeAsync(testCategoryList);

            var testQuestionObject1 = new TestQuestion()
            {
                QuestionId = question1.Id,
                TestId     = oldTest.Id,
                Test       = oldTest,
            };
            var testQuestionObject2 = new TestQuestion()
            {
                QuestionId = question2.Id,
                TestId     = oldTest.Id,
                Test       = oldTest,
            };
            var testQuestionList = new List <TestQuestion>();

            testQuestionList.Add(testQuestionObject1);
            testQuestionList.Add(testQuestionObject2);
            await _trappistDbContext.TestQuestion.AddRangeAsync(testQuestionList);

            var testIpAddressObject = new TestIpAddress()
            {
                Test      = oldTest,
                TestId    = oldTest.Id,
                IpAddress = testIp.IpAddress
            };
            var testIpList = new List <TestIpAddress>();

            testIpList.Add(testIpAddressObject);
            await _trappistDbContext.TestIpAddresses.AddRangeAsync(testIpList);

            var newTest = CreateTest("Maths_Copy");
            await _testRepository.CreateTestAsync(newTest, applicationUser.Id);

            await _testRepository.DuplicateTest(oldTest.Id, newTest);

            var count = await _testRepository.SetTestCopiedNumberAsync(oldTest.TestName);

            Assert.Equal(4, _trappistDbContext.TestQuestion.Count());
            Assert.Equal(4, _trappistDbContext.TestCategory.Count());
            Assert.Equal(2, _trappistDbContext.TestIpAddresses.Count());
            Assert.Equal(1, count);
        }