示例#1
0
 public static List <TestDTO> GetTests()
 {
     using (Entities e = new Entities())
     {
         return(TestCasting.TestsToDTO(e.tests.ToList()));
     }
 }
示例#2
0
 //create a simple test
 public static WebResult AddSimpleTest(SimpleTest newtest)
 {
     using (Entities e = new Entities())
     {
         WebResult wb = new WebResult();
         try
         {
             //add new test
             var t = e.tests.Add(TestCasting.TestToDAL(newtest.test));
             //add classes o the new test
             t.classes = ClassCasting.ClassesToDAL(newtest.classes);
             //add questions to the new test
             t.questions = QuestionCasting.QuestionsToDAL(newtest.questions);
             wb.status   = true;
             wb.message  = "succeed";
             wb.value    = TestCasting.TestToDTO(t);
             e.SaveChanges();
             return(wb);
         }
         catch (Exception ex)
         {
             wb.status  = false;
             wb.message = ex.Message;
             return(wb);
         }
     }
 }
示例#3
0
        public void SimpleFlowTest_OneWayIn_OneWayOut()
        {
            var castingMock = new TestCasting <TestMockAddresses>();

            // Here the syntax is a bit confusing - we setup a receive for a corresponding send port
            // If the intention is to retain the semantics of setting up receive for a corresponding receive location
            // then the implementation of the method should be reversed - it shuold implement a send operation, and vice versa.
            castingMock
            .SetupReceive(r => r.ReceiveFirstMessage_FILE)
            .SetupSend(s => s.SendFirstMessage_FILE);

            var mold = new TestMold <TestMockAddresses>(castingMock);

            // What if we use the already set up receive endpoint instead of creating a new one.
            // It creates even further confusion
            // Something like mold.Send( adr => adr.ReceiveFirstMessage_FILE,
            //      op => { op.MessageEncoding = System.Text.Encoding.UTF8; op.RequestFilePath = "TestFileIn.txt"},
            //      ctx => ctx.LogInfo("Sending message to the integration"))
            mold.Send((c, ma) => new ReceiveEndpoint()
            {
                URL              = ma.ReceiveFirstMessage_FILE,
                MessageEncoding  = System.Text.Encoding.UTF8,
                RequestFilePath  = "TestFileIn.txt",
                TimeoutInSeconds = 10
            }
                      )
            .Receive((c, ma) => new SendEndpoint()
            {
                URL = ma.SendFirstMessage_FILE,
                TimeoutInSeconds = 10
            },
                     // TODO: Validation helpers for performing the reading and looking up inside messages
                     //       a piece of joyful cake
                     (i, v) =>
            {
                string fileContents;
                using (var sr = new System.IO.StreamReader(v))
                {
                    fileContents = sr.ReadToEnd();
                }

                Assert.AreEqual("This is a test file", fileContents, "The contents of the received file differs");

                return(true);
            });
        }
示例#4
0
        //create generated test
        public static WebResult AddGeneratedTest(GeneratedTest newtest)
        {
            using (Entities e = new Entities())
            {
                WebResult wb = new WebResult();
                try
                {
                    //add new test
                    test t = e.tests.Add(TestCasting.TestToDAL(newtest.test));
                    e.SaveChanges();
                    //add rand questions to the new test
                    List <question> newQuesList = RandQues(t.test_id, t.level, newtest.american,
                                                           newtest.yesNo, newtest.match, newtest.classes.FirstOrDefault().teacher_id, newtest.subCategories);
                    t.classes.AddRange(ClassCasting.ClassesToDAL(newtest.classes));
                    newQuesList.ForEach(q =>
                    {
                        question qq = new question()
                        {
                            question_level = q.question_level,
                            question_id    = q.question_id,
                            question_text  = q.question_text,
                            //// answers = q.answers,
                            // sub_category = q.sub_category,
                            sub_category_id = q.sub_category_id,
                            // tests = q.tests,
                            // type = q.type,
                            type_id = q.type_id
                        };
                        t.questions.Add(qq);
                    });
                    //t.questions.AddRange(newQuesList.ToList());

                    wb.status  = true;
                    wb.message = "succeed";
                    wb.value   = TestCasting.TestToDTO(t);
                    e.SaveChanges();
                    return(wb);
                }
                catch (Exception ex)
                {
                    wb.status  = false;
                    wb.message = ex.Message;
                    return(wb);
                }
            }
        }
示例#5
0
 public static TestDTO GetTestById(int id)
 {
     using (Entities e = new Entities())
     {
         try
         {
             var test = e.tests.FirstOrDefault(t => t.test_id == id);
             if (test != null)
             {
                 return(TestCasting.TestToDTO(test));
             }
             throw new Exception("test is not exists");
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
示例#6
0
 public static List <TestDTO> GetTestsForCategory(int categoryId)
 {
     using (Entities e = new Entities())
     {
         try
         {
             var subCategory = e.sub_category.Where(s => s.category_id == categoryId).ToList();
             var tests       = e.tests.Where(t => t.sub_category.FirstOrDefault(s => s.category_id == categoryId).category_id == categoryId).ToList();
             if (tests != null)
             {
                 return(TestCasting.TestsToDTO(tests));
             }
             throw new Exception("no tests");
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
示例#7
0
 public static TestDTO AddTest(TestDTO test)
 {
     using (Entities e = new Entities())
     {
         try
         {
             var cls = e.classes.FirstOrDefault(c => c.class_id == test.class_id);
             if (cls == null)
             {
                 throw new Exception("class id is not exists");
             }
             var t = e.tests.Add(TestCasting.TestToDAL(test));
             e.SaveChanges();
             return(TestCasting.TestToDTO(t));
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
示例#8
0
        public static SolveTest GetTest(int studentId, DateTime time)
        {
            using (Entities e = new Entities())
            {
                try
                {
                    SolveTest sTest   = new SolveTest();
                    test      testDal = new test();


                    var student = e.students.FirstOrDefault(s => s.userId == studentId);
                    if (student != null)
                    {
                        var teacherId = [email protected]_id;
                        var test      = e.tests.FirstOrDefault(t => t.teacherId == teacherId &&
                                                               t.test_date == time.Date && t.test_start_time <time.TimeOfDay && t.test_end_time> time.TimeOfDay);
                        var TTT = e.tests.ToList();
                        if (test != null)
                        {
                            sTest.test = TestCasting.TestToDTO(test);

                            sTest.questions = QuestionCasting.QuestionsToDTO((test.questions).ToList());
                            var x            = e.answers.ToList();
                            var questionsIds = sTest.questions.Select(t => t.question_id).ToList();
                            var y            = x.Where(a => questionsIds.Contains(a.question_id)).ToList();
                            sTest.answers = AnswerCasting.AnswersToDTO(y);
                            return(sTest);
                        }
                        throw new Exception("no test0");
                    }
                    throw new Exception("no student");
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
示例#9
0
        public void SimpleFlowTest_TwoWayIn_TwoWayOut()
        {
            var castingMock = new TestCasting <TestMockAddresses>();

            // Here the syntax is a bit confusing - we setup a receive to a receive location
            // If the intention is to retain the semantics of setting up receive for a corresponding receive location
            // then the implementation of the method should be reversed - it shuold implement a send operation, and vice versa.
            castingMock
            .SetupSendRequestAndReceiveResponse(r => r.TwoWayReceive_WebHTTP)
            .SetupReceiveRequestAndSendResponse(s => s.TwoWaySend_WebHTTP);

            var mold = new TestMold <TestMockAddresses>(castingMock);

            mold.InParallel((tm) =>
                            tm.ReceiveRequestAndSendResponse(
                                (ctx, adr) => new SendEndpoint()
            {
                URL             = adr.TwoWaySend_WebHTTP,
                MessageEncoding = System.Text.Encoding.UTF8,
                // DONE: This serves well for static responses, but one of the main challanges
                // with the BizUnit based implementation is the need to identify and send content
                // dynamically based on the contents of the request
                //ResponseFilePath = "TestFileResponse.txt",
                TimeoutInSeconds = 10
            },
                                (i, v) =>
            {
                string fileContents;
                using (var sr = new System.IO.StreamReader(v))
                {
                    fileContents = sr.ReadToEnd();
                }

                // TODO: Handle errors correctly in parallel scenarios
                //       In case a validation fails here, the process hangs
                Assert.AreEqual("This is a test request file", fileContents, "The contents of the received file differs");
                return(true);
            },
                                // TODO: consider to set the response strategy in the first parameter
                                // by specifying it as a property on a composit operation config object
                                resp =>
            {
                var strategy      = new StaticFileResponseStrategy();
                strategy.FilePath = "TestFileResponse.txt";

                return(strategy);
            }
                                )
                            ) // End of parallel actions
            .SendRequestAndReceiveResponse(
                (c, ma) => new ReceiveEndpoint()
            {
                URL              = ma.TwoWayReceive_WebHTTP,
                MessageEncoding  = System.Text.Encoding.UTF8,
                RequestFilePath  = "TestFileRequest.txt",
                TimeoutInSeconds = 10
            },
                v =>
            {
                string fileContents;
                using (var sr = new System.IO.StreamReader(v))
                {
                    fileContents = sr.ReadToEnd();
                }

                Assert.AreEqual("This is a test response file", fileContents, "The contents of the received file differs");

                return(true);
            }
                )
            .CleanUp(); // We call cleanup at the end
        }