Exemple #1
0
        public static QuestionEF UpdateFromDetached(this QuestionEF qAttach, QuestionEF qDetached)
        {
            if (qAttach is null)
            {
                throw new ArgumentNullException();
            }

            if (qDetached is null)
            {
                throw new NullReferenceException();
            }

            if (qAttach.Id != qDetached.Id)
            {
                throw new Exception("Cannot update Question because it is not the same ID.");
            }

            if ((qAttach != default) && (qDetached != default))
            {
                qAttach.Id           = qDetached.Id;
                qAttach.LostSoulId   = qDetached.LostSoulId;
                qAttach.IsArchived   = qDetached.IsArchived;
                qAttach.Questioning  = qDetached.Questioning;
                qAttach.Answers      = qDetached.Answers;
                qAttach.CreationDate = qDetached.CreationDate;
                qAttach.State        = qDetached.State;
            }

            return(qAttach);
        }
Exemple #2
0
        public static QuestionEF ToEF(this QuestionTO question)
        {
            if (question is null)
            {
                throw new ArgumentNullException(nameof(question));
            }

            var q = new QuestionEF();

            q.Id          = question.Id;
            q.NameEnglish = question.Libelle.English;
            q.NameFrench  = question.Libelle.French;
            q.NameDutch   = question.Libelle.Dutch;
            q.Position    = question.Position;
            q.Type        = question.Type;
            //q.Form.Id = question.FormId;

            if (question.Propositions != null)
            {
                q.Propositions = question.Propositions.Select(x => x.ToEF()).ToList();
                q.Propositions.Select(x => x.Question = q);
            }

            return(q);
        }
        public void ToTransfertObject_ProvidingNull_ThrowException()
        {
            //ARRANGE
            QuestionEF question = null;

            //ACT
            Assert.ThrowsException <ArgumentNullException>(() => question.ToTransferObject());
        }
        public void ToTrackedEF_ProvidingNullEF_ThrowException()
        {
            //ARRANGE
            QuestionTO question         = null;
            QuestionEF questionToModify = null;

            //ACT
            Assert.ThrowsException <ArgumentNullException>(() => question.ToTrackedEF(questionToModify));
        }
        public void ToTrackedEF_ProvidingNullTO_ThrowException()
        {
            //ARRANGE
            QuestionTO question         = null;
            DateTime   date             = DateTime.Now;
            var        questionToModify = new QuestionEF {
                Id = 1, IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };

            //ACT
            Assert.ThrowsException <ArgumentNullException>(() => question.ToTrackedEF(questionToModify));
        }
Exemple #6
0
        public void ToTrackedEF_ProvidingNullTO_ThrowException()
        {
            //ARRANGE
            AnswerTO answer   = null;
            DateTime date     = DateTime.Now;
            var      question = new QuestionEF {
                Id = 1, IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            var answerToModify = new AnswerEF {
                Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = question,
            };

            //ACT
            Assert.ThrowsException <ArgumentNullException>(() => answer.ToTrackedEF(answerToModify));
        }
Exemple #7
0
        public void ToTransfertObject_Successful()
        {
            //ARRANGE
            DateTime date     = DateTime.Now;
            var      question = new QuestionEF {
                Id = 1, IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            var answer = new AnswerEF {
                Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = question,
            };
            //ACT
            var result = answer.ToTransferObject();

            //Assert
            Assert.AreEqual(answer.AuthorId, result.AuthorId);
            Assert.AreEqual(answer.Message, result.Message);
        }
Exemple #8
0
        public static QuestionTO ToTransfertObject(this QuestionEF question)
        {
            if (question is null)
            {
                throw new ArgumentNullException(nameof(question));
            }

            return(new QuestionTO
            {
                Id = question.Id,
                Libelle = new MultiLanguageString(question.NameEnglish, question.NameFrench, question.NameDutch),
                Form = question.Form.ToTransfertObject(),
                Position = question.Position,
                Type = question.Type,
                Choices = question.Choices?.Select(x => x.ToTransfertObject()).ToList(),
            });
        }
Exemple #9
0
        public static QuestionTO ToTransferObject(this QuestionEF question)
        {
            if (question is null)
            {
                throw new ArgumentNullException(nameof(question));
            }

            return(new QuestionTO
            {
                Id = question.Id,
                AuthorId = question.AuthorId,
                Date = question.Date,
                IsResolved = question.IsResolved,
                IsDeleted = question.IsDeleted,
                Message = question.Message,
                Title = question.Title,
            });
        }
        public void ToTransfertObject_Successful()
        {
            //ARRANGE
            DateTime date     = DateTime.Now;
            var      question = new QuestionEF {
                Id = 1, IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            //ACT
            var result = question.ToTransferObject();

            //Assert
            Assert.AreEqual(question.Id, result.Id);
            Assert.AreEqual(question.IsResolved, result.IsResolved);
            Assert.AreEqual(question.AuthorId, result.AuthorId);
            Assert.AreEqual(question.Title, result.Title);
            Assert.AreEqual(question.Date, result.Date);
            Assert.AreEqual(question.Message, result.Message);
        }
Exemple #11
0
        public static QuestionEF ToEF(this QuestionTO question)
        {
            if (question is null)
            {
                throw new ArgumentNullException(nameof(question));
            }

            var result = new QuestionEF
            {
                Id           = question.Id,
                Questioning  = question.Questioning,
                CreationDate = question.CreationDate,
                IsArchived   = question.IsArchived,
                State        = question.State,
                LostSoulId   = question.LostSoulId,
                Answers      = question.Answers?.Select(x => x.ToEF()).ToList()
            };

            return(result);
        }
Exemple #12
0
        public static QuestionEF ToTrackedEF(this QuestionTO question, QuestionEF questionToModify)
        {
            if (questionToModify is null)
            {
                throw new ArgumentNullException(nameof(questionToModify));
            }
            if (question is null)
            {
                throw new ArgumentNullException(nameof(question));
            }

            questionToModify.Id         = question.Id;
            questionToModify.AuthorId   = question.AuthorId;
            questionToModify.Date       = question.Date;
            questionToModify.IsResolved = question.IsResolved;
            questionToModify.IsDeleted  = question.IsDeleted;
            questionToModify.Message    = question.Message;
            questionToModify.Title      = question.Title;

            return(questionToModify);
        }
Exemple #13
0
        static void Main(string[] args)
        {
            //IQuestionTypeRepository questionTypeRepository = new QuestionTypeADO();
            //IQuestionRepository questionRepository = new QuestionADO();
            //IOptionRepository optionRepository = new OptionADO();
            //IAnswerRepository answerRepository = new AnswerADO();

            //DEMO 1
            //ConnectionStringHelper.OpenSqlConnectionInCode();

            //ADD QUESTION
            //questionTypeRepository.Add(new QuestionTypeDTO { Description = "Dumb" });

            //DELETE QUESTION
            //questionTypeRepository.Delete(4);

            //COUNT ROWS
            //Console.WriteLine(questionTypeRepository.CountQuestionType());

            //GET ALL QUESTIONTYPES
            //var results = questionTypeRepository.GetAll();
            //foreach(QuestionTypeDTO item in results)
            //{
            //    //Console.WriteLine($"{item.QuestionTypeId} {item.Description}");
            //    Console.WriteLine("{0} {1}", item.QuestionTypeId, item.Description);
            //}

            //GET ALL OPTIONS
            //var results = optionRepository.GetAll();
            //foreach (OptionDTO item in results)
            //{
            //    Console.WriteLine("{0} {1}", item.OptionId, item.Text);
            //}

            //GET ALL QUESTIONS
            //var results = questionRepository.GetAll();
            //foreach (QuestionDTO item in results)
            //{
            //    Console.WriteLine("{0} {1} {2}", item.QuestionId, item.Text, item.QuestionTypeId);
            //}

            //GET ALL ANSWERS
            //var results = answerRepository.GetAll();
            //foreach (AnswerDTO item in results)
            //{
            //    Console.WriteLine("{0} {1} {2} {3}", item.AnswerId, item.QuestionId, item.OpenValue, item.OptionId);
            //}

            //List<QuestionDTO> results = new List<QuestionDTO>();
            //results = questionRepositoryOff.GetAll();
            //foreach(QuestionDTO question in results)
            //{
            //    Console.WriteLine("{0} {1} {2}", question.QuestionId, question.Text, question.QuestionTypeId);
            //}

            //SPOptionADO spado = new SPOptionADO();
            //spado.OptionsByQuestionId(4);

            /////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////****ENTITY FRAMEWORK****///////////////////////////////////////////////////
            /////////////////////////////////////////////////////////////////////////////////////////////

            //using(var context = new DemoContext())
            //{
            //    context.QuestionTypes.Add(new QuestionType { Description = "Si/No" });
            //    context.QuestionTypes.Add(new QuestionType { Description = "Abierta" });
            //    context.QuestionTypes.Add(new QuestionType { Description = "Opcion Multiple" });
            //    context.QuestionTypes.Add(new QuestionType { Description = "Test Question" });
            //    context.SaveChanges();
            //}

            //using (var context = new DemoContext())
            //{
            //    context.QuestionTypes.Add(new QuestionType { Description = "Para que corra" });
            //    context.SaveChanges();
            //}

            IQuestionTypeRepository questionTypeRepository = new QuestionTypeEF();
            IQuestionRepository     questionRepository     = new QuestionEF();
            IOptionRepository       optionRepository       = new OptionEF();

            //questionTypeRepository.Add(new QuestionTypeDTO { Description = "Paquecorra", CreateDate = DateTime.Now });
            //questionTypeRepository.Update(new QuestionTypeDTO { Description = "Ya corrio!", QuestionTypeId = 9 });
            //questionTypeRepository.Delete(8);

            //questionRepository.Add(new QuestionDTO { Text = "Que tal?", QuestionTypeId = 1, IsActive = false, IsRequired = true });
            //questionRepository.Update(new QuestionDTO { QuestionId = 9, Text = "Donde llueve cafe?" });
            //questionRepository.Delete(11);

            //optionRepository.Add(new OptionDTO { Text = "En el campo" });
            //optionRepository.Update(new OptionDTO { OptionId = 9, Text = "Mexico" });

            var question = questionRepository.GetById(1);
            var options  = question.Option;

            Console.WriteLine($"{question.Text} \n {}");

            //Console.WriteLine("Question Types");
            //var resultqtype = questionTypeRepository.GetAll();
            //foreach(QuestionTypeDTO qtype in resultqtype)
            //{
            //    Console.WriteLine($"{qtype.QuestionTypeId} { qtype.Description}");
            //}

            //Console.WriteLine("\n Questions");
            //var resultqu = questionRepository.GetAll();
            //foreach (QuestionDTO qtype in resultqu)
            //{
            //    Console.WriteLine($"{qtype.QuestionId} {qtype.Text} {qtype.QuestionTypeId}");
            //}

            //Console.WriteLine("\n Options");
            //var resultop = optionRepository.GetAll();
            //foreach (OptionDTO qtype in resultop)
            //{
            //    Console.WriteLine($"{qtype.OptionId} { qtype.Text}");
            //}

            Console.ReadKey();
        }