public HttpResponseMessage EndSequence(SequenceModel seqFromClient)
        {
            //ideally here we look up the elapsed time based on whats in the db
            //and not rely on them to report the time used but...
            //after all: manipulating this only hurts the user if they want to cheat
            var timeSpan = TimeSpan.FromMilliseconds(seqFromClient.ElapsedInMilliseconds);

            //ignore the results from the call to stop as for now the user is redirected
            //to the details page
            UserSessionStateless sessionMgr = new UserSessionStateless();

            sessionMgr.StopSequence(seqFromClient.SequenceId, seqFromClient.TextEntered, timeSpan);

            return(Request.CreateResponse(HttpStatusCode.OK, string.Empty));
        }
        public void stateless_stopping_sequence_saves_accuracy_with_correct_values()
        {
            UserSessionStateless session = new UserSessionStateless(_user);
            ITextSample          sample  = new TextSample()
            {
                SourceKey  = "http://some_url",
                SourceType = TextSampleSourceType.Wikipedia,
                Text       = "this is some sample text shown"
            };

            string      enteredText  = "this is somee SAMple tex shownn";
            int         elapsedInSec = 5;
            KeySequence seq          = session.StartNewSequence(sample);

            session.StopSequence(seq.KeySequenceId, enteredText, TimeSpan.FromSeconds(elapsedInSec));

            UserSessionHistory history = new UserSessionHistory();
            var keySeq = history.GetHistoryDetailsByKeySequence(seq.KeySequenceId);

            var accuracy = keySeq.KeySequenceAnalysis
                           .Where(ks => ks.AnalysisTypeId == (int)Analytics.AnalyticType.Accuracy)
                           .Select(s => s.AnalysisAccuracy)
                           .FirstOrDefault();

            Assert.That(accuracy, Is.Not.Null);
            Assert.That(accuracy.NumIncorrectChars, Is.EqualTo(3));
            Assert.That(accuracy.NumExtraChars, Is.EqualTo(2));
            Assert.That(accuracy.NumShortChars, Is.EqualTo(1));
            Assert.That(accuracy.NumWords, Is.EqualTo(6));

            //TODO: address this...
            //spaces are not currently counted towards the total number of characters
            //should they be?!...
            //Assert.That(accuracy.NumChars, Is.EqualTo(sample.GetText().Length));
            //Assert.That(accuracy.NumCorrectChars, Is.EqualTo(sample.GetText().Length - accuracy.NumIncorrectChars));
        }
        public void stateless_stopping_sequence_saves_speed_with_correct_values()
        {
            UserSessionStateless session = new UserSessionStateless(_user);
            ITextSample          sample  = new TextSample()
            {
                SourceKey  = "http://some_url",
                SourceType = TextSampleSourceType.Wikipedia,
                Text       = "this is some sample text shown"
            };

            string      enteredText  = "this is some SAMple tex shownn";
            int         elapsedInSec = 5;
            KeySequence seq          = session.StartNewSequence(sample);

            session.StopSequence(seq.KeySequenceId, enteredText, TimeSpan.FromSeconds(elapsedInSec));

            UserSessionHistory history = new UserSessionHistory();
            var keySeq = history.GetHistoryDetailsByKeySequence(seq.KeySequenceId);

            var speed = keySeq.KeySequenceAnalysis
                        .Where(ks => ks.AnalysisTypeId == (int)Analytics.AnalyticType.Speed)
                        .Select(s => s.AnalysisSpeed)
                        .FirstOrDefault();

            Assert.That(speed, Is.Not.Null);
            Assert.That(speed.TotalTimeInMilliSec, Is.EqualTo(elapsedInSec * 1000));

            double charsPerSec = (double)enteredText.Length / (double)elapsedInSec;

            Assert.That(speed.CharsPerSec, Is.EqualTo(Math.Round(charsPerSec, 2)));

            int    numWords    = enteredText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length;
            double wordsPerMin = (double)numWords / (elapsedInSec / (double)60);

            Assert.That(speed.WordPerMin, Is.EqualTo(wordsPerMin));
        }