public QuizService(QuizaldoDbContext context, IMapper mapper, INotificationService notificationService, IAchievementService achievementService) : base(context) { this.mapper = mapper; this.notificationService = notificationService; this.achievementService = achievementService; }
public async Task GetAllSuggestions_WithNoData_ShouldReturnEmptyList() { var options = new DbContextOptionsBuilder <QuizaldoDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new QuizaldoDbContext(options); var questionSuggestionService = new QuestionSuggestionService(context, mapper, notificationService); var result = await questionSuggestionService.GetAllSuggestions(); Assert.True(result.Count() == 0); }
public async Task AllQuizzes_WithData_ShouldReturnAllQuizzes() { var options = new DbContextOptionsBuilder <QuizaldoDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new QuizaldoDbContext(options); var quizService = new QuizService(context, mapper, notificationService, achievementService); SeedTestQuiz(context); var result = await quizService.AllQuizzes(); Assert.False(result.Count() == 0); }
public async Task RemoveSuggestion_WithIncorrectData_ShouldntRemoveSuggestion(int questionSuggestionId) { var options = new DbContextOptionsBuilder <QuizaldoDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new QuizaldoDbContext(options); var questionSuggestionService = new QuestionSuggestionService(context, mapper, notificationService); SeedTestQuestionSuggestion(context); await questionSuggestionService.RemoveSuggestion(questionSuggestionId); Assert.Equal(1, context.QuestionSuggestions.Count()); }
public async Task DeleteQuiz_WithIncorrectData_ShouldntDeleteQuiz(int id) { var options = new DbContextOptionsBuilder <QuizaldoDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new QuizaldoDbContext(options); var quizService = new QuizService(context, mapper, notificationService, achievementService); SeedTestQuiz(context); await quizService.DeleteQuiz(id); Assert.Equal(1, context.Quizzes.Count()); }
public async Task CreateQuiz_WithCorrectInputData_ShouldCreateQuiz() { var options = new DbContextOptionsBuilder <QuizaldoDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new QuizaldoDbContext(options); var quizService = new QuizService(context, mapper, notificationService, achievementService); var quiz = GetTestQuiz(); await quizService.CreateQuiz(quiz); Assert.True(quiz.Id > 0); }
public async Task GetQuizById_WithCorrectData_ShouldReturnQuiz(int id) { var options = new DbContextOptionsBuilder <QuizaldoDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new QuizaldoDbContext(options); var quizService = new QuizService(context, mapper, notificationService, achievementService); SeedTestQuiz(context); var currentQuiz = await quizService.GetQuizById(id); Assert.True(currentQuiz.Id == id); }
public async Task SuggestQuestion_WithCorrectInputDataAndIncorretUser_ShouldntReturnQuestion(string username) { var options = new DbContextOptionsBuilder <QuizaldoDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new QuizaldoDbContext(options); var questionSuggestionService = new QuestionSuggestionService(context, mapper, notificationService); var question = GetTestQuestionSuggestion(); SeedTestUser(context); await questionSuggestionService.SuggestQuestion(question, username); Assert.Equal(0, context.QuestionSuggestions.Count()); }
public async Task Create_WithIncorrectData_ShouldntCreateQuiz() { var options = new DbContextOptionsBuilder <QuizaldoDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new QuizaldoDbContext(options); var quizService = new QuizService(context, mapper, notificationService, achievementService); var quiz = GetTestQuiz(); quiz.Id = 0; await quizService.CreateQuiz(quiz); Assert.Equal(0, context.Questions.Count()); }
public async Task ApproveSuggestion_WithCorrectData_ShouldAddQuestion(int questionSuggestionId) { var options = new DbContextOptionsBuilder <QuizaldoDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new QuizaldoDbContext(options); var config = new MapperConfiguration(opts => { opts.CreateMap <Question, QuestionSuggestion>().ReverseMap(); }); var mapper = config.CreateMapper(); var questionSuggestionService = new QuestionSuggestionService(context, mapper, notificationService); SeedTestQuestionSuggestion(context); await questionSuggestionService.ApproveSuggestion(questionSuggestionId); Assert.Equal(0, context.QuestionSuggestions.Count()); }
public async Task AddQuestion_WithIncorrectInputData_ShouldntReturnQuestion() { var options = new DbContextOptionsBuilder <QuizaldoDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new QuizaldoDbContext(options); var questionService = new QuestionService(context); var question = new Question() { QuestionName = "Is it a correct test?", FirstOption = "Yes", SecondOption = "No", ThirdOption = "Idk", FourthOption = "Maybe", CorrectAnswer = "oops" }; await questionService.AddQuestion(question); Assert.Equal(0, context.Questions.Count()); }
private void SeedTestQuestionSuggestion(QuizaldoDbContext context) { context.QuestionSuggestions.Add(GetTestQuestionSuggestion()); context.SaveChanges(); }
private void SeedTestUser(QuizaldoDbContext context) { context.Users.Add(GetTestUser()); context.SaveChanges(); }
public DataService(QuizaldoDbContext context) { this.context = context; }
public JokeService(QuizaldoDbContext context) : base(context) { }
public AchievementService(QuizaldoDbContext context, INotificationService notificationService) : base(context) { this.notificationService = notificationService; }
public UserResultService(QuizaldoDbContext context, IMapper mapper) : base(context) { this.mapper = mapper; }
private void SeedTestQuiz(QuizaldoDbContext context) { context.Quizzes.Add(GetTestQuiz()); context.SaveChanges(); }
public NotificationService(QuizaldoDbContext context) : base(context) { }
public QuestionSuggestionService(QuizaldoDbContext context, IMapper mapper, INotificationService notificationService) : base(context) { this.mapper = mapper; this.notificationService = notificationService; }
public QuestionService(QuizaldoDbContext context) : base(context) { }
public UserService(QuizaldoDbContext context) : base(context) { }