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

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

                var currentQuestionGroups = context.QuestionGroups.Count();
                var questions             = EfTestData.CreateQuestionsDtos();

                var questionGroupsDto = new List <QuestionGroupDto>
                {
                    new QuestionGroupDto
                    {
                        Name      = "Test QuestionGroup Dto",
                        Questions = questions
                    }
                };

                var surveyDto = new SurveyDto
                {
                    Id = 1,
                    QuestionGroupsDtos = questionGroupsDto
                };

                var service = new AddQuestionGroupService(context, new MapQuestionsToGroupService());
                var result  = service.AddQuestionGroup(surveyDto);
                result.ShouldBeNull();
                context.SaveChanges();
                context.QuestionGroups.Count().ShouldEqual(currentQuestionGroups + 1);
            }
        }
        public void ShouldReturnAnErrorMessageWhenNoNameProvided()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var currentSurveys = context.Surveys.Count();
                var questionGroups = EfTestData.CreateQuestionGroupDtos();

                var surveyDto = new SurveyDto
                {
                    QuestionGroupsDtos = questionGroups,
                };

                var service = new AddSurveyService(context, new MapQuestionsToGroupService());
                var result  = service.AddSurvey(surveyDto);
                result.ShouldNotBeNull();
                context.SaveChanges();
                result.First().ErrorMessage.ShouldEqual("A name has not been provided for this survey.");
                context.Surveys.Count().ShouldEqual(currentSurveys);
            }
        }
        public void ShouldReturnErrorMessageWhenSurveyNotFound()
        {
            var options = SqliteInMemory.CreateOptions<SurveyDbContext>();
            using (var context = new SurveyDbContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDataBaseWithSurveys();

                var currentCompletedQuestions = context.CompletedQuestions.Count();
                var completedSurveyId = -1;

                var completedSurveyDto = new CompletedSurveyDto
                {
                    CompletedSurveyId = completedSurveyId,
                    Name = "Test Completed Survey",
                    CaseNo = 999,
                    Questions = completedQuestionsDto
                };

                var service = new SaveCompletedQuestionToCompletedSurveyService(context, new MapCompletedQuestionsFromDtoService());

                var result = service.SaveCompletedQuestion(completedSurveyDto);
                result.ShouldNotBeNull();
                context.SaveChanges();
                result.First().ErrorMessage.ShouldEqual($"Could not find Survey with an Id of {completedSurveyId}");
                context.CompletedQuestions.Count().ShouldEqual(currentCompletedQuestions);

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

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

                var currentQuestionGroups = context.QuestionGroups.Count();
                var questions             = EfTestData.CreateQuestionsDtos();

                var questionGroupsDto = new List <QuestionGroupDto>
                {
                    new QuestionGroupDto
                    {
                        Questions = questions
                    }
                };

                var surveyDto = new SurveyDto
                {
                    Id = 1,
                    QuestionGroupsDtos = questionGroupsDto
                };

                var service = new AddQuestionGroupService(context, new MapQuestionsToGroupService());
                var result  = service.AddQuestionGroup(surveyDto);
                result.ShouldNotBeNull();
                context.SaveChanges();
                result.First().ErrorMessage.ShouldEqual("A name is needed when creating a new question group.");
                context.QuestionGroups.Count().ShouldEqual(currentQuestionGroups);
            }
        }
        public void ShouldReturnAnErrorMessageIfNewNameNotProvided()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var currentName = context.Surveys.First(m => m.SurveyId == 1).Name;

                var surveyDto = new SurveyDto
                {
                    Id      = 1,
                    NewName = ""
                };

                var service = new RenameSurveyService(context);

                var result = service.RenameSurvey(surveyDto);
                result.ShouldNotBeNull();
                result.First().ErrorMessage.ShouldEqual("No new name has been provided for this survey.");
                context.SaveChanges();
                context.Surveys.First(m => m.SurveyId == surveyDto.Id).Name.ShouldEqual(currentName);
            }
        }
        public void TestSaveSurveyNoQuestions()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var currentCompletedSurveys = context.CompletedSurveys.Count();
                var completedQuestionsDto   = EfTestData.CreateCompletedQuestionsDto();
                var completedSurveyDto      = new CompletedSurveyDto
                {
                    Name   = "Test Completed Survey",
                    CaseNo = 999
                };

                var service = new SaveCompletedSurveysService(context, new MapCompletedQuestionsFromDtoService());
                var result  = service.SaveCompletedSurvey(completedSurveyDto);
                context.SaveChanges();
                result.ShouldNotBeNull();
                result.First().ErrorMessage.ShouldEqual("No Questions have been submitted with this completed survey.");
                context.CompletedSurveys.Count().ShouldEqual(currentCompletedSurveys);
            }
        }
示例#7
0
        public async Task ShouldReturnOkObjectResult()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var controller = new TestController();
                var surveys    = EfTestData.CreateSurveys();

                var mockService = new Mock <IListSurveysService>();
                mockService.Setup(m => m.GetSurveys()).Returns((Task.FromResult((surveys))));

                var result = await controller.GetListOfSurveys(mockService.Object);

                result.ShouldNotBeNull();
                result.ShouldEqual(result as OkObjectResult);

                var r = result as OkObjectResult;

                r.Value.ShouldEqual(surveys);
            }
        }
        public void TestSaveSurveyOk()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var currentCompletedSurveys = context.CompletedSurveys.Count();
                var completedQuestionsDto   = EfTestData.CreateCompletedQuestionsDto();
                var completedSurveyDto      = new CompletedSurveyDto
                {
                    Name      = "Test Completed Survey",
                    CaseNo    = 999,
                    Questions = completedQuestionsDto
                };

                var service = new SaveCompletedSurveysService(context, new MapCompletedQuestionsFromDtoService());
                var result  = service.SaveCompletedSurvey(completedSurveyDto);
                result.ShouldBeNull();
                context.SaveChanges();
                service.Errors.Count.ShouldEqual(0);
                context.CompletedSurveys.Count().ShouldEqual(currentCompletedSurveys + 1);
            }
        }
        public void TestSaveSurveyNoName()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var currentCompletedSurveys = context.CompletedSurveys.Count();
                var completedQuestionsDto   = EfTestData.CreateCompletedQuestionsDto();
                var completedSurveyDto      = new CompletedSurveyDto
                {
                    CaseNo    = 999,
                    Questions = completedQuestionsDto
                };

                var service = new SaveCompletedSurveysService(context, new MapCompletedQuestionsFromDtoService());
                var result  = service.SaveCompletedSurvey(completedSurveyDto);
                context.SaveChanges();
                result.ShouldNotBeNull();
                service.Errors.Count.ShouldEqual(1);
                service.Errors.First().ErrorMessage.ShouldEqual("A survey name has not been supplied.");
                context.CompletedSurveys.Count().ShouldEqual(currentCompletedSurveys);
            }
        }
        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 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 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);
            }
        }
        public void ShouldReturnErrorMessageIfSurveyNotFound()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var currentSurveys = context.Surveys.Count();

                var surveyDto = new SurveyDto
                {
                    Id = -1
                };

                var service = new RemoveSurveyService(context);

                var result = service.RemoveSurvey(surveyDto);

                result.ShouldNotBeNull();
                result.First().ErrorMessage.ShouldEqual($"A survey with the ID of {surveyDto.Id} was not found.");
                context.SaveChanges();
                context.Surveys.Count().ShouldEqual(currentSurveys);
            }
        }
示例#14
0
        public async Task ShouldReturnBadObjectResult()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var controller   = new TestController();
                var errorMessage = "Could not retrieve surveys.";

                var mockService = new Mock <IListSurveysService>();
                mockService.Setup(m => m.GetSurveys()).Returns((Task.FromResult((List <Survey>)null)));

                var result = await controller.GetListOfSurveys(mockService.Object);

                result.ShouldNotBeNull();
                result.ShouldBeType <BadRequestObjectResult>();

                var r = result as BadRequestObjectResult;

                r.Value.ShouldEqual(errorMessage);
            }
        }
        public void TestSqlLiteOk()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

            using (var context = new SurveyDbContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDataBaseWithSurveys();
                context.CompletedSurveys.Count().ShouldEqual(4);
            }
        }
示例#16
0
        public void ShouldReturnNullIfContextIsNull()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var service = new ListSurveysService(null);

                var result = service.GetSurveys();
                result.ShouldBeNull();
            }
        }
示例#17
0
        public void ShouldReturnAListOfSurveysForDropdown()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var currentSurveys = context.Surveys.ToList().Count;

                var service = new ListSurveysService(context);
                var result  = service.GetSurveysForDropdown();
                result.ShouldNotBeNull();
                result.First().ShouldBeType <SurveyListForDropdownDto>();
                result.Count().ShouldEqual(currentSurveys);
            }
        }
        public void ShouldReturnAnErrorMessageIfSurveyNotFound()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var surveyDto = new SurveyDto
                {
                    Id      = -1,
                    NewName = "Test New Name"
                };

                var service = new RenameSurveyService(context);

                var result = service.RenameSurvey(surveyDto);
                result.ShouldNotBeNull();
                result.First().ErrorMessage.ShouldEqual($"A survey with the Id {surveyDto.Id} does not exist.");
            }
        }
        public void ShouldRenameASurvey()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var surveyDto = new SurveyDto
                {
                    Id      = 1,
                    NewName = "Test New Name"
                };

                var service = new RenameSurveyService(context);

                var result = service.RenameSurvey(surveyDto);
                result.ShouldBeNull();
                context.SaveChanges();
                context.Surveys.First(m => m.SurveyId == surveyDto.Id).Name.ShouldEqual(surveyDto.NewName);
            }
        }
        public void TestAddCompletedSurvey()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var type     = new QuestionType("Text");
                var question = new Question("How has your sleep pattern been?", type);

                var completedQuestions = new List <CompletedQuestion>
                {
                    new CompletedQuestion(question, "It's not been great.")
                };

                var completedSurvey = new DataLayer.Models.CompletedSurvey("New Test Survey", 10, completedQuestions);
                context.CompletedSurveys.Add(completedSurvey);
                context.SaveChanges();
                context.CompletedSurveys.Count().ShouldEqual(5);
            }
        }
        public void TestAddCompletedQuestionToCompletedSurvey()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var completedSurvey   = context.CompletedSurveys.First();
                var type              = new QuestionType("Text");
                var question          = new Question("How has your sleep pattern been?", type);
                var completedQuestion = new CompletedQuestion(question, "It's not been great.", completedSurvey);

                var status = completedSurvey.AddQuestion(completedQuestion, context);
                status.Errors.ShouldBeEmpty();
                status.HasErrors.ShouldBeFalse();
                status.Message.ShouldEqual("Success");
                context.SaveChanges();

                completedSurvey.CompletedQuestions.Count().ShouldEqual(2);
            }
        }
        public void ShouldReturnErrorMessageWhenNoAnswerProvided()
        {
            var options = SqliteInMemory.CreateOptions<SurveyDbContext>();
            using (var context = new SurveyDbContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDataBaseWithSurveys();

                var currentCompletedQuestions = context.CompletedQuestions.Count();

                var completedQuestionsDto = new List<CompletedQuestionDto>
                {
                    new CompletedQuestionDto
                    {
                        QuestionId = 1,
                    }
                };

                var completedSurveyDto = new CompletedSurveyDto
                {
                    CompletedSurveyId = 1,
                    Name = "Test Completed Survey",
                    CaseNo = 999,
                    Questions = completedQuestionsDto
                };

                var service = new SaveCompletedQuestionToCompletedSurveyService(context, new MapCompletedQuestionsFromDtoService());

                var result = service.SaveCompletedQuestion(completedSurveyDto);
                result.ShouldNotBeNull();
                context.SaveChanges();
                result.First().ErrorMessage.ShouldEqual("An answer is needed when submitting a question.");
                context.CompletedQuestions.Count().ShouldEqual(currentCompletedQuestions);

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

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

                var currentQuestionGroups = context.QuestionGroups.Count();
                var questions             = EfTestData.CreateQuestionsDtos();
                var surveyId = -1;

                var questionGroupsDto = new List <QuestionGroupDto>
                {
                    new QuestionGroupDto
                    {
                        Name      = "Test QuestionGroup Dto",
                        Questions = questions
                    }
                };

                var surveyDto = new SurveyDto
                {
                    Id = surveyId,
                    QuestionGroupsDtos = questionGroupsDto
                };

                var service = new AddQuestionGroupService(context, new MapQuestionsToGroupService());
                var result  = service.AddQuestionGroup(surveyDto);
                result.ShouldNotBeNull();
                context.SaveChanges();
                result.First().ErrorMessage.ShouldEqual($"Could not find Survey with an Id of {surveyId}");
                context.QuestionGroups.Count().ShouldEqual(currentQuestionGroups);
            }
        }
        public void ShouldRemoveASurvey()
        {
            var options = SqliteInMemory.CreateOptions <SurveyDbContext>();

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

                var currentSurveys = context.Surveys.Count();

                var dto = new SurveyDto
                {
                    Id = 1
                };

                var service = new RemoveSurveyService(context);

                var result = service.RemoveSurvey(dto);
                result.ShouldBeNull();
                context.SaveChanges();
                context.Surveys.Count().ShouldEqual(currentSurveys - 1);
            }
        }