Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

multiple choice question feature added to main area, javascripts refa…

…ctored
  • Loading branch information...
commit c41811bcdf060ea2dd2e2ec2533fc2bdf66d75ca 1 parent 199c933
@mule authored
View
2  DotNetQuiz/Areas/Admin/ViewModels/QuestionViewModel.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Web;
+using DotNetQuizDataAccess.Models;
namespace DotNetQuiz.Areas.Admin.ViewModels
{
@@ -9,6 +10,7 @@ public class QuestionViewModel
{
public string Id { get; set; }
public string QuestionText { get; set; }
+ public Question.AnswerType AnswerType { get; set; }
public List<Tuple<int,string>> AnswerOptions { get; set; }
}
}
View
10 DotNetQuiz/Controllers/QuizController.cs
@@ -30,7 +30,8 @@ public ActionResult Index()
{
QuestionText = questionStr,
AnswerOptions =
- new List<Tuple<int, string>> { answer1,answer2,asnwer3,answer4}
+ new List<Tuple<int, string>> { answer1,answer2,asnwer3,answer4},
+ AnswerType = Question.AnswerType.SingleChoice
};
@@ -38,7 +39,7 @@ public ActionResult Index()
}
[HttpPost]
- public ActionResult Answer(int question, int answer, int quizId)
+ public ActionResult Answer(int question, ICollection<int> answers, int quizId)
{
return Json(new {correct = false, message = "Test message"});
@@ -63,7 +64,9 @@ public ActionResult NextQuestion()
Id = "1",
QuestionText = questionStr,
AnswerOptions =
- new List<Tuple<int, string>> { answer1,answer2,asnwer3,answer4}
+ new List<Tuple<int, string>> { answer1,answer2,asnwer3,answer4},
+ AnswerType = Question.AnswerType.MultipleChoice
+
};
@@ -101,5 +104,6 @@ public ActionResult QuizStatus(int quizId)
}
+
}
}
View
169 DotNetQuiz/Scripts/DotNetQuiz.js
@@ -98,6 +98,175 @@ function QuestionEditor() {
}
+function Question() {
+
+ var id, questionText, answerType;
+ this.AnswerOptions = new Array();
+ this.Id = id;
+ this.QuestionText = questionText;
+ this.AnswerType = answerType;
+
+
+}
+
+
+function Quiz() {
+ var quizId;
+ var startTime;
+ var host = '';
+ //var currentQuestionId;
+
+ this.CurrentQuestion = new Question();
+ this.Host = host;
+ var me = this;
+
+ //page resouces
+ var answerBox = $('#answerBox');
+ var questionBox = $('#questionBox');
+ var txtQuestion = questionBox.find('#question');
+ var answerTemplate = $('#answerOptionsTemplate');
+ var multiChoiceAnswer = $('#answerOptionsTemplateMultiChoice');
+ var answerOptions = $('#answerOptions');
+ var btnAnswerQuestion = $('#btnAnswer');
+ var btnNextQuestion = $('#btnNextQuestion');
+
+ wireEvents();
+
+
+
+ Quiz.prototype.StartNewQuiz = function () {
+
+ $.ajax({
+ url: me.Host + "/Quiz/NewQuiz",
+ type: "POST",
+ datatype: "json",
+
+ success: function (result) {
+ quizId = result.QuizId;
+ me.startTime = result.StartTime;
+ me.GetQuestionFromServer();
+ }
+
+ });
+ };
+
+ Quiz.prototype.GetQuizStatus = function () {
+
+ var id = $.cookie('DotNetQuiz');
+
+ if (id != null) {
+
+ this.quizId = parseInt(id);
+
+ $.ajax({
+ url: me.Host + "/Quiz/QuizStatus",
+ type: "POST",
+ data: { quizId: me.quizId },
+ datatype: "json",
+ success: function (result) {
+ me.startTime = result.StartTime;
+
+ me.GetQuestionFromServer();
+ },
+ failure: function (result) {
+ alert('Could not get Quiz status');
+ }
+ });
+ } else {
+ me.StartNewQuiz();
+ }
+ };
+
+
+ Quiz.prototype.AnswerQuestion = function () {
+
+ var answers = new Array();
+ $('.answer input:[checked=true]').each(function () {
+
+ var id = $(this).val();
+ answers.push(id);
+
+ });
+
+
+ $.ajax({
+ url: me.Host + "/Quiz/Answer",
+ type: "POST",
+ traditional: true,
+ data: { question: me.CurrentQuestion.Id, answers: answers, quizId: me.quizId },
+ dataType: "json",
+ success: function (result) {
+ $('#questionBox').hide();
+ var answer = $('#answerBox');
+ if (result.correct == false) {
+ answer.find('#succesBox').text("Answer was incorrect");
+ answer.find('#messageBox').text(result.message);
+ } else {
+ answer.find('#succesBox').text("Answer was correct");
+ answer.find('#messageBox').text(result.message);
+ }
+ answer.show();
+
+ }
+ });
+ };
+
+
+
+ Quiz.prototype.GetQuestionFromServer = function() {
+
+ $.ajax({
+ url: me.Host + "/Quiz/NextQuestion",
+ type: "POST",
+ data: quizId,
+ dataType: "json",
+
+ success: function(result) {
+
+ me.CurrentQuestion.Id = result.Id;
+ me.CurrentQuestion.QuestionText = result.QuestionText;
+ me.CurrentQuestion.AnswerOptions = result.AnswerOptions;
+ me.CurrentQuestion.AnswerType = result.AnswerType;
+ me.RefreshQuestion();
+
+ }
+
+ //TODO: Add failure handling
+ });
+ };
+
+ Quiz.prototype.RefreshQuestion = function () {
+
+ if (answerBox != null && txtQuestion != null && answerOptions != null && answerTemplate != null && questionBox != null && multiChoiceAnswer != null) {
+ answerBox.hide();
+ txtQuestion.text(me.CurrentQuestion.QuestionText);
+ answerOptions.empty();
+
+ if (me.CurrentQuestion.AnswerType == 1)
+ answerTemplate.tmpl(me.CurrentQuestion.AnswerOptions).appendTo(answerOptions);
+
+ if (me.CurrentQuestion.AnswerType == 2)
+ multiChoiceAnswer.tmpl(me.CurrentQuestion.AnswerOptions).appendTo(answerOptions);
+
+ questionBox.show();
+ }
+ //TODO: Log error if resources not found
+
+ };
+
+ function wireEvents() {
+
+ if(btnAnswerQuestion!=null && btnNextQuestion!=null) {
+ btnAnswerQuestion.bind('click', function() { me.AnswerQuestion(); return false; });
+ btnNextQuestion.bind('click', function() { me.GetQuestionFromServer(); return false; });
+ }
+
+
+ }
+
+}
+
+
View
121 DotNetQuiz/Views/Quiz/Index.cshtml
@@ -9,6 +9,7 @@
@section AdditionalScripts{
<script src="@Url.Content("~/Scripts/jquery.tmpl.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.cookie.js")" type="text/javascript"></script>
+<script src="@Url.Content("~/Scripts/DotNetQuiz.js")" type="text/javascript"></script>
}
@@ -22,7 +23,7 @@
</div>
<div id="answerBtnBox">
- <input id="btnAnswer" type="button" value="Answer" onclick="quiz.AnswerQuestion()" />
+ <input id="btnAnswer" type="button" value="Answer" />
</div>
}
</section>
@@ -31,7 +32,7 @@
<div id="succesBox"></div>
<div id="messageBox"></div>
<div>
-<input type="button" id="btnNextQuestion" value="Next question" onclick="quiz.GetQuestion(); "/>
+<input type="button" id="btnNextQuestion" value="Next question"/>
</div>
</section>
@@ -46,6 +47,14 @@
<input type="radio" value=${Item1} name="Answer" id="Answer"> ${Item2}
</div>
</script>
+
+<script id="answerOptionsTemplateMultiChoice" type="text/x-jquery-tmpl">
+
+ <div class="answer">
+ <input type="checkbox" value=${Item1} name="Answer" id="Answer"> ${Item2}
+ </div>
+</script>
+
<script type="text/javascript">
@@ -57,115 +66,7 @@
-function Quiz()
-{
- var quizId;
- var startTime;
- var currentQuestionId;
-
- var me = this;
-
- Quiz.prototype.GetQuestion = function () {
- $.ajax({
- url: "Quiz/NextQuestion",
- type: "POST",
- data: quizId,
- dataType: "json",
-
- success: function (result) {
- me.currentQuestionId = result.QuestionId;
- var answer = $('#answerBox');
- answer.hide();
- var qBox = $('#questionBox');
- qBox.find('#question').text(result.QuestionText);
- var answerOptions = $('#answerOptions');
- answerOptions.empty();
- $('#answerOptionsTemplate').tmpl(result.AnswerOptions).appendTo(answerOptions);
-
- qBox.show();
- }
-
-
- });
- };
-
-
- Quiz.prototype.StartNewQuiz = function() {
-
- $.ajax({
- url: "Quiz/NewQuiz",
- type: "POST",
- datatype: "json",
-
- success: function(result) {
- quizId = result.QuizId;
- me.startTime = result.StartTime;
- me.GetQuestion();
- }
-
- });
- };
- Quiz.prototype.GetQuizStatus = function () {
-
- var id = $.cookie('DotNetQuiz');
-
- if (id != null) {
-
- this.quizId = parseInt(id);
-
- $.ajax({
- url: "Quiz/QuizStatus",
- type: "POST",
- data: { quizId: me.quizId },
- datatype: "json",
- success: function (result) {
- me.startTime = result.StartTime;
-
- me.GetQuestion();
- },
- failure: function (result) {
- alert('Could not get Quiz status');
- }
- });
- } else {
- me.StartNewQuiz();
- }
- };
-
-
- Quiz.prototype.AnswerQuestion = function () {
-
- var answerId = $('.answer input:radio[checked=true]').val();
-
-
- $.ajax({
- url: "Quiz/Answer",
- type: "POST",
- data: { question: me.currentQuestionId, answer: parseInt(answerId), quizId: me.quizId },
- dataType: "json",
- success: function (result) {
- $('#questionBox').hide();
- var answer = $('#answerBox');
- if (result.correct == false) {
- answer.find('#succesBox').text("Answer was incorrect");
- answer.find('#messageBox').text(result.message);
- } else {
- answer.find('#succesBox').text("Answer was correct");
- answer.find('#messageBox').text(result.message);
- }
- answer.show();
-
- }
- });
-
-
-
-
-
- };
-
-}
</script>
}
View
1  DotNetQuizJSTests/Default.htm
@@ -4,6 +4,7 @@
<title>QUnit Test Suite</title>
<script src="/scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="/scripts/jquery.tmpl.min.js" type="text/javascript"></script>
+ <script src="/scripts/jquery.cookie.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css"
type="text/css" media="screen">
<script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script>
View
1  DotNetQuizJSTests/DotNetQuizJSTests.csproj
@@ -55,6 +55,7 @@
<Content Include="scripts\DotNetQuizTests.js" />
<Content Include="scripts\DotNetQuiz.js" />
<Content Include="scripts\jquery-1.5.1.min.js" />
+ <Content Include="scripts\jquery.cookie.js" />
<Content Include="scripts\jquery.tmpl.min.js" />
<Content Include="scripts\qunit.css" />
<Content Include="scripts\qunit.js" />
View
439 DotNetQuizJSTests/scripts/DotNetQuiz.js
@@ -2,23 +2,34 @@ function QuestionEditor() {
var questionText = '';
var answerOptions = new Array();
+
var me = this;
this.QuestionText = questionText;
this.AnswerOptions = answerOptions;
+ this.AnswerType = 0;
+
+
+
//Find needed resources from html
var questionTxtBox = $('#txtQuestion');
var answerOptionsBox = $('#AnswerOptions');
var answerOptionTemplate = $('#answerOptionEditTemplate');
+ var answerTypeDropDown = $('#AnswerType');
wireEvents();
+
+
+
QuestionEditor.prototype.CreateQuestion = function () {
getQuestionText();
getAnswerOptions();
+ me.AnswerType = $(answerTypeDropDown).val();
+
sendQuestionToServer();
};
@@ -31,7 +42,7 @@ function QuestionEditor() {
function getQuestionText() {
- var questionTxt = questionTxtBox.text();
+ var questionTxt = questionTxtBox.val();
me.QuestionText = questionTxt;
}
@@ -39,12 +50,14 @@ function QuestionEditor() {
function getAnswerOptions() {
+ me.AnswerOptions = new Array();
+
var options = answerOptionsBox.find('.answerOption');
options.each(function () {
var id = $(this).attr('id');
- var answerTxt = $(this).find('.txtAnswerOption').text();
+ var answerTxt = $(this).find('.txtAnswerOption').val();
var correctAnswer = $(this).find('.cbxCorrect').attr('checked');
- me.AnswerOptions.push({ 'id': id, 'text': answerTxt, 'correct': correctAnswer });
+ me.AnswerOptions.push({ 'id': id, 'AnswerText': answerTxt, 'correct': correctAnswer });
});
}
@@ -59,17 +72,17 @@ function QuestionEditor() {
{ removeAnswerOption($(this))});
$('#btnAddAnswer').bind('click', function () { me.AddAnswerOption(); return false; });
-
+ $('#btnCreateQuestion').bind('click', function() { me.CreateQuestion(); return false; });
}
-
-
+
+
function sendQuestionToServer() {
$.ajax({
- url: "AdminHome/CreateQuestion",
+ url: "/Admin/AdminHome/CreateQuestion",
type: "POST",
- data: { questionTxt: me.QuestionText, answerOptions: me.AnswerOptions },
+ data: $.toDictionary({ QuestionText: me.QuestionText, AnswerOptions: me.AnswerOptions, AnswerType: me.AnswerType}),
datatype: "json",
success: function (result) {
alert(result);
@@ -79,8 +92,416 @@ function QuestionEditor() {
alert(result);
}
});
+
+ }
+
+}
+
+
+function Question() {
+
+ var id, questionText, answerType;
+ this.AnswerOptions = new Array();
+ this.Id = id;
+ this.QuestionText = questionText;
+ this.AnswerType = answerType;
+
+
+}
+
+
+function Quiz() {
+ var quizId;
+ var startTime;
+ var host = '';
+ //var currentQuestionId;
+
+ this.CurrentQuestion = new Question();
+ this.Host = host;
+ var me = this;
+
+ //page resouces
+ var answerBox = $('#answerBox');
+ var questionBox = $('#questionBox');
+ var txtQuestion = questionBox.find('#question');
+ var answerTemplate = $('#answerOptionsTemplate');
+ var multiChoiceAnswer = $('#answerOptionsTemplateMultiChoice');
+ var answerOptions = $('#answerOptions');
+ var btnAnswerQuestion = $('#btnAnswer');
+ var btnNextQuestion = $('#btnNextQuestion');
+
+ wireEvents();
+
+
+
+ Quiz.prototype.StartNewQuiz = function () {
+
+ $.ajax({
+ url: me.Host + "/Quiz/NewQuiz",
+ type: "POST",
+ datatype: "json",
+
+ success: function (result) {
+ quizId = result.QuizId;
+ me.startTime = result.StartTime;
+ me.GetQuestionFromServer();
+ }
+
+ });
+ };
+
+ Quiz.prototype.GetQuizStatus = function () {
+
+ var id = $.cookie('DotNetQuiz');
+
+ if (id != null) {
+
+ this.quizId = parseInt(id);
+
+ $.ajax({
+ url: me.Host + "/Quiz/QuizStatus",
+ type: "POST",
+ data: { quizId: me.quizId },
+ datatype: "json",
+ success: function (result) {
+ me.startTime = result.StartTime;
+
+ me.GetQuestionFromServer();
+ },
+ failure: function (result) {
+ alert('Could not get Quiz status');
+ }
+ });
+ } else {
+ me.StartNewQuiz();
+ }
+ };
+
+
+ Quiz.prototype.AnswerQuestion = function () {
+
+ var answers = new Array();
+ $('.answer input:[checked=true]').each(function () {
+
+ var id = $(this).attr('id');
+ answers.push(id);
+
+ });
+
+
+ $.ajax({
+ url: me.Host + "/Quiz/Answer",
+ type: "POST",
+ data: { question: me.CurrentQuestion.Id, answers: answers, quizId: me.quizId },
+ dataType: "json",
+ success: function (result) {
+ $('#questionBox').hide();
+ var answer = $('#answerBox');
+ if (result.correct == false) {
+ answer.find('#succesBox').text("Answer was incorrect");
+ answer.find('#messageBox').text(result.message);
+ } else {
+ answer.find('#succesBox').text("Answer was correct");
+ answer.find('#messageBox').text(result.message);
+ }
+ answer.show();
+
+ }
+ });
+ };
+
+
+
+ Quiz.prototype.GetQuestionFromServer = function() {
+
+ $.ajax({
+ url: me.Host + "/Quiz/NextQuestion",
+ type: "POST",
+ data: quizId,
+ dataType: "json",
+
+ success: function(result) {
+
+ me.CurrentQuestion.Id = result.Id;
+ me.CurrentQuestion.QuestionText = result.QuestionText;
+ me.CurrentQuestion.AnswerOptions = result.AnswerOptions;
+ me.CurrentQuestion.AnswerType = result.AnswerType;
+ me.RefreshQuestion();
+
+ }
+
+ //TODO: Add failure handling
+ });
+ };
+
+ Quiz.prototype.RefreshQuestion = function () {
+
+ if (answerBox != null && txtQuestion != null && answerOptions != null && answerTemplate != null && questionBox != null && multiChoiceAnswer != null) {
+ answerBox.hide();
+ txtQuestion.text(me.CurrentQuestion.QuestionText);
+ answerOptions.empty();
+
+ if (me.CurrentQuestion.AnswerType == 1)
+ answerTemplate.tmpl(me.CurrentQuestion.AnswerOptions).appendTo(answerOptions);
+
+ if (me.CurrentQuestion.AnswerType == 2)
+ multiChoiceAnswer.tmpl(me.CurrentQuestion.AnswerOptions).appendTo(answerOptions);
+
+ questionBox.show();
+ }
+ //TODO: Log error if resources not found
+
+ };
+
+ function wireEvents() {
+ if(btnAnswerQuestion!=null && btnNextQuestion!=null) {
+ btnAnswerQuestion.bind('click', function() { me.AnswerQuestion(); return false; });
+ btnNextQuestion.bind('click', function() { me.GetQuestionFromServer(); return false; });
+ }
+
+
}
+}
+
+
+
+
+
+
+
+/*!
+
+* jQuery toDictionary() plugin
+
+*
+
+* Version 1.2 (11 Apr 2011)
+
+*
+
+* Copyright (c) 2011 Robert Koritnik
+
+* Licensed under the terms of the MIT license
+
+* http://www.opensource.org/licenses/mit-license.php
+
+*/
+
+
+
+(function ($) {
+
+
+
+ // #region String.prototype.format
+
+ // add String prototype format function if it doesn't yet exist
+
+ if ($.isFunction(String.prototype.format) === false) {
+
+ String.prototype.format = function () {
+
+ var s = this;
+
+ var i = arguments.length;
+
+ while (i--) {
+
+ s = s.replace(new RegExp("\\{" + i + "\\}", "gim"), arguments[i]);
+
+ }
+
+ return s;
+
+ };
+
+ }
+
+ // #endregion
+
+
+
+ // #region Date.prototype.toISOString
+
+ // add Date prototype toISOString function if it doesn't yet exist
+
+ if ($.isFunction(Date.prototype.toISOString) === false) {
+
+ Date.prototype.toISOString = function () {
+
+ var pad = function (n, places) {
+
+ n = n.toString();
+
+ for (var i = n.length; i < places; i++) {
+
+ n = "0" + n;
+
+ }
+
+ return n;
+
+ };
+
+ var d = this;
+
+ return "{0}-{1}-{2}T{3}:{4}:{5}.{6}Z".format(
+
+ d.getUTCFullYear(),
+
+ pad(d.getUTCMonth() + 1, 2),
+
+ pad(d.getUTCDate(), 2),
+
+ pad(d.getUTCHours(), 2),
+
+ pad(d.getUTCMinutes(), 2),
+
+ pad(d.getUTCSeconds(), 2),
+
+ pad(d.getUTCMilliseconds(), 3)
+
+ );
+
+ };
+
+ }
+
+ // #endregion
+
+
+
+ var _flatten = function (input, output, prefix, includeNulls) {
+
+ if ($.isPlainObject(input)) {
+
+ for (var p in input) {
+
+ if (includeNulls === true || typeof (input[p]) !== "undefined" && input[p] !== null) {
+
+ _flatten(input[p], output, prefix.length > 0 ? prefix + "." + p : p, includeNulls);
+
+ }
+
+ }
+
+ }
+
+ else {
+
+ if ($.isArray(input)) {
+
+ $.each(input, function (index, value) {
+
+ _flatten(value, output, "{0}[{1}]".format(prefix, index));
+
+ });
+
+ return;
+
+ }
+
+ if (!$.isFunction(input)) {
+
+ if (input instanceof Date) {
+
+ output.push({ name: prefix, value: input.toISOString() });
+
+ }
+
+ else {
+
+ var val = typeof (input);
+
+ switch (val) {
+
+ case "boolean":
+
+ case "number":
+
+ val = input;
+
+ break;
+
+ case "object":
+
+ // this property is null, because non-null objects are evaluated in first if branch
+
+ if (includeNulls !== true) {
+
+ return;
+
+ }
+
+ default:
+
+ val = input || "";
+
+ }
+
+ output.push({ name: prefix, value: val });
+
+ }
+
+ }
+
+ }
+
+ };
+
+
+
+ $.extend({
+
+ toDictionary: function (data, prefix, includeNulls) {
+
+ /// <summary>Flattens an arbitrary JSON object to a dictionary that Asp.net MVC default model binder understands.</summary>
+
+ /// <param name="data" type="Object">Can either be a JSON object or a function that returns one.</data>
+
+ /// <param name="prefix" type="String" Optional="true">Provide this parameter when you want the output names to be prefixed by something (ie. when flattening simple values).</param>
+
+ /// <param name="includeNulls" type="Boolean" Optional="true">Set this to 'true' when you want null valued properties to be included in result (default is 'false').</param>
+
+
+
+ // get data first if provided parameter is a function
+
+ data = $.isFunction(data) ? data.call() : data;
+
+
+
+ // is second argument "prefix" or "includeNulls"
+
+ if (arguments.length === 2 && typeof (prefix) === "boolean") {
+
+ includeNulls = prefix;
+
+ prefix = "";
+
+ }
+
+
+
+ // set "includeNulls" default
+
+ includeNulls = typeof (includeNulls) === "boolean" ? includeNulls : false;
+
+
+
+ var result = [];
+
+ _flatten(data, result, prefix || "", includeNulls);
+
+
+
+ return result;
+
+ }
+
+ });
+
+})(jQuery);
-}
View
15 DotNetQuizJSTests/scripts/DotNetQuizTests.js
@@ -32,6 +32,21 @@ test('CreateQuestionWithAnswerTest()', function () {
ok(qEditor.AnswerOptions.length == 1,qEditor.AnswerOptions.toString());
+});
+
+test('GetQuestionTest()', function () {
+ stop();
+ var quiz = new Quiz();
+
+
+ quiz.Host = 'localhost:53311';
+
+
+ quiz.GetQuizStatus();
+ quiz.GetQuestionFromServer();
+ setTimeout()
+ ok(quiz.CurrentQuestion.AnswerOptions.length > 0);
+
});
View
41 DotNetQuizJSTests/scripts/jquery.cookie.js
@@ -0,0 +1,41 @@
+/**
+ * jQuery Cookie plugin
+ *
+ * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ */
+jQuery.cookie = function (key, value, options) {
+
+ // key and at least value given, set cookie...
+ if (arguments.length > 1 && String(value) !== "[object Object]") {
+ options = jQuery.extend({}, options);
+
+ if (value === null || value === undefined) {
+ options.expires = -1;
+ }
+
+ if (typeof options.expires === 'number') {
+ var days = options.expires, t = options.expires = new Date();
+ t.setDate(t.getDate() + days);
+ }
+
+ value = String(value);
+
+ return (document.cookie = [
+ encodeURIComponent(key), '=',
+ options.raw ? value : encodeURIComponent(value),
+ options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
+ options.path ? '; path=' + options.path : '',
+ options.domain ? '; domain=' + options.domain : '',
+ options.secure ? '; secure' : ''
+ ].join(''));
+ }
+
+ // key and possibly options given, get cookie...
+ options = value || {};
+ var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
+ return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
+};
View
23 DotNetQuizTests/DotNetQuizTests.csproj
@@ -33,9 +33,28 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="AsyncCtpLibrary, Version=1.0.4107.18181, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
+ <Reference Include="Glimpse.Core">
+ <HintPath>..\packages\Glimpse.0.85\lib\net40\Glimpse.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="Glimpse.Mvc3">
+ <HintPath>..\packages\Glimpse.Mvc3.0.85\lib\net40\Glimpse.Mvc3.dll</HintPath>
+ </Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ <Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="Newtonsoft.Json, Version=4.0.2.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL" />
+ <Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL" />
+ <Reference Include="Raven.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=37f41c7f99471593, processorArchitecture=MSIL" />
+ <Reference Include="Raven.Client.Debug">
+ <HintPath>..\packages\RavenDB.1.0.0.482\lib\net40\Raven.Client.Debug.dll</HintPath>
+ </Reference>
<Reference Include="Raven.Client.Lightweight, Version=1.0.0.0, Culture=neutral, PublicKeyToken=37f41c7f99471593, processorArchitecture=MSIL" />
+ <Reference Include="Raven.Client.MvcIntegration">
+ <HintPath>..\packages\RavenDB.1.0.0.482\lib\net40\Raven.Client.MvcIntegration.dll</HintPath>
+ </Reference>
<Reference Include="StructureMap">
<HintPath>..\packages\structuremap.2.6.3\lib\StructureMap.dll</HintPath>
</Reference>
@@ -63,6 +82,10 @@
<Reference Include="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
+ <Reference Include="Telerik.Web.Mvc, Version=2011.2.712.340, Culture=neutral, PublicKeyToken=121fae78165ba3d4, processorArchitecture=MSIL" />
+ <Reference Include="WebActivator">
+ <HintPath>..\packages\WebActivator.1.4.4\lib\net40\WebActivator.dll</HintPath>
+ </Reference>
<Reference Include="xunit">
<HintPath>..\packages\xunit.1.8.0.1549\lib\xunit.dll</HintPath>
</Reference>
View
30 DotNetQuizTests/QuizControllerTest.cs
@@ -1,4 +1,5 @@
-using System.Web.Helpers;
+using System.Diagnostics;
+using System.Web.Helpers;
using System.Web.Script.Serialization;
using DotNetQuiz.Controllers;
using DotNetQuizDataAccess.Models;
@@ -103,11 +104,11 @@ public void AnswerTest()
{
QuizController target = new QuizController();
int question = 1;
- int answer = 1;
+ var answers = new int[] {1};
int quiz = 1;
- var actual = target.Answer(question, answer,quiz) as JsonResult;
+ var actual = target.Answer(question, answers,quiz) as JsonResult;
dynamic data = actual.Data;
Assert.IsTrue(data.correct == false);
@@ -118,5 +119,28 @@ public void AnswerTest()
}
+
+ /// <summary>
+ ///A test for NextQuestion
+ ///</summary>
+ // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
+ // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
+ // whether you are testing a page, web service, or a WCF service.
+ [TestMethod()]
+ [HostType("ASP.NET")]
+ [AspNetDevelopmentServerHost("D:\\projects\\DotNet-Quiz\\DotNetQuiz", "/")]
+ [UrlToTest("http://localhost:53311/")]
+ public void NextQuestionTest()
+ {
+ QuizController target = new QuizController();
+
+ var actual = target.NextQuestion() as JsonResult;
+
+ dynamic data = actual.Data;
+
+
+ Assert.IsTrue(data.AnswerType == Question.AnswerType.MultipleChoice);
+
+ }
}
}
View
BIN  packages/RavenDB.1.0.0.482/server/Data/Data
Binary file not shown
View
BIN  packages/RavenDB.1.0.0.482/server/Data/logs/RVN.log
Binary file not shown
View
BIN  packages/RavenDB.1.0.0.482/server/Data/system/RVN.chk
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.