示例#1
0
        public void ClearStatisticsTest()
        {
            var ts = new TestStatistic {
                Id = 1, NumberOfCorrect = 2, PercentOfCorrect = 50, Test = new Test(), TimeInMinutes = 1
            };

            var ent = new List <TestStatistic> {
                ts
            };

            var mockObj = TestsMethodsTests.Create(ent);

            var mockContext = new Mock <Test2DBContainer>();

            mockContext.Setup(m => m.TestStatistics).Returns(mockObj.Object);

            var service = new Service(mockContext.Object);

            service.ClearStatistics();

            var list = service.GetStatistics();

            //mockObj.Verify(x => x.RemoveRange(ent), Times.Once);
            mockContext.Verify(m => m.SaveChanges(), Times.Once);
        }
示例#2
0
        public SelectedTestViewModel(Test test)
        {
            _test = test;

            SelectedTest.Name  = _test.Name;
            SelectedTest.Theme = _test.Theme;

            QuestionsCount = _test.Questions.Count;

            testStatistic = statisticLogic.GetTestStatistic(_test.Name);

            SelectedTestStatistic.AttempsCount = testStatistic.AttempsCount;
            SelectedTestStatistic.SuccessCount = testStatistic.SuccessCount;

            /// TODO
            if (testStatistic.AttempsCount > 0)
            {
                SelectedTestStatistic.SuccessRate      = Math.Round((double)testStatistic.SuccessCount * 100 / testStatistic.AttempsCount, 2);
                SelectedTestStatistic.RightAnswersRate = Math.Round(testStatistic.RightAnswersProcent.AsQueryable().Sum() / testStatistic.AttempsCount, 2);
            }

            else
            {
                SelectedTestStatistic.SuccessRate      = 0;
                SelectedTestStatistic.RightAnswersRate = 0;
            }

            Execution      = new CommandParameter();
            Execution.Test = test;
        }
示例#3
0
        /// TODO Check if not Statistic
        public List <TestStatistic> GetAllStatistic()
        {
            List <TestStatistic> statistics = new List <TestStatistic>();

            string        path    = $"{Constants.StatisticPath}";
            DirectoryInfo dirInfo = new DirectoryInfo(path);

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }

            BinaryFormatter formatter = new BinaryFormatter();

            foreach (string file in Directory.EnumerateFiles(path, "*.dat"))
            {
                using (FileStream fileStream = File.Open(file, FileMode.OpenOrCreate))
                {
                    TestStatistic testStatistic = (TestStatistic)formatter.Deserialize(fileStream);
                    statistics.Add(testStatistic);
                }
            }

            return(statistics);
        }
示例#4
0
        public void SaveTestStatistic(TestStatistic testStatistic)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            using (FileStream fileStream = File.Open($"{Constants.StatisticPath}\\{testStatistic.Name}.dat", FileMode.OpenOrCreate))
            {
                formatter.Serialize(fileStream, testStatistic);
            }
        }
示例#5
0
        public TestStatistic OpenTestStatistic(string testName)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            using (FileStream fileStream = File.Open($"{Constants.StatisticPath}\\{testName}.dat", FileMode.OpenOrCreate))
            {
                TestStatistic testStatistic = (TestStatistic)formatter.Deserialize(fileStream);
                return(testStatistic);
            }
        }
示例#6
0
        public void SaveStatistics(UIStatistics statistics)
        {
            var t  = DbContext.Tests.FirstOrDefault(x => x.Name == statistics.TestName);
            var ts = new TestStatistic
            {
                NumberOfCorrect  = statistics.NumberOfCorrect,
                PercentOfCorrect = statistics.PercentOfCorrect,
                TimeInMinutes    = statistics.TimeInMinutes
            };

            t.TestStatistics.Add(ts);
            DbContext.SaveChanges();
        }
示例#7
0
        public void GetStatisticsTest()
        {
            var ts = new TestStatistic {
                Id = 1, NumberOfCorrect = 2, PercentOfCorrect = 50, Test = new Test(), TimeInMinutes = 1
            };

            var mockObj = TestsMethodsTests.Create(new List <TestStatistic> {
                ts
            });

            var mockContext = new Mock <Test2DBContainer>();

            mockContext.Setup(m => m.TestStatistics).Returns(mockObj.Object);

            var service = new Service(mockContext.Object);
            var list    = service.GetStatistics();

            Assert.IsTrue(list.Count == 1);
            Assert.AreEqual(2, list[0].NumberOfCorrect);
        }
示例#8
0
        /// TODO Procents and mb something else
        public void UpdateTestStatistic(string testName, TestResult testResult, int questionsAmount)
        {
            if (statisticFiles.CheckIfFileExists(testName, Constants.StatisticPath, "dat"))
            {
                TestStatistic testStatistic = statisticFiles.OpenTestStatistic(testName);
                testStatistic.AttempsCount++;

                testStatistic.RightAnswersProcent.Add(System.Math.Round((double)(Constants.Percent * testResult.AmountOfRight / questionsAmount), 2));
                testStatistic.RightAnswersCount.Add(testResult.AmountOfRight);

                if (testResult.Passed)
                {
                    testStatistic.SuccessCount++;
                }

                statisticFiles.SaveTestStatistic(testStatistic);
            }

            else
            {
                TestStatistic testStatistic = new TestStatistic()
                {
                    Name              = testName,
                    AttempsCount      = 1,
                    RightAnswersCount = new List <int>()
                    {
                        testResult.AmountOfRight
                    },
                    RightAnswersProcent = new List <double> {
                        System.Math.Round((double)(Constants.Percent * testResult.AmountOfRight / questionsAmount), 2)
                    }
                };

                if (testResult.Passed)
                {
                    testStatistic.SuccessCount++;
                }

                statisticFiles.CreateTestStatistic(testStatistic);
            }
        }
示例#9
0
        /// TODO Right answers, success count etc
        public TestStatistic GetTestStatistic(string testName)
        {
            if (statisticFiles.CheckIfFileExists(testName, Constants.StatisticPath, "dat"))
            {
                TestStatistic testStatistic = statisticFiles.OpenTestStatistic(testName);
                return(testStatistic);
            }

            else
            {
                TestStatistic testStatistic = new TestStatistic()
                {
                    Name                = testName,
                    AttempsCount        = 0,
                    RightAnswersCount   = new List <int>(),
                    SuccessCount        = 0,
                    RightAnswersProcent = new List <double>()
                };

                statisticFiles.CreateTestStatistic(testStatistic);
                return(testStatistic);
            }
        }