public QuizSlide(SlideInfo slideInfo, Quiz quiz) : base(quiz.Blocks, slideInfo, quiz.Title, Guid.Parse(quiz.Id)) { MaxDropCount = quiz.MaxDropCount; MaxScore = Blocks.OfType<AbstractQuestionBlock>().Sum(block => block.MaxScore); Quiz = quiz; }
public void Test() { var serializer = new XmlSerializer(typeof(Quiz)); var quiz = new Quiz { Title = "Title", Id = "Id", Blocks = new SlideBlock[] { new MdBlock {Markdown = "This is quiz!"}, new IsTrueBlock { Id = "1", Text = "Это утверждение ложно", }, new ChoiceBlock { Text = "What is the \nbest color?", Items = new[] { new ChoiceItem {Id="1", Description = "black", IsCorrect = true}, new ChoiceItem {Id="2", Description = "green"}, new ChoiceItem {Id="3", Description = "red"}, } }, new ChoiceBlock { Multiple = true, Text = "What does the fox say?", Items = new[] { new ChoiceItem {Description = "Apapapapa", IsCorrect = true}, new ChoiceItem {Description = "Ding ding ding", IsCorrect = true}, new ChoiceItem {Description = "Mew"}, } }, new FillInBlock { Text = "What does the fox say?", Regexes = new[] {new RegexInfo {Pattern = "([Dd]ing )+"}, new RegexInfo {Pattern = "Ap(ap)+"}}, Sample = "Apapap" }, } }; var w1 = new StringWriter(); var ns = new XmlSerializerNamespaces(); ns.Add("x", "http://www.w3.org/2001/XMLSchema-instance"); serializer.Serialize(w1, quiz, ns); ApprovalTests.Approvals.Verify(w1.ToString()); Console.WriteLine(w1.ToString()); Console.WriteLine(); var quiz2 = serializer.Deserialize(new StringReader(w1.ToString())); var w2 = new StringWriter(); serializer.Serialize(w2, quiz2, ns); Console.WriteLine(w2.ToString()); Assert.AreEqual(w1.ToString(), w2.ToString()); }
public bool HasEqualStructureWith(Quiz other) { if (Blocks.Length != other.Blocks.Length) return false; for (var blockIdx = 0; blockIdx < Blocks.Length; blockIdx++) { var block = Blocks[blockIdx]; var otherBlock = other.Blocks[blockIdx]; var questionBlock = block as AbstractQuestionBlock; var otherQuestionBlock = otherBlock as AbstractQuestionBlock; /* Ignore non-question blocks */ if (questionBlock == null) continue; /* If our block is question, block in other slide must be question with the same Id */ if (otherQuestionBlock == null || questionBlock.Id != otherQuestionBlock.Id) return false; if (! questionBlock.HasEqualStructureWith(otherQuestionBlock)) return false; } return true; }
public static void BuildUp(Quiz quiz, DirectoryInfo slideDir, CourseSettings settings) { var context = new BuildUpContext(slideDir, settings, null); var blocks = quiz.Blocks.SelectMany(b => b.BuildUp(context, ImmutableHashSet<string>.Empty)); quiz.Blocks = blocks.ToArray(); }
public QuizSlide(SlideInfo slideInfo, Quiz quiz) : base(quiz.Blocks, slideInfo, quiz.Title, quiz.Id) { MaxDropCount = quiz.MaxDropCount; MaxScore = Blocks.Count(block => block is AbstractQuestionBlock); }
public void BeSerializable() { var serializer = new XmlSerializer(typeof(Quiz)); var quiz = new Quiz { Title = "Title", Id = "Id", Blocks = new SlideBlock[] { new MdBlock { Markdown = "This is quiz!" }, new IsTrueBlock { Id = "1", Text = "Это утверждение ложно", }, new ChoiceBlock { Text = "What is the \nbest color?", Items = new[] { new ChoiceItem { Id = "1", Description = "black", IsCorrect = true }, new ChoiceItem { Id = "2", Description = "green" }, new ChoiceItem { Id = "3", Description = "red" }, } }, new ChoiceBlock { Multiple = true, Text = "What does the fox say?", Items = new[] { new ChoiceItem { Description = "Apapapapa", IsCorrect = true }, new ChoiceItem { Description = "Ding ding ding", IsCorrect = true }, new ChoiceItem { Description = "Mew" }, } }, new FillInBlock { Text = "What does the fox say?", Regexes = new[] { new RegexInfo { Pattern = "([Dd]ing )+" }, new RegexInfo { Pattern = "Ap(ap)+" } }, Sample = "Apapap" }, } }; var w1 = new StringWriter(); var ns = new XmlSerializerNamespaces(); ns.Add("x", "http://www.w3.org/2001/XMLSchema-instance"); serializer.Serialize(w1, quiz, ns); ApprovalTests.Approvals.Verify(w1.ToString()); w1.ToString().DeserializeXml <Quiz>(); }