Exemple #1
0
        public void Add_question_to_database()
        {
            var options = new DbContextOptionsBuilder <QuizDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_question_to_database")
                          .Options;

            using (var context = new QuizDbContext(options))
            {
                var      service = new QuestionService(context);
                Question q1      = new Question {
                    Content = "AAA", QuizID = 12, Id = 1
                };
                Question q2 = new Question {
                    Content = "BBB", QuizID = 13, Id = 2
                };

                service.CreateQuestion(q1);
                service.CreateQuestion(q2);
            }

            using (var context = new QuizDbContext(options))
            {
                var numberOfQuestionsInDb = context.Question.Count();
                numberOfQuestionsInDb.Should().Be(2);
            }
        }
Exemple #2
0
        public void Add_quiz_to_database()
        {
            var options = new DbContextOptionsBuilder <QuizDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_quiz_to_database")
                          .Options;

            using (var context = new QuizDbContext(options))
            {
                var  service = new QuizService(context);
                Quiz q1      = new Quiz {
                    Name = "AAA", Id = 1
                };
                Quiz q2 = new Quiz {
                    Name = "BBB", Id = 2
                };

                service.CreateQuiz(q1);
                service.CreateQuiz(q2);
            }

            using (var context = new QuizDbContext(options))
            {
                var numberOfQuizesInDb = context.Quiz.Count();
                numberOfQuizesInDb.Should().Be(2);
            }
        }
Exemple #3
0
 public QuizUserControllerBase(
     QuizDbContext <IdType, FormType, QuestionType, RecordType, WritedType> dbContext,
     IAuthorizationProvider authProvider
     ) : base(dbContext)
 {
     this.AuthorizationProvider = authProvider;
 }
Exemple #4
0
 public EmployeeRepository(QuizDbContext dbContext, UserManager <EmployeeAuthentication> userManager, SignInManager <EmployeeAuthentication> signInManager, IConfiguration configuration)
 {
     _dbContext     = dbContext;
     _userManager   = userManager;
     _signInManager = signInManager;
     _configuration = configuration;
 }
        public void Add_answer_to_database()
        {
            var options = new DbContextOptionsBuilder <QuizDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_answer_to_database")
                          .Options;

            using (var context = new QuizDbContext(options))
            {
                var    service = new AnswerService(context);
                Answer a1      = new Answer {
                    Content = "AAA", Id = 1, QuestionID = 12
                };
                Answer a2 = new Answer {
                    Content = "BBB", Id = 2, QuestionID = 13
                };

                service.CreateAnswer(a1);
                service.CreateAnswer(a2);
            }

            using (var context = new QuizDbContext(options))
            {
                var numberOfAnserwsInDb = context.Answer.Count();
                numberOfAnserwsInDb.Should().Be(2);
            }
        }
Exemple #6
0
        public async void DbTest()
        {
            using (var db = new QuizDbContext(_testFixture.DbOptions))
            {
                var count = db.Quizzes.Count();
                Assert.Equal(16, count);

                var firstQuiz = await db.Quizzes
                                .Include(q => q.Questions)
                                .ThenInclude(q => q.Answers)
                                .ThenInclude(a => a.AnswerOutcomes)
                                .FirstAsync();

                Assert.NotNull(firstQuiz);
                Assert.Equal("Quiz Number 0", firstQuiz.Title);

                var firstQuestion = firstQuiz.Questions.First();
                Assert.Equal("What is question number 0?", firstQuestion.Text);

                var firstAnswer = firstQuestion.Answers.First();
                Assert.Equal("Answer number 0", firstAnswer.Text);

                var answerOutcome = firstAnswer.AnswerOutcomes.First();
                Assert.NotNull(answerOutcome);
            }
        }
 public ManageQuizController(
     QuizDbContext context,
     IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Exemple #8
0
        public QuestionService()
        {
            var options = new DbContextOptionsBuilder <QuizDbContext>()
                          .UseInMemoryDatabase("Quiz")
                          .Options;

            _context = new QuizDbContext(options);
        }
Exemple #9
0
 public AnswerController(QuizDbContext db, IAnswerService answerService, IStorageService storageService,
                         IPhotoService photoService, IMapper mapper)
 {
     _db             = db;
     _answerService  = answerService;
     _storageService = storageService;
     _photoService   = photoService;
     _mapper         = mapper;
 }
Exemple #10
0
 public AdminController(
     UserManager <IdentityUser> userManager,
     IdentityDbContext identityContext,
     QuizDbContext context)
 {
     this.userManager     = userManager;
     this.identityContext = identityContext;
     this.context         = context;
 }
 public QuizController(
     QuizDbContext context,
     IMapper mapper,
     IQuizChecker quizChecker)
 {
     _context     = context;
     _mapper      = mapper;
     _quizChecker = quizChecker;
 }
Exemple #12
0
 public void SetUp()
 {
     _validator = new Mock <AbstractValidator <AnswerDto> >();
     _validator.Setup(validator => validator.ValidateAsync(It.IsAny <ValidationContext <AnswerDto> >(), It.IsAny <CancellationToken>()))
     .ReturnsAsync(new ValidationResult());
     _context = new QuizDbContext(UnitTestsHelper.GetUnitTestDbOptions());
     _helper  = new Mock <IServiceHelper <Answer> >();
     _service = new AnswerService(_context, _helper.Object, _validator.Object);
 }
Exemple #13
0
 public OutcomeController(QuizDbContext db, IOutcomeService outcomeService,
                          IStorageService storageService, IPhotoService photoService, IMapper mapper)
 {
     _db             = db;
     _outcomeService = outcomeService;
     _storageService = storageService;
     _photoService   = photoService;
     _mapper         = mapper;
 }
        public async Task TestMethod_UsingSqliteInMemoryProvider_Fail()
        {
            var options = new DbContextOptionsBuilder <QuizDbContext>()
                          .UseSqlite("DataSource=:memory:")
                          .Options;

            await using (var context = new QuizDbContext(options)) { Assert.True(await context.Database.EnsureCreatedAsync()); }

            await using (var context = new QuizDbContext(options)) { Assert.Throws <Microsoft.Data.Sqlite.SqliteException>(() => context.Quiz.Count()); }
        }
Exemple #15
0
 public UserService(QuizDbContext dbContext, SignInManager <User> signInManager, UserManager <User> userManager, IOptions <JwtSettings> jwtSettings,
                    AbstractValidator <UserDto> validator, RoleManager <IdentityRole> roleManager)
 {
     _quizDbContext = dbContext;
     _signInManager = signInManager;
     _userManager   = userManager;
     _roleManager   = roleManager;
     _jwtSettings   = jwtSettings.Value;
     _validator     = validator;
 }
Exemple #16
0
        public static DbContextOptions <QuizDbContext> GetUnitTestDbOptions()
        {
            var options = new DbContextOptionsBuilder <QuizDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            using var context = new QuizDbContext(options);
            FillWithData(context);
            return(options);
        }
Exemple #17
0
 public MembersController(
     UserManager <IdentityUser> userManager,
     SignInManager <IdentityUser> signInManager,
     IdentityDbContext identityContext,
     QuizDbContext context)
 {
     this.userManager     = userManager;
     this.signInManager   = signInManager;
     this.identityContext = identityContext;
     this.context         = context;
 }
 private static void Add_example_records(DbContextOptions <QuizDbContext> options)
 {
     using (var context = new QuizDbContext(options))
     {
         context.Answer.Add(new Answer {
             Content = "AAA", Id = 1, QuestionID = 12
         });
         context.Answer.Add(new Answer {
             Content = "BBB", Id = 2, QuestionID = 13
         });
         context.SaveChanges();
     }
 }
Exemple #19
0
 private static void Add_example_recorods(DbContextOptions <QuizDbContext> options)
 {
     using (var context = new QuizDbContext(options))
     {
         context.Quiz.Add(new Quiz {
             Name = "AAA", Id = 1
         });
         context.Quiz.Add(new Quiz {
             Name = "BBB", Id = 2
         });
         context.SaveChanges();
     }
 }
Exemple #20
0
 private static void Add_example_records(DbContextOptions <QuizDbContext> options)
 {
     using (var context = new QuizDbContext(options))
     {
         context.Question.Add(new Question {
             Content = "AAA", QuizID = 12, Id = 1
         });
         context.Question.Add(new Question {
             Content = "BBB", QuizID = 13, Id = 2
         });
         context.SaveChanges();
     }
 }
Exemple #21
0
    public TestFixture()
    {
        var dbOptionsBuilder = new DbContextOptionsBuilder <QuizDbContext>();

        dbOptionsBuilder.UseInMemoryDatabase();

        this.DbOptions = dbOptionsBuilder.Options;
        using (var db = new QuizDbContext(DbOptions))
        {
            var seeder = new DefaultSeeder(db);
            seeder.Seed();
        }

        MapperConfig = new ConfigureMapper().Config;
    }
Exemple #22
0
        public void Get_quiz_by_id_from_database()
        {
            var options = new DbContextOptionsBuilder <QuizDbContext>()
                          .UseInMemoryDatabase(databaseName: "Get_quiz_id_from_database")
                          .Options;

            Add_example_recorods(options);

            using (var context = new QuizDbContext(options))
            {
                var service = new QuizService(context);
                var nameOfQuizWithIdEquals1 = service.GetQuizByID(1).Name;

                nameOfQuizWithIdEquals1.Should().Be("AAA");
            }
        }
        public void Get_answer_by_id_from_database()
        {
            var options = new DbContextOptionsBuilder <QuizDbContext>()
                          .UseInMemoryDatabase(databaseName: "Get_answer_by_id_from_database")
                          .Options;

            Add_example_records(options);

            using (var context = new QuizDbContext(options))
            {
                var service = new AnswerService(context);
                var questionIdOfChosenAnswer = service.GetAnswerByID(2).QuestionID;

                questionIdOfChosenAnswer.Should().Be(13);
            }
        }
Exemple #24
0
        private void SeedData(QuizDbContext context)
        {
            context.Subjects.Add(new Subject {
                Id = "subject1", Name = "Subject1", LecturerId = "1"
            });
            context.Subjects.Add(new Subject {
                Id = "subject2", Name = "Subject2", LecturerId = "2"
            });
            context.Topics.Add(new Topic {
                Id = "topic1", Name = "Topic1", MaxAttemptCount = 3, QuestionsPerAttempt = 1, TimeToPass = 5, TopicNumber = 1, SubjectId = "subject1"
            });
            context.Topics.Add(new Topic {
                Id = "topic2", Name = "Topic2", MaxAttemptCount = 2, QuestionsPerAttempt = 2, TimeToPass = 3, TopicNumber = 2, SubjectId = "subject2"
            });
            context.Questions.Add(new Question {
                Id = "question1", QuestionNumber = 1, TopicId = "topic1", QuestionText = "Where?"
            });
            context.Questions.Add(new Question {
                Id = "question2", QuestionNumber = 3, TopicId = "topic2", QuestionText = "Why?"
            });
            context.Answers.Add(new Answer {
                Id = "answer1", AnswerText = "Here", IsCorrect = true, QuestionId = "question1"
            });
            context.Answers.Add(new Answer {
                Id = "answer2", AnswerText = "There", IsCorrect = false, QuestionId = "question1"
            });
            context.Answers.Add(new Answer {
                Id = "answer3", AnswerText = "Because", IsCorrect = true, QuestionId = "question2"
            });
            context.Answers.Add(new Answer {
                Id = "answer4", AnswerText = "London is the capital of Great Britain", IsCorrect = false, QuestionId = "question2"
            });
            context.Attempts.Add(new Attempt {
                Id = "attempt1", DateTime = DateTime.Now, Score = 100, StudentId = "1", TopicId = "topic2"
            });
            context.Attempts.Add(new Attempt {
                Id = "attempt3", DateTime = DateTime.Now, Score = 75, StudentId = "1", TopicId = "topic2"
            });
            context.QuestionResults.Add(new QuestionResult {
                Id = "questionResult1", AttemptId = "attempt1", QuestionId = "question2", Result = true
            });
            context.QuestionResults.Add(new QuestionResult {
                Id = "questionResult3", AttemptId = "attempt3", QuestionId = "question2", Result = false
            });

            context.SaveChanges();
        }
Exemple #25
0
        public void Get_all_quizes_from_database()
        {
            var options = new DbContextOptionsBuilder <QuizDbContext>()
                          .UseInMemoryDatabase(databaseName: "Get_all_quizes_from_database")
                          .Options;

            Add_example_recorods(options);

            using (var context = new QuizDbContext(options))
            {
                var service = new QuizService(context);
                var actual  = service.GetAll();

                var numberOfQuizes = actual.Count();

                numberOfQuizes.Should().Be(2);
            }
        }
        public void Get_answers_by_questionID_from_database()
        {
            var options = new DbContextOptionsBuilder <QuizDbContext>()
                          .UseInMemoryDatabase(databaseName: "Get_answers_by_questionID_from_database")
                          .Options;

            Add_example_records(options);

            using (var context = new QuizDbContext(options))
            {
                var service = new AnswerService(context);
                var actual  = service.GetAnswersByQuestionID(12);

                var numberOfAnswersToSelectedQuestion = actual.Count();

                numberOfAnswersToSelectedQuestion.Should().Be(1);
            }
        }
Exemple #27
0
        public void Delete_quiz_from_database()
        {
            var options = new DbContextOptionsBuilder <QuizDbContext>()
                          .UseInMemoryDatabase(databaseName: "Delete_quiz_from_database")
                          .Options;

            Add_example_recorods(options);

            using (var context = new QuizDbContext(options))
            {
                var service = new QuizService(context);
                service.DeleteQuizByID(1);

                var numberOfQuizesInDb = context.Quiz.Count();
                var idOfLastedQuiz     = context.Quiz.Single().Id;

                numberOfQuizesInDb.Should().Be(1);
                idOfLastedQuiz.Should().Be(2);
            }
        }
        public void Delete_answer_from_database()
        {
            var options = new DbContextOptionsBuilder <QuizDbContext>()
                          .UseInMemoryDatabase(databaseName: "Delete_answer_from_database")
                          .Options;

            Add_example_records(options);

            using (var context = new QuizDbContext(options))
            {
                var service = new AnswerService(context);
                service.DeleteAnswerByID(1);

                var numberOfAnserwsInDb = context.Answer.Count();
                var idOfLastedAnswer    = context.Answer.Single().Id;

                numberOfAnserwsInDb.Should().Be(1);
                idOfLastedAnswer.Should().Be(2);
            }
        }
Exemple #29
0
        public void ShouldGetQuizzesTest()
        {
            const int numberOfQuizzes = 3;
            var       skipInterval    = numberOfQuizzes;

            using (var db = new QuizDbContext(_testFixture.DbOptions))
            {
                var quizService = new QuizService(db);
                var quizzes1    = quizService.GetQuizzes(numberOfQuizzes).ToList();
                Assert.Equal("Quiz Number 0", quizzes1[0].Title);
                Assert.Equal("Quiz Number 1", quizzes1[1].Title);
                Assert.Equal("Quiz Number 10", quizzes1[2].Title);
                Assert.Equal(numberOfQuizzes, quizzes1.Count);

                var quizzes2 = quizService.GetQuizzes(numberOfQuizzes, skipInterval).ToList();
                Assert.Equal("Quiz Number 11", quizzes2[0].Title);
                Assert.Equal("Quiz Number 12", quizzes2[1].Title);
                Assert.Equal("Quiz Number 13", quizzes2[2].Title);
                Assert.Equal(numberOfQuizzes, quizzes2.Count);
            }
        }
        public void QuizDBContext_Constructor_Success()
        {
            //Arrange
            var settings = new ConnectionStrings()
            {
                Mongo = "mongodb://localhost:27017/Quiz"
            };

            var mongodbUrl = new MongoUrl(settings.Mongo);

            _mockOptions.Setup(s => s.Value).Returns(settings);
            _mockClient.Setup(c => c
                              .GetDatabase(mongodbUrl.DatabaseName, null))
            .Returns(_mockDB.Object);

            //Act
            var context = new QuizDbContext(_mockOptions.Object);

            //Assert
            Assert.NotNull(context);
        }