Beispiel #1
0
        public async Task TestTakeQuiz()
        {
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "*****@*****.**"),
                new Claim(ClaimTypes.Email, "*****@*****.**")
            }, "mock"));


            var quiz = new ProProfQuiz()
            {
                Id = "1", QuizLink = "Test", QuizName = "Test", QuizUniqueName = "test"
            };

            _mockRepository.Setup(x => x.GetQuizByUniqeName("test")).ReturnsAsync(quiz);
            _mockUserRepository.Setup(x => x.GetUser("*****@*****.**")).ReturnsAsync(new ProProfsUser()
            {
                Email = "*****@*****.**", Password = "******"
            });
            var controller = new QuizController(_mockRepository.Object, _mockUserRepository.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user
                }
            };
            var quizs = await controller.Take("test");

            Assert.Equal($"https://www.proprofs.com/quiz-school/story.php?title=test&[email protected]&passkey=Test", quizs.QuizLink);
        }
Beispiel #2
0
        public async Task TestSaveQuiz()
        {
            // Arrange
            var request = new
            {
                Url = "/api/Account/Userprofile"
            };

            // Act
            var response = await Client.GetAsync(request.Url);

            var json = await response.Content.ReadAsStringAsync();

            var singleResponse = JsonConvert.DeserializeObject <UserProfile>(json);

            UserAccessToken = singleResponse.UserAccessToken;
            request         = new
            {
                Url = "/api/Quiz"
            };

            Client.DefaultRequestHeaders.Authorization
                = new AuthenticationHeaderValue("Bearer", UserAccessToken);
            var getallresponse = await Client.GetAsync(request.Url);

            var output = await getallresponse.Content.ReadAsStringAsync();

            var data = JsonConvert.DeserializeObject <IList <ProProfQuiz> >(output);
            var quiz = new ProProfQuiz();

            quiz.Id       = Guid.NewGuid().ToString();
            quiz.QuizName = "Test Quiz";
            quiz.QuizLink = "Test Quiz Link";
            var input            = JsonConvert.SerializeObject(quiz);
            var httpContent      = new StringContent(input, Encoding.UTF8, "application/json");
            var sqveQuizResponse = await Client.PostAsync(request.Url, httpContent);

            getallresponse = await Client.GetAsync(request.Url);

            output = await getallresponse.Content.ReadAsStringAsync();

            var data1 = JsonConvert.DeserializeObject <IList <ProProfQuiz> >(output);

            request = new
            {
                Url = $"/api/Quiz/{quiz.Id}"
            };
            getallresponse = await Client.GetAsync(request.Url);

            output = await getallresponse.Content.ReadAsStringAsync();

            var quizouput = JsonConvert.DeserializeObject <ProProfQuiz>(output);

            // Assert
            Assert.Equal(System.Net.HttpStatusCode.OK, sqveQuizResponse.StatusCode);
            Assert.True(data1.Count > data.Count);
            Assert.True(quizouput.QuizLink == quiz.QuizLink);
        }
Beispiel #3
0
        public async Task TestPostQuiz()
        {
            var quiz = new ProProfQuiz()
            {
                Id = "1", QuizLink = "Test", QuizName = "Test"
            };

            _mockRepository.Setup(x => x.SaveQuiz(quiz)).ReturnsAsync(quiz);
            var controller = new QuizController(_mockRepository.Object, _mockUserRepository.Object);
            var quizs      = await controller.Post(quiz);

            Assert.Equal(quiz, quizs);
        }
Beispiel #4
0
        public virtual async Task <ProProfQuiz> SaveQuiz(ProProfQuiz quiz)
        {
            var quizzes      = this.DataContext.Quizzes.Find(x => x.Id == quiz.Id);
            var existingQuiz = await quizzes.FirstOrDefaultAsync();

            if (existingQuiz != null)
            {
                FilterDefinition <ProProfQuiz> filter = Builders <ProProfQuiz> .Filter.Where(q => q.Id == quiz.Id);

                await this.DataContext.Quizzes.ReplaceOneAsync(filter, quiz);

                return(quiz);
            }
            else
            {
                await this.DataContext.Quizzes.InsertOneAsync(quiz);

                return(quiz);
            }
        }
 public async Task <ProProfQuiz> Post([FromBody] ProProfQuiz quiz)
 {
     return(await this.quizReporitory.SaveQuiz(quiz));
 }