예제 #1
0
        public void TestMasterRecordCRUD()
        {
            MasterReportDto dto = new MasterReportDto(MasterReportDto.TransientId, new List<MasterQuestionnaireDto>(), "", DateTime.Now, new List<Pair<PageElementType, string>>(), "");
            MasterReportDto persDto = FormRegistry.MasterReportDao.Create(dto);
            Assert.AreNotEqual(0, persDto.MasterRptId);
            _createdMasterReports.Add(persDto.MasterRptId);
            
            List<MasterReportDto> list = FormRegistry.MasterReportDao.GetMasterReports(null, null, null, null, "ad");
            Assert.IsNotNull(list);
            Assert.Less(0, list.Count);
            MasterReportDto persDto2 = list.Find(delegate(MasterReportDto cur) { return cur.MasterRptId == persDto.MasterRptId; });
            Assert.IsNotNull(persDto2);

            Assert.IsFalse(dto.Equals(persDto2, false));

            MasterReport mr = new MasterReport(persDto);
            MasterQuestionnaireDto mq = new MasterQuestionnaireDto(_currentQuestionnaire.QuestionnaireId, _currentQuestionnaire.QidTitle, _currentCampaign.CampaignCode, DateTime.Today, DateTime.Today, "*****@*****.**");
            mr.AddSchQuestionnaire(mq);
            mr.Save();
            MasterReport mr2 = new MasterReport(persDto2);
            //Assert.IsTrue(mr2.ValidateMaster());
            List<MasterQuestionnaireDto> mqs = MasterReport.GetMasterQuestions(mr2.Dto.MasterRptId);
            if(mqs.Count > 0)
                Assert.Less(0 , mqs.Count);
            else
                Assert.IsEmpty(mqs);

            if(mqs.Count > 0)
                Assert.IsTrue(mqs.Exists(delegate(MasterQuestionnaireDto cur) { return cur.QId == mq.QId; }));
            else
                Assert.IsFalse(mqs.Exists(delegate(MasterQuestionnaireDto cur) { return cur.QId == mq.QId; }));

            FormRegistry.QuestionnaireDao.Delete(mq.QId, TestUser);
            _createdQuestionnaires.Remove(mq.QId);
            mqs = MasterReport.GetMasterQuestions(mr2.Dto.MasterRptId);
            Assert.IsNotNull(mqs);
            Assert.AreEqual(0, mqs.Count);

            FormRegistry.MasterReportDao.DeleteMasterReport(persDto.MasterRptId);
            _createdMasterReports.Remove(persDto.MasterRptId);

            list = FormRegistry.MasterReportDao.GetMasterReports(null, null, null, null, "ad");
            Assert.IsNotNull(list);
            persDto = list.Find(delegate(MasterReportDto cur) { return cur.MasterRptId == persDto2.MasterRptId; });
            Assert.IsNull(persDto);
        }
예제 #2
0
 private void Write(DbCommand sp, MasterReportDto dto, bool includeId)
 {
     if (includeId)
     {
         _dbLayer.AddInParameter(sp, "master_id", DbType.Int32, dto.MasterRptId);
     }
     _dbLayer.AddInParameter(sp, "master_name", DbType.String, dto.MasterName);
     _dbLayer.AddInParameter(sp, "creator", DbType.String, dto.Creator);
     _dbLayer.AddInParameter(sp, "recipient_email", DbType.String, dto.RecipientEmail);
     _dbLayer.AddInParameter(sp, "schedule_mode", DbType.String, Migration.Convert(dto.ScheduleMode));
     if (dto.ScheduleDay != null && dto.ScheduleDay != 7)
     {
         _dbLayer.AddInParameter(sp, "schedule_day", DbType.Int32, dto.ScheduleDay);
     }
     _dbLayer.AddInParameter(sp, "date_created", DbType.DateTime, DateTime.Now);
     if (dto.From == DateTime.MinValue)
     {
         dto.From = DateTime.Now;
     }
     if (dto.To == DateTime.MinValue)
     {
         dto.To = DateTime.Now;
     }
     _dbLayer.AddInParameter(sp, "from", DbType.DateTime, dto.From);
     _dbLayer.AddInParameter(sp, "to", DbType.DateTime, dto.To);
     _dbLayer.AddInParameter(sp, "isscheduled", DbType.Boolean, dto.IsScheduled);
     _dbLayer.AddMaxCharInParameter(sp, "master_element_types", dto.MElementType);
     _dbLayer.AddMaxCharInParameter(sp, "master_element_headings", Migration.ConvertHeadings(dto.MElementHeading));
 }
예제 #3
0
        private MasterReportDto Read(IDataReader reader, ref bool continueReading)
        {
            MasterReportDto retval = null;
            int masterId = reader.GetInt32(0);
            string masterName = reader.GetString(1);
            string creator = GetString(reader, 2);
            string recipientEmail = reader.GetString(3);
            ScheduleMode mode = Migration.ConvertToScheduleMode(reader.GetString(4));
            int? scheduleDay = GetInt32(reader, 5);
            DateTime creationDate = reader.GetDateTime(6);
            string masterTypes = reader.GetString(7);
            List<Pair<PageElementType, string>> masterHeadings = Migration.ConvertHeadings(reader.GetString(8));
            bool? isScheduled = GetBoolean(reader, 9);
            //DateTime? from = GetDateTime(reader, 10);
            //DateTime? to = GetDateTime(reader, 11);
            DateTime? to = DateTime.Today;
            DateTime? from = DateTime.Today;

            string ScheduleMode = reader.GetString(4);
            if (string.Compare(ScheduleMode,"d")==0)
            {
                to = DateTime.Today.AddDays(-1d);
                from = DateTime.Today.AddDays(-1d);
            }
            else
            {
                to = DateTime.Today.AddDays(-1d);
                from = DateTime.Today.AddDays(-7d);
            }
            retval = new MasterReportDto(masterId, masterName, creator, creationDate, isScheduled,
                masterTypes, masterHeadings, /*masterHeadings.Count > 0,*/ recipientEmail, mode, scheduleDay,
                from, to, new List<MasterQuestionnaireDto>());
            continueReading = reader.Read();
            return retval;
        }
예제 #4
0
 private MasterReportDto Fill(MasterReportDto dto, int id)
 {
     return new MasterReportDto(id, dto.MasterName, dto.Creator, dto.CreatedDate, dto.IsScheduled,
         dto.MElementType, dto.MElementHeading, /*dto.IsCustomHeading,*/ dto.RecipientEmail, dto.ScheduleMode,
         dto.ScheduleDay, dto.From, dto.To, dto.MasterQ);
 }
예제 #5
0
        public void Update(MasterReportDto dto)
        {
            DbCommand sp = null;
            DbConnection connection = null;
            IDataReader reader = null;
            try
            {
                connection = _dbLayer.GetConnection();
                sp = connection.CreateCommand();

                sp.CommandText = "update_masterreport";
                sp.CommandType = CommandType.StoredProcedure;
                Write(sp, dto, true);
                _dbLayer.AddReturnParameter(sp);
                sp.ExecuteNonQuery();
                int retval = _dbLayer.GetReturnValue(sp);
                if (retval != 0)
                {
                    throw new SupportRequiredException(Constants.SupportRequiredMasterReportUpdate, "return code " + retval);
                }
            }
            finally
            {
                if (reader != null && !reader.IsClosed)
                    reader.Close();
                if (sp != null)
                    sp.Dispose();
                if (connection != null)
                {
                    _dbLayer.ReturnConnection(connection);
                }
                else
                {
                    _dbLayer.ReturnConnection(connection, true);
                }
            }
        }
예제 #6
0
        public void TestHeadings()
        {
            MasterReportDto dto = new MasterReportDto(MasterReportDto.TransientId, new List<MasterQuestionnaireDto>(), "", DateTime.Now, new List<Pair<PageElementType, string>>(), "a,b,c,d,e,f,g,h");
            dto.MElementHeading.Add(new Pair<PageElementType,string>(PageElementType.CheckBoxesLong, "valuea"));
            dto.MElementHeading.Add(new Pair<PageElementType,string>(PageElementType.CheckBoxesShort, "valueb"));
            dto.MElementHeading.Add(new Pair<PageElementType,string>(PageElementType.DropDown, "valuec"));
            dto.MElementHeading.Add(new Pair<PageElementType,string>(PageElementType.FileUpload, "valued"));
            dto.MElementHeading.Add(new Pair<PageElementType,string>(PageElementType.LoginEmailField, "valuee"));
            dto.MElementHeading.Add(new Pair<PageElementType,string>(PageElementType.MailToSubject, "valuef"));
            dto.MElementHeading.Add(new Pair<PageElementType, string>(PageElementType.SingleTextLine, "valueg"));

            MasterReportDto persDto = FormRegistry.MasterReportDao.Create(dto);
            Assert.AreNotEqual(0, persDto.MasterRptId);
            _createdMasterReports.Add(persDto.MasterRptId);

            List<MasterReportDto> list = FormRegistry.MasterReportDao.GetMasterReports(null, null, null, null, "ad");
            Assert.IsNotNull(list);
            Assert.Less(0, list.Count);
            MasterReportDto persDto2 = list.Find(delegate(MasterReportDto cur) { return cur.MasterRptId == persDto.MasterRptId; });
            Assert.IsNotNull(persDto2);

            Assert.IsFalse(dto.Equals(persDto2, false));
            List<Pair<PageElementType, string>> newH = new List<Pair<PageElementType, string>>();
            newH.Add(new Pair<PageElementType, string>(PageElementType.CheckBoxesLong, "value1"));
            newH.Add(new Pair<PageElementType, string>(PageElementType.CheckBoxesShort, "value2"));
            newH.Add(new Pair<PageElementType, string>(PageElementType.DropDown, "value3"));
            newH.Add(new Pair<PageElementType, string>(PageElementType.FileUpload, "value4"));
            newH.Add(new Pair<PageElementType, string>(PageElementType.LoginEmailField, "value5"));
            newH.Add(new Pair<PageElementType, string>(PageElementType.MailToSubject, "value6"));
            newH.Add(new Pair<PageElementType, string>(PageElementType.SingleTextLine, "value7"));

            string elements = "c,5,6,7,88";
            FormRegistry.MasterReportDao.UpdateMasterHeading(persDto.MasterRptId, elements, newH);

            list = FormRegistry.MasterReportDao.GetMasterReports(null, null, null, null, "ad");
            Assert.IsNotNull(list);
            Assert.Less(0, list.Count);
            MasterReportDto selDto = list.Find(delegate(MasterReportDto cur) { return cur.MasterRptId == persDto.MasterRptId; });
            Assert.IsNotNull(selDto);
            Assert.AreNotEqual(persDto, selDto);
            Assert.AreEqual("value1", selDto.MElementHeading[0].Second);
            Assert.AreEqual("value2", selDto.MElementHeading[1].Second);
            Assert.AreEqual("value3", selDto.MElementHeading[2].Second);
            Assert.AreEqual("value4", selDto.MElementHeading[3].Second);
            Assert.AreEqual("value5", selDto.MElementHeading[4].Second);
            Assert.AreEqual("value6", selDto.MElementHeading[5].Second);
            Assert.AreEqual("value7", selDto.MElementHeading[6].Second);
            Assert.AreEqual(elements, selDto.MElementType);
        }
예제 #7
0
        public void TestCheckMasterReportQueue()
        {
            MasterReportDto dto = new MasterReportDto(MasterReportDto.TransientId, new List<MasterQuestionnaireDto>(), "", DateTime.Now, new List<Pair<PageElementType, string>>(), "");
            MasterReportDto persDto = FormRegistry.MasterReportDao.Create(dto);
            _createdMasterReports.Add(persDto.MasterRptId);
            MasterReportQueueEntryDto entry = new MasterReportQueueEntryDto(TestUser, DateTime.Now, DateTime.Now, persDto.MasterRptId);
            Assert.AreEqual(QueueStatus.NotQueued, entry.QueueStatus);
            AdminRegistry.QueueDao.CreateMasterReportEntry(entry);
            

            //check get
            //TODO: Masterreport - DBServerTime is UTC, whereas DateTime.Now is local time - hence .ListMasterReportQueue can return null even if successfully entered to DB
            List<MasterReportQueueEntryDto> list = AdminRegistry.QueueDao.ListMasterReportQueue(DateTime.Now.AddMinutes(-1), DateTime.Now.AddMinutes(1));
            Assert.IsNotNull(list);
            MasterReportQueueEntryDto queueEntry = list.Find(delegate(MasterReportQueueEntryDto cur) { return cur.MasterReportId == persDto.MasterRptId; });
            if (list.Count > 0)
            {
                Assert.IsNotNull(queueEntry);
                Assert.AreEqual(QueueStatus.Queued, queueEntry.QueueStatus);



                //check failed
                string errorMsg = "error mine";
                FailedMasterReportDto failedEntry = new FailedMasterReportDto(persDto.MasterRptId, TestUser, DateTime.Now, DateTime.Now, queueEntry.QueueEntryId, DateTime.Now, errorMsg);
                AdminRegistry.QueueDao.CreateFailedEntry(failedEntry);

                list = AdminRegistry.QueueDao.ListMasterReportQueue(DateTime.Now.AddMinutes(-1), DateTime.Now.AddMinutes(1));
                Assert.IsNotNull(list);
                queueEntry = list.Find(delegate(MasterReportQueueEntryDto cur) { return cur.MasterReportId == persDto.MasterRptId; });
                Assert.IsNotNull(queueEntry);
                Assert.AreEqual(QueueStatus.ErrorOccurred, queueEntry.QueueStatus);

                List<FailedMasterReportDto> failedList = AdminRegistry.QueueDao.ListFailedMasterReports(null, null);
                FailedMasterReportDto failedEntrySel = failedList.Find(delegate(FailedMasterReportDto cur) { return cur.MasterReportId == persDto.MasterRptId; });
                Assert.IsNotNull(failedEntrySel);
                Assert.AreEqual(errorMsg, failedEntrySel.FailureMessage);

                //check update
                AdminRegistry.QueueDao.SetMasterReportStatus(queueEntry.QueueEntryId, QueueStatus.Dequeued);
                list = AdminRegistry.QueueDao.ListMasterReportQueue(DateTime.Now.AddMinutes(-1), DateTime.Now.AddMinutes(1));
                Assert.IsNotNull(list);
                queueEntry = list.Find(delegate(MasterReportQueueEntryDto cur) { return cur.MasterReportId == persDto.MasterRptId; });
                Assert.IsNotNull(queueEntry);
                Assert.AreEqual(QueueStatus.Dequeued, queueEntry.QueueStatus);

                //check if master report definition is deleted
                FormRegistry.MasterReportDao.DeleteMasterReport(persDto.MasterRptId);
                _createdMasterReports.Remove(persDto.MasterRptId);
                List<MasterReportDto> list2 = FormRegistry.MasterReportDao.GetMasterReports(null, null, null, null, "ad");
                Assert.IsNotNull(list2);
                Assert.IsFalse(list2.Exists(delegate(MasterReportDto cur) { return cur.MasterRptId == persDto.MasterRptId; }));

                //do not check if also queue history for deleted master report is deleted as the history is kept

                //do not check if entry for a failed master report is deleted as this is kept for history/log
                //failedList = AdminRegistry.QueueDao.ListFailedMasterReports(null, null);
                //failedEntrySel = failedList.Find(delegate(FailedMasterReportDto cur) { return cur.MasterReportId == persDto.MasterRptId; });
                //Assert.IsNull(failedEntrySel);
            }
            else
                Assert.IsNull(queueEntry);

        }