public void Given_existing_template_with_question_when_exclude_question_then_template_does_not_contains_question()
        {
            // given
            var checklistTemplateId = Guid.NewGuid();
            var existingTemplate = new ChecklistTemplate()
            {
                Id = checklistTemplateId,
                Name = "ChecklistTemplate 1"
            };

            existingTemplate.AddQuestion(
                new ChecklistTemplateQuestion
                {
                    ChecklistTemplate = new ChecklistTemplate() {Id = checklistTemplateId},
                    Question = new Question {Id = Guid.NewGuid(), Deleted = false}
                }
                , null);

            _checklistTemplateRepository
              .Setup(x => x.GetById(existingTemplate.Id))
              .Returns(() => existingTemplate);

            ChecklistTemplate savedTemplate = null;

            _checklistTemplateRepository
                .Setup(x => x.SaveOrUpdate(It.IsAny<ChecklistTemplate>()))
                .Callback(
                    delegate(ChecklistTemplate x)
                    {
                        savedTemplate = x;
                    }
                );

            // when
            var controller = GetTarget();
            controller.UpdateTemplateQuestion(new UpdateTemplateQuestionRequest()
            {
                TemplateId = existingTemplate.Id,
                QuestionId = existingTemplate.Questions[0].Question.Id,
                Exclude = true
            });

            //then
            Assert.That(savedTemplate.Questions.Count, Is.EqualTo(0));
        }
        public void Given_template_had_question_deleted_when_adding_same_question_to_template_then_the_question_is_restored()
        {
            // given
            var questionId = Guid.NewGuid();
            var template = new ChecklistTemplate() { Id = Guid.NewGuid(), Name = "ChecklistTemplate 1" };
            template.AddQuestion(new ChecklistTemplateQuestion() { Question = new Question() { Id = questionId }, Deleted = true}, null);

            _checklistTemplateRepository
                .Setup(x => x.GetById(It.IsAny<Guid>()))
                .Returns(() => template);

            _questionRepository.
                Setup(x => x.GetById(It.IsAny<Guid>()))
                .Returns<Guid>(id => new Question() {Id = id});

            ChecklistTemplate savedTemplate = null;
            _checklistTemplateRepository
               .Setup(x => x.SaveOrUpdate(It.IsAny<ChecklistTemplate>()))
                               .Callback(
                   delegate(ChecklistTemplate x)
                   {
                       savedTemplate = x;
                   }
               );

            // when
            var controller = GetTarget();
            var result = controller.UpdateTemplateQuestion(new UpdateTemplateQuestionRequest() { Exclude = false, QuestionId = questionId, TemplateId = template.Id });

            //then
            Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(savedTemplate.Questions.Count(x => !x.Deleted), Is.EqualTo(1));
            Assert.That(savedTemplate.Deleted,Is.EqualTo(false));
        }
        public void Given_existing_template_with_question_when_clone_with_name_then_new_template_contains_questions()
        {
            // given
            var existingTempate = new ChecklistTemplate()
            {
                Id = Guid.NewGuid(),
                Name = "ChecklistTemplate 1"
            };

            existingTempate.AddQuestion(new ChecklistTemplateQuestion {Question = new Question {Id = Guid.NewGuid()}}, null);
            existingTempate.AddQuestion(new ChecklistTemplateQuestion { Question = new Question { Id = Guid.NewGuid() } }, null);

            var newTemplateName = "ChecklistTemplate 2";

            _checklistTemplateRepository
                .Setup(x => x.GetById(existingTempate.Id))
                .Returns(() => existingTempate);

            ChecklistTemplate template1 = null;

            _checklistTemplateRepository
                .Setup(x => x.SaveOrUpdate(It.IsAny<ChecklistTemplate>()))
                .Callback(
                    delegate(ChecklistTemplate x)
                    {
                        template1 = x;
                    }
                );

            // when
            var controller = GetTarget();
            controller.Clone(new CloneTemplateRequest
            {
                Id = existingTempate.Id,
                TemplateType = 2,
                Name = newTemplateName
            });

            //then
            Assert.That(template1.Questions.Count, Is.EqualTo(existingTempate.Questions.Count));
            Assert.That(template1.Questions[0].Question.Id, Is.EqualTo(existingTempate.Questions[0].Question.Id));
            Assert.That(template1.Questions[1].Question.Id, Is.EqualTo(existingTempate.Questions[1].Question.Id));
            Assert.That(template1.TemplateType, Is.EqualTo(ChecklistTemplateType.Bespoke));
        }