public void ShouldReturnErrorMessageWhenQuestionTextNotSpecified()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

            using (var context = new SurveyDbContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDataBaseWithSurveys();

                var currentQuestions = context.Questions.Count();
                var questionDtos     = new List <QuestionDto>
                {
                    new QuestionDto
                    {
                        Type = 1
                    }
                };

                var surveyDto = new SurveyDto
                {
                    Id = 1,
                    QuestionGroupId = 1,
                    QuestionsDtos   = questionDtos
                };

                var service = new AddQuestionService(context, new MapQuestionDtoToQuestionsService());
                var result  = service.AddQuestion(surveyDto);
                result.ShouldNotBeNull();
                result.First().ErrorMessage.ShouldEqual("A question has been submitted without any text.");
                context.SaveChanges();
                context.Questions.Count().ShouldEqual(currentQuestions);
            }
        }
        public void ShouldReturnErrorMessageWhenQuestionGroupNotFound()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

            using (var context = new SurveyDbContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDataBaseWithSurveys();

                var questionGroupId  = -1;
                var currentQuestions = context.Questions.Count();
                var questionDtos     = new List <QuestionDto>
                {
                    new QuestionDto
                    {
                        Text = "How well have you been sleeping?",
                        Type = 1
                    }
                };

                var surveyDto = new SurveyDto
                {
                    Id = 1,
                    QuestionGroupId = questionGroupId,
                    QuestionsDtos   = questionDtos
                };

                var service = new AddQuestionService(context, new MapQuestionDtoToQuestionsService());
                var result  = service.AddQuestion(surveyDto);
                result.ShouldNotBeNull();
                result.First().ErrorMessage.ShouldEqual($"Could not find QuestionGroup with an Id of {questionGroupId}");
                context.SaveChanges();
                context.Questions.Count().ShouldEqual(currentQuestions);
            }
        }
        public void ShouldAddAQuestion()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

            using (var context = new SurveyDbContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDataBaseWithSurveys();

                var currentQuestions = context.Questions.Count();
                var questionDtos     = new List <QuestionDto>
                {
                    new QuestionDto
                    {
                        Text = "How well have you been sleeping?",
                        Type = 1
                    }
                };

                var surveyDto = new SurveyDto
                {
                    Id = 1,
                    QuestionGroupId = 1,
                    QuestionsDtos   = questionDtos
                };

                var service = new AddQuestionService(context, new MapQuestionDtoToQuestionsService());
                var result  = service.AddQuestion(surveyDto);
                result.ShouldBeNull();
                context.SaveChanges();
                context.Questions.Count().ShouldEqual(currentQuestions + 1);
            }
        }