Example #1
0
 private void DecreaseNumberOfRuns(TestingUrl testingUrl)
 {
     if (testingUrl.NumberOfRuns <= 0)
     {
         return;
     }
     testingUrl.NumberOfRuns--;
     _testingRepository.Update(testingUrl);
 }
 private void DecreaseNumberOfRuns(TestingUrl testingUrl)
 {
     if (testingUrl.NumberOfRuns <= 0)
     {
         return;
     }
     if (testingUrl.NumberOfRuns == 1)
     {
         testingUrl.NumberOfRuns = testingUrl.NumberOfRuns - 2;
     }
     else
     {
         testingUrl.NumberOfRuns--;
     }
     _testingRepository.Update(testingUrl);
 }
        public TestingUrlViewModel MapTestingUrl(TestingUrl testingUrl)
        {
            var testingUrlViewModel = new TestingUrlViewModel
            {
                AllowedStartDate = testingUrl.AllowedStartDate?.ToString("MM/dd/yyyy HH:mm:ss") ?? "No restrictions",
                AllowedEndDate   = testingUrl.AllowedEndDate?.ToString("MM/dd/yyyy HH:mm:ss") ?? "No restrictions",
                Guid             = testingUrl.Guid,
                Interviewee      = testingUrl.Interviewee,
                IsValid          = _advancedLogicService.IsTestValid(testingUrl.Test),
                TestGuid         = testingUrl.Test.Guid,
                NumberOfRuns     = testingUrl.NumberOfRuns,
                TestName         = testingUrl.Test.Name
            };

            return(testingUrlViewModel);
        }
 public string CheckTestingUrlForAvailability(TestingUrl testingUrl)
 {
     if (testingUrl.AllowedStartDate != null && testingUrl.AllowedStartDate.Value > DateTime.Now)
     {
         return("Test is not available yet. Try it on " + testingUrl.AllowedStartDate);
     }
     if (testingUrl.AllowedEndDate != null && testingUrl.AllowedEndDate.Value < DateTime.Now)
     {
         return("Test is not available already. It was till " + testingUrl.AllowedEndDate);
     }
     if (testingUrl.NumberOfRuns < 0)
     {
         return("Test was already run too many times");
     }
     if (!IsTestValid(testingUrl.Test))
     {
         return("Testing is invalid, please contact administrator!");
     }
     return("");
 }
 public void StartQuiz(TestingUrl testingUrl, string attemptGuid)
 {
     DecreaseNumberOfRuns(testingUrl);
     _startedQuizzes.TryAdd(attemptGuid, DateTime.Now);
 }
Example #6
0
 public void CreateTestingUrl(TestingUrl testingUrl)
 {
     _testingRepository.Add(testingUrl);
 }
        protected override void Seed(TestingContext context)
        {
            //Add admin user
            context.Users.Add(new User {
                UserId = 1, Username = "******", Password = "******"
            });

            //Add few questions
            var question = new TestQuestion
            {
                TestId = 1, TestQuestionId = 1, Instance = "What is the main paradigm of Java?", Hint = "Classes bro", Guid = Guid.NewGuid().ToString()
            };

            question.TestAnswers = new List <TestAnswer> {
                new TestAnswer {
                    TestAnswerId = 1, Instance = "Object oriented", IsCorrect = true, TestQuestion = question
                },
                new TestAnswer {
                    TestAnswerId = 2, Instance = "Functional", IsCorrect = false, TestQuestion = question
                },
                new TestAnswer {
                    TestAnswerId = 3, Instance = "Aspect oriented", IsCorrect = false, TestQuestion = question
                }
            };

            var question2 = new TestQuestion
            {
                TestId = 1, TestQuestionId = 2, Instance = "When was Angular 2 released?", Hint = "Not so far...", Guid = Guid.NewGuid().ToString()
            };

            question2.TestAnswers = new List <TestAnswer>
            {
                new TestAnswer {
                    TestAnswerId = 4, Instance = "in 2010", IsCorrect = false, TestQuestion = question2
                },
                new TestAnswer {
                    TestAnswerId = 5, Instance = "in 2016", IsCorrect = true, TestQuestion = question2
                },
                new TestAnswer {
                    TestAnswerId = 6, Instance = "in 2012", IsCorrect = false, TestQuestion = question2
                }
            };

            var question3 = new TestQuestion
            {
                TestId = 1, TestQuestionId = 3, Instance = "Which of these ways are available for transfering data from controller to view in ASP.MVC?",
                Hint   = "Test question hint", Guid = Guid.NewGuid().ToString()
            };

            question3.TestAnswers = new List <TestAnswer>
            {
                new TestAnswer {
                    TestAnswerId = 7, Instance = "via ViewBag", IsCorrect = true, TestQuestion = question3
                },
                new TestAnswer {
                    TestAnswerId = 8, Instance = "via Model", IsCorrect = true, TestQuestion = question3
                },
                new TestAnswer {
                    TestAnswerId = 9, Instance = "via ActionResult", IsCorrect = false, TestQuestion = question3
                },
                new TestAnswer {
                    TestAnswerId = 10, Instance = "via ViewData", IsCorrect = true, TestQuestion = question3
                }
            };

            var test = new Test {
                TestId = 1, Name = "Default test", TestTimeLimit = new TimeSpan(0, 1, 00), QuestionTimeLimit = new TimeSpan(0, 0, 30), Description = "Default description"
            };

            test.TestQuestions.Add(question);
            test.TestQuestions.Add(question2);
            test.TestQuestions.Add(question3);


            var testingUrl = new TestingUrl
            {
                AllowedStartDate = DateTime.Now,
                AllowedEndDate   = DateTime.Now + TimeSpan.FromDays(10),
                Guid             = Guid.NewGuid().ToString(),
                Interviewee      = "My user",
                NumberOfRuns     = 200,
                Test             = test,
                TestingUrlId     = 1
            };

            //context.TestQuestions.Add(question);
            //context.Tests.Add(test);
            context.TestingUrls.Add(testingUrl);
            base.Seed(context);
        }