public void Can_get_test_details()
        {
            #region Arrange
            var test = new TestDto
            {
                Author       = ProfileModelDto.Map(TestPofile),
                CreationDate = DateTime.Now,
                Name         = "new test",
                TestType     = TestTypeModelDto.Map(TestTestType),
                Questions    = new List <TestQuestionModelDto> {
                    TestQuestionModelDto.Map(TestQuestion)
                }
            };
            using (var session = DataAccess.OpenSession())
            {
                var course = session.Get <CourseModel>(1);
                course.Tests.Add(TestDto.UnMap(test));
                session.Flush();
            }
            #endregion

            #region Act

            test = new TestService().GetTestDetails(3);

            #endregion

            #region Assert
            Assert.That(test.Name, Is.EqualTo("new test"));
            Assert.That(test.Questions.Count, Is.EqualTo(1));
            Assert.That(test.Questions.First().Answers.Count, Is.EqualTo(1));
            #endregion
        }
Exemplo n.º 2
0
        public bool UpdateTest(TestDto test)
        {
            try
            {
                DataAccess.InTransaction(session => session.Update(TestDto.UnMap(test)));

                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error("Error : TestService.UpdateTest - {0}", ex.Message);
                return(false);
            }
        }
Exemplo n.º 3
0
 public int AddTestToLearningMaterial(int learningMaterialId, TestDto test)
 {
     try
     {
         var id = -1;
         DataAccess.InTransaction(session =>
         {
             var learningMaterial = session.Get <LearningMaterialModel>(learningMaterialId);
             var model            = TestDto.UnMap(test);
             id = (int)session.Save(model);
             learningMaterial.Tests.Add(model);
             session.Save(learningMaterial);
         });
         Logger.Trace("Created Test id - {0}", id);
         return(id);
     }
     catch (Exception ex)
     {
         Logger.Error("Error : AddTestToLearningMaterial - {0}", ex.Message);
         return(-1);
     }
 }
Exemplo n.º 4
0
 public int AddTestToCourse(int courseId, TestDto test)
 {
     try
     {
         var id = -1;
         DataAccess.InTransaction(session =>
         {
             var course = session.Get <CourseModel>(courseId);
             var model  = TestDto.UnMap(test);
             id         = (int)session.Save(model);
             course.Tests.Add(model);
             session.Save(course);
         });
         Logger.Trace("Created Test id - {0}", id);
         return(id);
     }
     catch (Exception ex)
     {
         Logger.Error("Error : AddTestToCourse - {0}", ex.Message);
         return(-1);
     }
 }
        public void Can_update_test()
        {
            #region Arrange
            var test = new TestDto {
                Author = ProfileModelDto.Map(TestPofile), CreationDate = DateTime.Now, Name = "new test", TestType = TestTypeModelDto.Map(TestTestType)
            };
            using (var session = DataAccess.OpenSession())
            {
                var course = session.Get <CourseModel>(1);
                course.Tests.Add(TestDto.UnMap(test));
                session.Flush();
            }

            using (var session = DataAccess.OpenSession())
            {
                var course = session.Get <CourseModel>(1);
                Assert.That(course.Tests[0].Name, Is.EqualTo("new test"));
                test.ID = course.Tests[0].ID;
            }
            #endregion

            #region Act
            test.Name = "updated test";
            bool updateOk = new TestService().UpdateTest(test);

            #endregion

            #region Assert
            using (var session = DataAccess.OpenSession())
            {
                var course = session.Get <CourseModel>(1);
                Assert.That(course.Tests[0].Name, Is.EqualTo("updated test"));
                Assert.That(updateOk, Is.True);
            }
            #endregion
        }