public void check_questions_index_changed()
        {
            DForm form = new DForm( "Title", "Nunit" );
            QuestionBase q1 = new OpenQuestion( "1st Question" );
            QuestionBase q2 = new OpenQuestion( "2nd Question" );
            QuestionBase q3 = new OpenQuestion( "3rd Question" );
            QuestionBase q4 = new OpenQuestion( "4th Question" );

            q1.AddNewQuestion( q2 );
            q1.AddNewQuestion( q3 );
            q1.AddNewQuestion( q4 );

            Assert.That( q2.Index, Is.EqualTo( 0 ) );
            Assert.That( q3.Index, Is.EqualTo( 1 ) );
            Assert.That( q4.Index, Is.EqualTo( 2 ) );

            Assert.Throws<ArgumentException>( () => q3.Index = -1 );

            Assert.Throws<IndexOutOfRangeException>( () => q2.Index = 3 );
            Assert.DoesNotThrow( () => q2.Index = 2 );
            Assert.IsTrue( q2.Index == 2 && q4.Index == 1 );

            Assert.DoesNotThrow( () => q2.Parent = null );
            Assert.IsTrue( q2.Index == -1 && !q1.Contains(q2) );

            q2.Parent = q1;
            Assert.AreEqual( 2, q2.Index );
        }
 public void check_questions_are_not_null_at_construction()
 {
     DForm form = new DForm();
     Assert.NotNull( form.Questions );
     form = new DForm( "Title", "Nunit" );
     Assert.NotNull( form.Questions );
 }
 public QuestionBase()
 {
     questions = new List<QuestionBase>();
     _form = null;
     _parent = null;
     _title = "default Titlte";
 }
 public void check_questions_contains_feature()
 {
     DForm form = new DForm( "Title", "Nunit" );
     Assert.Throws<ArgumentNullException>( () => form.Questions.Contains( null ) );
     QuestionBase q = new OpenQuestion( "Test Question" );
     form.Questions.AddNewQuestion( q );
     Assert.IsTrue( form.Questions.Contains( q ) );
 }
 public QuestionBase(string title, QuestionBase parent = null)
 {
     if( String.IsNullOrEmpty( title ) )
         throw new ArgumentException( "title", "title MUST NOT be NULL or EMPTY!" );
     questions = new List<QuestionBase>();
     _form = null;
     _parent = parent;
     _title = title;
 }
        public FormAnswer(string author, DForm form)
        {
            if( String.IsNullOrEmpty( author ) )
                throw new ArgumentException( "uniqueName", "uniqueName MUST NOT be NULL or EMPTY!" );
            if( form == null )
                throw new ArgumentNullException( "form", "form MUST NOT be NULL!" );

            _form = form;
            _uniqueName = author;
            _answers = new Dictionary<QuestionBase, AnswerBase>();
        }
        public void check_contains_feature()
        {
            DForm form = new DForm();
            OpenQuestion q1 = new OpenQuestion( "Q1" );
            OpenQuestion q2 = new OpenQuestion( "Q2" );
            OpenQuestion q3 = new OpenQuestion( "Q3" );
            OpenQuestion q4 = new OpenQuestion( "Q4" );

            q4.Parent = q3;
            q3.Parent = q2;
            q2.Parent = q1;

            Assert.IsTrue( q1.Contains( q4 ) );
        }
        public void check_questions_add_feature()
        {
            DForm form = new DForm( "Title", "Nunit" );

            QuestionBase oq = form.Questions.AddNewQuestion( typeof( OpenQuestion ) );
            Assert.IsInstanceOf( typeof( OpenQuestion ), oq );
            Assert.AreEqual( form.Questions, oq.Parent );

            QuestionBase q1 = new OpenQuestion( "First Question" );
            QuestionBase q2 = new OpenQuestion( "Second Question" );
            form.Questions.AddNewQuestion( q1 );
            Assert.IsTrue( form.Questions.Contains( q1 ) );
            Assert.Throws<ArgumentException>( () => form.Questions.AddNewQuestion( q1 ) );
            Assert.DoesNotThrow( () => form.Questions.AddNewQuestion( q2 ) );
        }
        public void LaTotale()
        {
            DForm f = new DForm("Title", "Nunit");

            OpenQuestion qOpen=(OpenQuestion)f.Questions.AddNewQuestion(typeof(OpenQuestion));
            qOpen.Title = "First Question in the World! ";
            qOpen.AllowEmptyAnswer = false;

            FormAnswer a = f.CreateAnswer("Emilie");
            AnswerBase theAnswerOfEmilieToqOpen = a.FindAnswer(qOpen);
            if ( theAnswerOfEmilieToqOpen==null)
            {
                theAnswerOfEmilieToqOpen = a.AddAnswerFor(qOpen);
            }

            Assert.IsInstanceOfType(typeof(OpenAnswer),theAnswerOfEmilieToqOpen);

            OpenAnswer emilieAnswer = (OpenAnswer)theAnswerOfEmilieToqOpen;
            emilieAnswer.FreeAnswer = "I'm very hapy to be here";
        }
        public void check_question_parent_changing()
        {
            DForm form = new DForm( "Title", "Nunit" );
            QuestionBase q1 = new OpenQuestion( "First Question" );
            QuestionBase q2 = new OpenQuestion( "Second Question" );

            q1.Parent = form.Questions;
            Assert.IsTrue( form.Questions.Contains( q1 ) );
        }
        public void check_questions_remove_feature()
        {
            DForm form = new DForm( "Title", "Nunit" );

            Assert.Throws<ArgumentNullException>( () => form.Questions.RemoveQuestion( null ) );

            QuestionBase q1 = new OpenQuestion( "First Question" );
            QuestionBase q2 = new OpenQuestion( "Second Question" );
            form.Questions.AddNewQuestion( q1 );
            Assert.DoesNotThrow( () => form.Questions.RemoveQuestion( q1 ) );
            Assert.IsNull( q1.Parent );
            Assert.IsFalse( form.Questions.Contains( q1 ) );
        }
 internal QuestionRoot()
     : base()
 {
     _form = null;
 }
 internal QuestionRoot( DForm form )
     : base("Question Root")
 {
     _form = form;
 }