Example #1
0
        public void TestDashboardNoRequestEditor()
        {
            // Create a test request in the DB
            var rc1 = new RequestContent {
                patientFName = "DInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
                requestStatus = Constants.RequestStatus.Completed,
                timeOpened = DateTime.Now
            };
            var rc2 = new RequestContent {
                patientFName = "DInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
                requestStatus = Constants.RequestStatus.Open,
                timeOpened = DateTime.Now
            };
            var rmc = new RequestManagementController();
            long rid1 = rmc.create(rc1);
            long rid2 = rmc.create(rc2);

            _ctm.removeRole(Constants.Roles.REQUEST_EDITOR);
            _ctm.removeRole(Constants.Roles.ADMINISTRATOR);

            // Go to the Dashboard
            _driver.Navigate().GoToUrl(CommonTestingMethods.getURL());

            ReadOnlyCollection<IWebElement> elements =
                _driver.FindElements(By.CssSelector("[data-id='" + rid1 + "']"));
            Assert.Greater(elements.Count, 0);

            elements =
                _driver.FindElements(By.CssSelector("[data-id='" + rid2 + "']"));
            Assert.AreEqual(0, elements.Count);

            elements = _driver.FindElements(By.ClassName("add-button"));
            Assert.AreEqual(0, elements.Count);

            // Add the roles back
            _ctm.addRole(Constants.Roles.ADMINISTRATOR);
            _ctm.addRole(Constants.Roles.REQUEST_EDITOR);

            Request rq1 = _cdc.Requests.FirstOrDefault(r => r.RequestID == rid1);
            Request rq2 = _cdc.Requests.FirstOrDefault(r => r.RequestID == rid2);
            if (rq1 == null || rq2 == null) {
                Assert.Fail("Request is null");
            }
            _cdc.Requests.DeleteOnSubmit(rq1);
            _cdc.Requests.DeleteOnSubmit(rq2);
            _cdc.SubmitChanges();
        }
Example #2
0
        public ActionResult Create()
        {
            var dc = new DropdownManagementController();
            var reqContent = new RequestContent {
                timeOpened = DateTime.Now
            };

            ViewBag.RequestorTypes = new SelectList(
                dc.getEntries(Constants.DropdownTable.RequestorType),
                "id", "text");
            ViewBag.Regions = new SelectList(
                dc.getEntries(Constants.DropdownTable.Region),
                "id", "text");

            ViewBag.GenderOptions = new SelectList(Constants.genderOptions);

            return View(reqContent);
        }
Example #3
0
        public void TestViewRequestInvalid()
        {
            // Create a test request in the DB
            var rc = new RequestContent {
                patientFName = "VRInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
                requestStatus = Constants.RequestStatus.Invalid
            };
            var rmc = new RequestManagementController();
            long rid = rmc.create(rc);

            // Remove the Viewer Role from the User
            _ctm.removeRole(Constants.Roles.ADMINISTRATOR);

            // Attempt to go to the appropriate View Request Page Directly
            _driver.Navigate().GoToUrl(CommonTestingMethods.getURL());
            _driver.Navigate()
                   .GoToUrl(CommonTestingMethods.getURL() + "/Request/Details/" +
                            rid.ToString(CultureInfo.InvariantCulture));

            // Assert that we're redirected to the not authorized page
            StringAssert.Contains("/Request/Details", _driver.Url);
            _driver.FindElement(By.Id("error-header"));
            IWebElement msg = _driver.FindElement(By.Id("error-message"));
            StringAssert.AreEqualIgnoringCase(
                "You do not have the necessary permissions to view this request.",
                msg.Text);

            // Cleanup
            Request rq = _cdc.Requests.FirstOrDefault(r => r.RequestID == rid);
            if (rq == null) {
                Assert.Fail("Request is null");
            }

            _cdc.Requests.DeleteOnSubmit(rq);
            _cdc.SubmitChanges();

            _ctm.addRole(Constants.Roles.ADMINISTRATOR);
        }
        /// <summary>
        ///     Edit a request properties, question-response pairs and references
        ///     for a given request ID.
        /// </summary>
        /// <param name="reqContent">
        ///     Request content to modify in the database.
        /// </param>
        public void edit(RequestContent reqContent)
        {
            if (reqContent.requestID == -1) {
                throw new Exception("Invalid request.");
            }

            using (var trans = new TransactionScope()) {
                // Check if the request exists
                int exists =
                    (from reqs in _db.Requests
                     where reqs.RequestID == reqContent.requestID
                     select reqs.RequestID).Count();

                if (exists < 1) {
                    throw new Exception("Request does not exist.");
                }

                // Update the Request entity
                Request req = createRequestEntity(reqContent);
                _db.SubmitChanges();

                // Retrieve the list of current QuestionResponseIDs for
                // the request
                List<long> currQrIds =
                    getQuestionResponseIds(reqContent.requestID);

                // Check all QuestionResponses being updated against
                // those already in the database
                foreach (QuestionResponseContent qrContent in
                    reqContent.questionResponseList) {
                    qrContent.requestID = reqContent.requestID;

                    if (currQrIds.Remove(qrContent.questionResponseID)) {
                        // QuestionResponse already exists in the database
                        // Update QuestionResponse, References and Keywords
                        QuestionResponse qr =
                            createQuestionResponseEntity(qrContent);
                        _db.SubmitChanges();

                        // Retrieve all Keyword IDs for the
                        // given QuestionResponse
                        List<int> currKwIds = getKeywordIds(
                            reqContent.requestID,
                            qrContent.questionResponseID);

                        // Check all Keywords for the QuestionResponse
                        foreach (String kw in
                            qrContent.keywords) {
                            int kwId = getKeywordIdAndActivate(kw);

                            if (!currKwIds.Remove(kwId)) {
                                // Set Keyword for QuestionResponse

                                // Check if already associated with Question
                                var kq =
                                    (from kqs in _db.KeywordQuestions
                                     where kqs.KeywordID == kwId &&
                                           kqs.RequestID ==
                                           req.RequestID &&
                                           kqs.QuestionResponseID ==
                                           qr.QuestionResponseID
                                     select kqs)
                                        .SingleOrDefault();

                                if (kq != null) {
                                    continue;
                                }

                                kq = new KeywordQuestion {
                                    KeywordID = kwId,
                                    RequestID = reqContent.requestID,
                                    QuestionResponseID =
                                        qrContent.questionResponseID
                                };

                                _db.KeywordQuestions.InsertOnSubmit(kq);
                                _db.SubmitChanges();
                            }
                        }

                        // Remaining Keywords not associated anymore
                        foreach (int kwId in currKwIds) {
                            KeywordQuestion kq =
                                getKeywordQuestionEntity(
                                    kwId,
                                    reqContent.requestID,
                                    qrContent.questionResponseID);

                            _db.KeywordQuestions.DeleteOnSubmit(kq);
                            _db.SubmitChanges();
                        }

                        // Retrieve all Reference IDs for the given
                        // QuestionResponse
                        List<long> currRefIds = getReferenceIds(
                            reqContent.requestID,
                            qrContent.questionResponseID);

                        // Check all References for the QuestionResponse
                        foreach (ReferenceContent refContent in
                            qrContent.referenceList) {
                            refContent.requestID = req.RequestID;
                            refContent.questionResponseID =
                                qr.QuestionResponseID;

                            Reference r =
                                createReferenceEntity(refContent);

                            if (refContent.referenceID == -1) {
                                // Insert new Reference into database
                                _db.References.InsertOnSubmit(r);
                            } else {
                                currRefIds.Remove(refContent.referenceID);
                            }

                            _db.SubmitChanges();
                        }

                        // Remaining References do not exist anymore
                        foreach (long refId in currRefIds) {
                            Reference r = getReferenceEntity(
                                refId,
                                reqContent.requestID,
                                qrContent.questionResponseID);

                            _db.References.DeleteOnSubmit(r);
                            _db.SubmitChanges();
                        }
                    } else {
                        // Add new QuestionResponse
                        QuestionResponse qr =
                            createQuestionResponseEntity(qrContent);

                        _db.QuestionResponses.InsertOnSubmit(qr);
                        _db.SubmitChanges();

                        qrContent.questionResponseID =
                            qr.QuestionResponseID;

                        // Add new Keywords to QuestionResponse
                        foreach (String kw in qrContent.keywords) {
                            int kwId = getKeywordIdAndActivate(kw);

                            // Check if already associated with Question
                            var kq =
                                (from kqs in _db.KeywordQuestions
                                 where kqs.KeywordID == kwId &&
                                       kqs.RequestID ==
                                       req.RequestID &&
                                       kqs.QuestionResponseID ==
                                       qr.QuestionResponseID
                                 select kqs)
                                    .SingleOrDefault();

                            if (kq != null) {
                                continue;
                            }

                            // Set Keyword for QuestionResponse
                            kq = new KeywordQuestion {
                                KeywordID = kwId,
                                RequestID = req.RequestID,
                                QuestionResponseID = qr.QuestionResponseID
                            };

                            _db.KeywordQuestions.InsertOnSubmit(kq);
                            _db.SubmitChanges();
                        }

                        // Add all References for the QuestionResponse
                        foreach (ReferenceContent refContent in
                            qrContent.referenceList) {
                            refContent.requestID = req.RequestID;
                            refContent.questionResponseID =
                                qr.QuestionResponseID;

                            Reference r =
                                createReferenceEntity(refContent);

                            _db.References.InsertOnSubmit(r);
                            _db.SubmitChanges();
                        }
                    }
                }

                // Remove QuestionResponses that no longer exist
                foreach (long qrId in currQrIds) {
                    // Delete all Keyword associations
                    List<int> currKwIds = getKeywordIds(
                        reqContent.requestID, qrId);

                    foreach (int kwId in currKwIds) {
                        KeywordQuestion kq = getKeywordQuestionEntity(
                            kwId, reqContent.requestID, qrId);

                        _db.KeywordQuestions.DeleteOnSubmit(kq);
                        _db.SubmitChanges();
                    }

                    // Delete all References
                    List<long> currRefIds = getReferenceIds(
                        reqContent.requestID, qrId);

                    foreach (long refId in currRefIds) {
                        Reference r = getReferenceEntity(
                            refId, reqContent.requestID, qrId);

                        _db.References.DeleteOnSubmit(r);
                        _db.SubmitChanges();
                    }

                    // Delete QuestionResponse
                    QuestionResponse qr = getQuestionResponseEntity(
                        reqContent.requestID, qrId);

                    _db.QuestionResponses.DeleteOnSubmit(qr);
                    _db.SubmitChanges();
                }

                trans.Complete();
            }
        }
Example #5
0
        public ActionResult Create(RequestContent reqContent)
        {
            var rmc = new RequestManagementController();

            bool valid = ModelState.IsValid;

            if (reqContent.parentRequestID != null &&
                !rmc.requestExists((long) reqContent.parentRequestID)) {
                ModelState.AddModelError("NonexistentParentRequest",
                                         "Parent Request ID must correspond to an existing request.");
                valid = false;
            }

            if (Request.Form["mark_as_complete"] != null) {
                foreach (
                    QuestionResponseContent qrContent in
                        reqContent.questionResponseList) {
                    if (String.IsNullOrEmpty(qrContent.question) ||
                        removeNewLinesAndTabs(qrContent.question).Equals("<br />") ||
                        String.IsNullOrEmpty(qrContent.response) ||
                        removeNewLinesAndTabs(qrContent.response).Equals("<br />") ||
                        qrContent.questionTypeID == null ||
                        qrContent.tumourGroupID == null ||
                        qrContent.timeSpent == null ||
                        qrContent.severity == null ||
                        qrContent.consequence == null ||
                        qrContent.keywords.Count < 1) {
                        ModelState.AddModelError("IncompleteQuestion",
                                                 "Questions must be completed before marking request as complete.");
                        valid = false;
                        break;
                    }

                    if (qrContent.keywords.Any(keyword => keyword.Length > 128)) {
                        ModelState.AddModelError("KeywordTooLong",
                                                 "Keywords must be less than 128 characters.");
                        valid = false;
                    }

                    if (qrContent.referenceList.Any(refContent => String.IsNullOrEmpty(refContent.referenceString))) {
                        ModelState.AddModelError("IncompleteReference",
                                                 "References must be completed before marking request as complete.");
                        valid = false;
                    }
                }

                reqContent.timeClosed = DateTime.Now;
                reqContent.requestStatus = Constants.RequestStatus.Completed;
            }

            // Encode HTML in question responses
            // Replace null references with empty string
            foreach (
                QuestionResponseContent qrContent in
                    reqContent.questionResponseList) {
                if (!String.IsNullOrEmpty(qrContent.question)) {
                    qrContent.question = HttpUtility.HtmlEncode(
                        removeNewLinesAndTabs(qrContent.question))
                                                    .Replace("&#39;", "'");
                }
                if (!String.IsNullOrEmpty(qrContent.response)) {
                    qrContent.response = HttpUtility.HtmlEncode(
                        removeNewLinesAndTabs(qrContent.response))
                                                    .Replace("&#39;", "'");
                }
                if (!String.IsNullOrEmpty(qrContent.specialNotes)) {
                    qrContent.specialNotes = HttpUtility.HtmlEncode(
                        removeNewLinesAndTabs(qrContent.specialNotes))
                                                        .Replace("&#39;", "'");
                }

                foreach (
                    ReferenceContent refContent in qrContent.referenceList) {

                    refContent.referenceString =
                        refContent.referenceString == null ?
                            "" :
                            refContent.referenceString.Replace("\\", "\\\\");
                }
            }

            if (!valid) {
                var dc = new DropdownManagementController();

                ViewBag.RequestorTypes = new SelectList(
                    dc.getEntries(Constants.DropdownTable.RequestorType),
                    "id", "text");
                ViewBag.Regions = new SelectList(
                    dc.getEntries(Constants.DropdownTable.Region),
                    "id", "text");

                ViewBag.GenderOptions = new SelectList(Constants.genderOptions);

                return View(reqContent);
            }

            long reqId = rmc.create(reqContent);

            var uc = new UserManagementController();
            UserProfile up = uc.getUserProfile(User.Identity.Name);
            var almc = new AuditLogManagementController();
            almc.addEntry(reqId, up.UserId,
                          Constants.AuditType.RequestCreation,
                          reqContent.timeOpened);

            if (reqContent.requestStatus == Constants.RequestStatus.Completed &&
                reqContent.timeClosed != null) {
                almc.addEntry(reqId, up.UserId,
                              Constants.AuditType.RequestCompletion,
                              (DateTime) reqContent.timeClosed);
            }

            if (Roles.IsUserInRole(Constants.Roles.VIEWER)) {
                return RedirectToAction("Details", "Request",
                                        new {
                                            id = reqId
                                        });
            }

            return RedirectToAction("Index", "Home",
                                    new {
                                        status =
                                        Constants.URLStatus.SuccessfulCreate
                                    });
        }
Example #6
0
        public void TestQuickSearchRequestID()
        {
            var rc = new RequestContent {
                patientFName = "SInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
            };

            // Create the RequestContent
            var rmc = new RequestManagementController();
            long rid = rmc.create(rc);

            _driver.Navigate().GoToUrl(CommonTestingMethods.getURL());
            _driver.FindElement(By.Id(Constants.UIString.ItemIDs.SEARCH_DIV))
                   .SendKeys(rid.ToString(CultureInfo.InvariantCulture));
            _ctm.findAndClick(Constants.UIString.ItemIDs.SEARCH_BUTTON,
                              "/Request/Details/" +
                              rid.ToString(CultureInfo.InvariantCulture));

            //========================================
            // All done! Cleanup time!
            //========================================
            var cdc2 = new CAIRSDataContext();
            // Cleanup the AuditLog
            IQueryable<AuditLog> logs =
                cdc2.AuditLogs.Where(al => al.RequestID == rid);
            cdc2.AuditLogs.DeleteAllOnSubmit(logs);
            cdc2.SubmitChanges();

            // Cleanup Request
            Request req = cdc2.Requests.FirstOrDefault(r => r.RequestID == rid);
            if (req == null) {
                Assert.Fail("Request can't be found for Teardown!");
            }
            cdc2.Requests.DeleteOnSubmit(req);
            cdc2.SubmitChanges();
        }
Example #7
0
        public void TestQuickSearchKeywords()
        {
            var kw = new Keyword {
                KeywordValue = "SInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture)
            };
            _cdc.Keywords.InsertOnSubmit(kw);
            _cdc.SubmitChanges();

            // Setup the request
            var qrc = new QuestionResponseContent {
                keywords = new List<string> {kw.KeywordValue}
            };
            var rc = new RequestContent {
                patientFName = "SInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
            };
            rc.addQuestionResponse(qrc);

            // Create the RequestContent
            var rmc = new RequestManagementController();
            long rid = rmc.create(rc);

            //========================================
            // And we're ready to go!
            //========================================
            _driver.Navigate().GoToUrl(CommonTestingMethods.getURL());
            _driver.FindElement(By.Id(Constants.UIString.ItemIDs.SEARCH_DIV))
                   .SendKeys(kw.KeywordValue);
            _ctm.findAndClick(Constants.UIString.ItemIDs.SEARCH_BUTTON,
                              "/Search/Search");

            // Check Results
            ReadOnlyCollection<IWebElement> row1 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid + "']"));

            Assert.IsTrue(row1.Count > 0, "Request 1 not in results!");

            //========================================
            // All done! Cleanup time!
            //========================================
            // Cleanup KeywordQuestion
            var cdc2 = new CAIRSDataContext();
            KeywordQuestion keyq =
                cdc2.KeywordQuestions.FirstOrDefault(kq => kq.RequestID == rid);
            if (keyq == null) {
                Assert.Fail("KeywordQuestion can't be found for Teardown!");
            }
            cdc2.KeywordQuestions.DeleteOnSubmit(keyq);
            cdc2.SubmitChanges();

            // Cleanup Keyword
            Keyword kwDel =
                cdc2.Keywords.FirstOrDefault(k => k.KeywordID == kw.KeywordID);
            if (kwDel == null) {
                Assert.Fail("KeywordQuestion can't be found for Teardown!");
            }
            cdc2.Keywords.DeleteOnSubmit(kwDel);
            cdc2.SubmitChanges();

            // Cleanup QuestionResponse
            QuestionResponse qresp =
                cdc2.QuestionResponses.FirstOrDefault(qr => qr.RequestID == rid);
            if (qresp == null) {
                Assert.Fail("QuestionResponse can't be found for Teardown!");
            }
            cdc2.QuestionResponses.DeleteOnSubmit(qresp);
            cdc2.SubmitChanges();

            // Cleanup Request
            Request req = cdc2.Requests.FirstOrDefault(r => r.RequestID == rid);
            if (req == null) {
                Assert.Fail("Request can't be found for Teardown!");
            }
            cdc2.Requests.DeleteOnSubmit(req);
            cdc2.SubmitChanges();
        }
Example #8
0
        public void TestViewRequestNotViewer()
        {
            // Create a test request in the DB
            var rc = new RequestContent {
                patientFName = "VRInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture)
            };
            var rmc = new RequestManagementController();
            long rid = rmc.create(rc);

            // Remove the Viewer Role from the User
            _ctm.removeRole(Constants.Roles.VIEWER);

            // Attempt to go to the appropriate View Request Page Directly
            _driver.Navigate().GoToUrl(CommonTestingMethods.getURL());
            _driver.Navigate()
                   .GoToUrl(CommonTestingMethods.getURL() + "/Request/Details/" +
                            rid.ToString(CultureInfo.InvariantCulture));

            // Assert that we're redirected to the not authorized page
            StringAssert.Contains("/Account/Auth", _driver.Url);

            // Cleanup
            Request rq = _cdc.Requests.FirstOrDefault(r => r.RequestID == rid);
            if (rq == null) {
                Assert.Fail("Request is null");
            }

            _cdc.Requests.DeleteOnSubmit(rq);
            _cdc.SubmitChanges();

            _ctm.addRole(Constants.Roles.VIEWER);
        }
        /// <summary>
        ///     Creates a Request entity based off of the RequestContent.
        /// </summary>
        /// <param name="content">Request content holder.</param>
        /// <returns>Request entity based off content.</returns>
        private Request createRequestEntity(RequestContent content)
        {
            var req = new Request();

            if (content.requestID != -1) {
                req = (from r in _db.Requests
                       where r.RequestID == content.requestID
                       select r).Single();
            }

            req.ParentRequestID = content.parentRequestID;

            req.RequestorFName = content.requestorFirstName;
            req.RequestorLName = content.requestorLastName;
            req.RequestorPhone = content.requestorPhoneNum;
            req.RequestorPhoneExt = content.requestorPhoneExt;
            req.RequestorEmail = content.requestorEmail;

            req.PatientFName = content.patientFName;
            req.PatientLName = content.patientLName;
            req.PatientGender = (byte?) content.patientGender;
            req.PatientAgencyID = content.patientAgencyID;
            req.PatientAge = content.patientAge;

            req.RequestStatus = (byte) content.requestStatus;
            req.TimeOpened = content.timeOpened;
            req.TimeClosed = content.timeClosed;

            req.RegionID = content.regionID;
            req.RequestorTypeID = content.requestorTypeID;

            return req;
        }
        public void Test_getRequestDetails()
        {
            // Check request is actually returned
            DateTime opened = DateTime.Now;

            RequestContent rCon = new RequestContent {
                requestStatus = Constants.RequestStatus.Open,
                requestorFirstName = "Bob",
                requestorLastName = "Smith",
                requestorEmail = "*****@*****.**",
                requestorPhoneNum = "123-456-7890",
                requestorPhoneExt = "0000",
                patientFName = "Jane",
                patientLName = "Doe",
                patientGender = Constants.Gender.Female,
                patientAge = 20,
                patientAgencyID = "ABCDE",
                timeOpened = opened,
                regionID = _region.RegionID,
                requestorTypeID = _rType.RequestorTypeID
            };

            QuestionResponseContent qrCon = new QuestionResponseContent {
                question = "Test Question",
                response = "Test Response",
                timeSpent = 10,
                specialNotes = "Test Special Notes",
                questionTypeID = _qType.QuestionTypeID,
                tumourGroupID = _tGroup.TumourGroupID,
                severity = 0,
                consequence = 0
            };

            qrCon.addKeyword("TRMC_Keyword0");

            qrCon.addReference(new ReferenceContent {
                referenceString = "TRMC_Reference1",
                referenceType = Constants.ReferenceType.Text
            });

            rCon.addQuestionResponse(qrCon);

            _reqId = _rmc.create(rCon);

            RequestContent rCon2 = _rmc.getRequestDetails((long) _reqId);

            Assert.NotNull(rCon);
            Assert.AreEqual(rCon.requestStatus, rCon2.requestStatus);
            Assert.AreEqual(rCon.requestorFirstName, rCon2.requestorFirstName);
            Assert.AreEqual(rCon.requestorLastName, rCon2.requestorLastName);
            Assert.AreEqual(rCon.requestorEmail, rCon2.requestorEmail);
            Assert.AreEqual(rCon.requestorPhoneNum, rCon2.requestorPhoneNum);
            Assert.AreEqual(rCon.requestorPhoneExt, rCon2.requestorPhoneExt);
            Assert.AreEqual(rCon.patientFName, rCon2.patientFName);
            Assert.AreEqual(rCon.patientLName, rCon2.patientLName);
            Assert.AreEqual(rCon.patientGender, rCon2.patientGender);
            Assert.AreEqual(rCon.patientAge, rCon2.patientAge);
            Assert.AreEqual(rCon.patientAgencyID, rCon2.patientAgencyID);

            Assert.That(rCon.timeOpened, Is.EqualTo(rCon2.timeOpened).Within(1).Seconds);
            Assert.Null(rCon2.timeClosed);

            Assert.AreEqual(rCon.requestorTypeID, rCon2.requestorTypeID);
            Assert.AreEqual(rCon.regionID, rCon2.regionID);

            Assert.AreEqual(rCon.questionResponseList.Count,
                            rCon2.questionResponseList.Count);

            QuestionResponseContent qrCon2 =
                rCon2.questionResponseList.ElementAt(0);

            Assert.AreEqual(qrCon.question, qrCon2.question);
            Assert.AreEqual(qrCon.response, qrCon2.response);
            Assert.AreEqual(qrCon.timeSpent, qrCon2.timeSpent);
            Assert.AreEqual(qrCon.specialNotes, qrCon2.specialNotes);
            Assert.AreEqual(qrCon.tumourGroupID, qrCon2.tumourGroupID);
            Assert.AreEqual(qrCon.questionTypeID, qrCon2.questionTypeID);
            Assert.AreEqual(qrCon.severity, qrCon2.severity);
            Assert.AreEqual(qrCon.consequence, qrCon2.consequence);

            Assert.AreEqual(qrCon.referenceList.Count,
                            qrCon2.referenceList.Count);
            Assert.AreEqual(qrCon.referenceList.ElementAt(0).referenceType,
                            qrCon2.referenceList.ElementAt(0).referenceType);
            Assert.AreEqual(qrCon.referenceList.ElementAt(0).referenceString,
                            qrCon2.referenceList.ElementAt(0).referenceString);

            Assert.AreEqual(qrCon.keywords.Count, qrCon2.keywords.Count);

            for (int i = 0; i < qrCon.keywords.Count; i++) {
                Assert.True(qrCon.keywords.Contains(qrCon2.keywords.ElementAt(i)));
            }
        }
        public void Test_edit()
        {
            // Create a new request
            var rCon = new RequestContent {
                requestStatus = Constants.RequestStatus.Open,
                requestorFirstName = "Bob",
                requestorLastName = "Smith",
                requestorEmail = "*****@*****.**",
                requestorPhoneNum = "123-456-7890",
                requestorPhoneExt = "0000",
                patientFName = "Jane",
                patientLName = "Doe",
                patientGender = Constants.Gender.Female,
                patientAge = 20,
                patientAgencyID = "ABCDE",
                timeOpened = DateTime.Now,
                regionID = _region.RegionID,
                requestorTypeID = _rType.RequestorTypeID
            };

            var qrCon1 = new QuestionResponseContent {
                question = "Test Question",
                response = "Test Response",
                timeSpent = 10,
                specialNotes = "Test Special Notes",
                questionTypeID = _qType.QuestionTypeID,
                tumourGroupID = _tGroup.TumourGroupID,
                severity = 0,
                consequence = 0
            };

            qrCon1.addKeyword("TRMC_Keyword0");

            qrCon1.addReference(new ReferenceContent {
                referenceString = "TRMC_Reference0",
                referenceType = Constants.ReferenceType.Text
            });

            rCon.addQuestionResponse(qrCon1);

            var qrCon2 = new QuestionResponseContent {
                question = "Test Question",
                response = "Test Response",
                timeSpent = 10,
                specialNotes = "Test Special Notes",
                questionTypeID = _qType.QuestionTypeID,
                tumourGroupID = _tGroup.TumourGroupID,
                severity = 0,
                consequence = 0
            };

            // Test with new and existing keyword
            qrCon2.addKeyword("TRMC_Keyword0");
            qrCon2.addKeyword("TRMC_Keyword2");

            qrCon2.addReference(new ReferenceContent {
                referenceString = "TRMC_Reference1",
                referenceType = Constants.ReferenceType.Text
            });
            qrCon2.addReference(new ReferenceContent {
                referenceString = "TRMC_Reference2",
                referenceType = Constants.ReferenceType.Text
            });

            rCon.addQuestionResponse(qrCon2);

            _reqId = _rmc.create(rCon);

            // Get saved RequestContent details
            rCon = _rmc.getRequestDetails((long) _reqId);

            // Edit request
            rCon.requestStatus = Constants.RequestStatus.Completed;
            rCon.requestorFirstName = "Jane";
            rCon.requestorLastName = "Doe";
            rCon.requestorEmail = "*****@*****.**";
            rCon.requestorPhoneNum = "098-765-4321";
            rCon.requestorPhoneExt = "1111";
            rCon.patientFName = "Bob";
            rCon.patientLName = "Smith";
            rCon.patientGender = Constants.Gender.Male;
            rCon.patientAge = 30;
            rCon.patientAgencyID = "UVWXYZ";
            rCon.timeClosed = DateTime.Now;

            // Remove an existing QuestionResponse
            rCon.questionResponseList.RemoveAt(0);

            // Edit an existing QuestionResponse
            qrCon1 = rCon.questionResponseList.ElementAt(0);

            qrCon1.question = "Question Test";
            qrCon1.response = "Response Test";
            qrCon1.timeSpent = 30;
            qrCon1.specialNotes = "Special Notes Test";
            qrCon1.severity = Constants.Severity.Moderate;
            qrCon1.consequence = Constants.Consequence.Unlikely;

            // Remove an existing keyword from an existing QuestionResponse
            qrCon1.keywords.RemoveAt(0);

            // Add a new keyword to an existing QuestionResponse
            qrCon1.addKeyword("TRMC_Keyword3");

            // Remove an existing reference from an existing QuestionResponse
            qrCon1.referenceList.RemoveAt(0);

            // Edit an existing reference from an existing QuestionResponse
            qrCon1.referenceList.ElementAt(0).referenceString =
                "TRMC_Reference4";

            // Add a new reference to an existing QuestionResponse
            qrCon1.addReference(new ReferenceContent {
                referenceString = "TRMC_Reference5",
                referenceType = Constants.ReferenceType.Text
            });

            // Add a new QuestionResponse
            qrCon2 = new QuestionResponseContent {
                question = "Test Question New",
                response = "Test Response New",
                timeSpent = 10,
                specialNotes = "Test Special Notes New",
                questionTypeID = _qType.QuestionTypeID,
                tumourGroupID = _tGroup.TumourGroupID,
                severity = 0,
                consequence = 0
            };

            qrCon2.addKeyword("TRMC_Keyword0");
            qrCon2.addReference(new ReferenceContent {
                referenceString = "TRMC_Reference3",
                referenceType = Constants.ReferenceType.Text
            });

            rCon.addQuestionResponse(qrCon2);

            _rmc.edit(rCon);

            RequestContent rConEdited = _rmc.getRequestDetails((long) _reqId);

            Assert.AreEqual(rCon.requestStatus, rConEdited.requestStatus);
            Assert.AreEqual(rCon.requestorFirstName,
                            rConEdited.requestorFirstName);
            Assert.AreEqual(rCon.requestorLastName, rConEdited.requestorLastName);
            Assert.AreEqual(rCon.requestorEmail, rConEdited.requestorEmail);
            Assert.AreEqual(rCon.requestorPhoneNum, rConEdited.requestorPhoneNum);
            Assert.AreEqual(rCon.requestorPhoneExt, rConEdited.requestorPhoneExt);
            Assert.AreEqual(rCon.patientFName, rConEdited.patientFName);
            Assert.AreEqual(rCon.patientLName, rConEdited.patientLName);
            Assert.AreEqual(rCon.patientGender, rConEdited.patientGender);
            Assert.AreEqual(rCon.patientAge, rConEdited.patientAge);
            Assert.AreEqual(rCon.patientAgencyID, rConEdited.patientAgencyID);

            Assert.That(rCon.timeOpened,
                        Is.EqualTo(rConEdited.timeOpened).Within(1).Seconds);
            Assert.That(rCon.timeClosed,
                        Is.EqualTo(rConEdited.timeClosed).Within(1).Seconds);

            Assert.AreEqual(rCon.requestorTypeID, rConEdited.requestorTypeID);
            Assert.AreEqual(rCon.regionID, rConEdited.regionID);

            Assert.AreEqual(rCon.questionResponseList.Count,
                            rConEdited.questionResponseList.Count);

            for (int i = 0; i < rCon.questionResponseList.Count; i++) {
                QuestionResponseContent qrConOrig =
                    rCon.questionResponseList.ElementAt(i);
                QuestionResponseContent qrConEdited =
                    rConEdited.questionResponseList.ElementAt(i);

                Assert.AreEqual(qrConOrig.question, qrConEdited.question);
                Assert.AreEqual(qrConOrig.response, qrConEdited.response);
                Assert.AreEqual(qrConOrig.timeSpent, qrConEdited.timeSpent);
                Assert.AreEqual(qrConOrig.specialNotes, qrConEdited.specialNotes);
                Assert.AreEqual(qrConOrig.tumourGroupID,
                                qrConEdited.tumourGroupID);
                Assert.AreEqual(qrConOrig.questionTypeID,
                                qrConEdited.questionTypeID);
                Assert.AreEqual(qrConOrig.severity, qrConEdited.severity);
                Assert.AreEqual(qrConOrig.consequence, qrConEdited.consequence);

                Assert.AreEqual(qrConOrig.referenceList.Count,
                                qrConEdited.referenceList.Count);

                for (int j = 0; j < qrConOrig.referenceList.Count; j++) {
                    Assert.AreEqual(
                        qrConOrig.referenceList.ElementAt(j).referenceType,
                        qrConEdited.referenceList.ElementAt(j)
                                   .referenceType);
                    Assert.AreEqual(
                        qrConOrig.referenceList.ElementAt(j).referenceString,
                        qrConEdited.referenceList.ElementAt(j)
                                   .referenceString);
                }

                Assert.AreEqual(qrConOrig.keywords.Count,
                                qrConEdited.keywords.Count);

                for (int k = 0; k < qrConOrig.keywords.Count; k++) {
                    Assert.True(
                        qrConOrig.keywords.Contains(
                            qrConEdited.keywords.ElementAt(k)));
                }
            }
        }
        public void Test_create()
        {
            DateTime opened = DateTime.Now;

            var rCon = new RequestContent {
                requestStatus = Constants.RequestStatus.Open,
                requestorFirstName = "Bob",
                requestorLastName = "Smith",
                requestorEmail = "*****@*****.**",
                requestorPhoneNum = "123-456-7890",
                requestorPhoneExt = "0000",
                patientFName = "Jane",
                patientLName = "Doe",
                patientGender = Constants.Gender.Female,
                patientAge = 20,
                patientAgencyID = "ABCDE",
                timeOpened = opened,
                regionID = _region.RegionID,
                requestorTypeID = _rType.RequestorTypeID
            };

            var qrCon = new QuestionResponseContent {
                question = "Test Question",
                response = "Test Response",
                timeSpent = 10,
                specialNotes = "Test Special Notes",
                questionTypeID = _qType.QuestionTypeID,
                tumourGroupID = _tGroup.TumourGroupID,
                severity = 0,
                consequence = 0
            };

            // Test with new and existing keyword
            qrCon.addKeyword("TRMC_Keyword0");
            qrCon.addKeyword("TRMC_Keyword1");

            _db.ExecuteCommand(
                "INSERT INTO Keyword (KeywordValue, Active) " +
                "VALUES ('TRMC_Keyword0', 'False')");

            qrCon.addReference(new ReferenceContent {
                referenceString = "TRMC_Reference1",
                referenceType = Constants.ReferenceType.Text
            });

            rCon.addQuestionResponse(qrCon);

            _reqId = _rmc.create(rCon);

            Request req = (from r in _db.Requests
                           where r.RequestID == _reqId
                           select r)
                .Single();

            Assert.AreEqual(req.RequestStatus, (byte) rCon.requestStatus);
            Assert.AreEqual(req.RequestorFName, rCon.requestorFirstName);
            Assert.AreEqual(req.RequestorLName, rCon.requestorLastName);
            Assert.AreEqual(req.RequestorEmail, rCon.requestorEmail);
            Assert.AreEqual(req.RequestorPhone, rCon.requestorPhoneNum);
            Assert.AreEqual(req.RequestorPhoneExt, rCon.requestorPhoneExt);
            Assert.AreEqual(req.PatientFName, rCon.patientFName);
            Assert.AreEqual(req.PatientLName, rCon.patientLName);
            Assert.AreEqual(req.PatientGender, (byte) rCon.patientGender);
            Assert.AreEqual(req.PatientAge, rCon.patientAge);
            Assert.AreEqual(req.PatientAgencyID, rCon.patientAgencyID);

            Assert.That(rCon.timeOpened,
                        Is.EqualTo(req.TimeOpened).Within(1).Seconds);
            Assert.Null(req.TimeClosed);

            Assert.AreEqual(req.RequestorTypeID, rCon.requestorTypeID);
            Assert.AreEqual(req.RegionID, rCon.regionID);

            QuestionResponse qr = (from q in _db.QuestionResponses
                                   where q.RequestID == _reqId
                                   select q)
                .Single();

            Assert.AreEqual(qr.Question, qrCon.question);
            Assert.AreEqual(qr.Response, qrCon.response);
            Assert.AreEqual(qr.TimeSpent, qrCon.timeSpent);
            Assert.AreEqual(qr.SpecialNotes, qrCon.specialNotes);
            Assert.AreEqual(qr.TumourGroupID, qrCon.tumourGroupID);
            Assert.AreEqual(qr.QuestionTypeID, qrCon.questionTypeID);
            Assert.AreEqual(qr.Severity, (byte) qrCon.severity);
            Assert.AreEqual(qr.Consequence, (byte) qrCon.consequence);

            Reference[] rArr =
                (from r in _db.References
                 where r.RequestID == _reqId &&
                       r.QuestionResponseID == qr.QuestionResponseID
                 select r)
                    .ToArray();

            Assert.AreEqual(rArr.Length, qrCon.referenceList.Count);
            Assert.AreEqual(rArr[0].ReferenceType,
                            (byte)
                            qrCon.referenceList.ElementAt(0).referenceType);
            Assert.AreEqual(rArr[0].ReferenceString,
                            qrCon.referenceList.ElementAt(0).referenceString);

            KeywordQuestion[] kqArr =
                (from kq in _db.KeywordQuestions
                 where kq.RequestID == _reqId &&
                       kq.QuestionResponseID == qr.QuestionResponseID
                 select kq)
                    .ToArray();

            Assert.AreEqual(kqArr.Length, qrCon.keywords.Count);

            foreach (KeywordQuestion t in kqArr) {
                Keyword keyword =
                    (from kw in _db.Keywords
                     where kw.KeywordID == t.KeywordID
                     select kw)
                        .Single();

                Assert.True(qrCon.keywords.Contains(keyword.KeywordValue));
            }
        }
Example #13
0
        public void TestViewRequestLockedToAnother()
        {
            // Create a test request in the DB
            var rc = new RequestContent {
                patientFName = "VRInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture)
            };
            var rmc = new RequestManagementController();
            long rid = rmc.create(rc);

            // Create the User
            var up = new UserProfile {
                UserName = "******" +
                           _random.Next()
                                  .ToString(CultureInfo.InvariantCulture)
            };
            _cdc.UserProfiles.InsertOnSubmit(up);
            _cdc.SubmitChanges();

            // Create the Lock
            var rlmc = new RequestLockManagementController();
            rlmc.addLock(rid, up.UserId);

            // Remove the Viewer Role from the User
            _ctm.removeRole(Constants.Roles.ADMINISTRATOR);

            // Attempt to go to the appropriate View Request Page Directly
            _driver.Navigate().GoToUrl(CommonTestingMethods.getURL());
            _driver.Navigate()
                   .GoToUrl(CommonTestingMethods.getURL() + "/Request/Details/" +
                            rid.ToString(CultureInfo.InvariantCulture));
            _driver.FindElement(By.Id("error-header"));
            IWebElement msg = _driver.FindElement(By.Id("error-message"));
            StringAssert.AreEqualIgnoringCase(
                "This request has been locked to another person and cannot be viewed until unlocked.",
                msg.Text);

            // Assert that we're redirected to the not authorized page
            StringAssert.Contains("/Request/Details", _driver.Url);

            // Cleanup
            rlmc.removeLock(rid);
            _cdc.UserProfiles.DeleteOnSubmit(up);
            Request rq = _cdc.Requests.FirstOrDefault(r => r.RequestID == rid);
            if (rq == null) {
                Assert.Fail("Request is null");
            }
            _cdc.Requests.DeleteOnSubmit(rq);
            _cdc.SubmitChanges();

            _ctm.addRole(Constants.Roles.ADMINISTRATOR);
        }
Example #14
0
        public void TestViewRequestWorking()
        {
            // Add some Dependencies
            var rt = new RequestorType {
                Code = _random.Next(1000000)
                              .ToString(CultureInfo.InvariantCulture),
                Value = "VRInt-" +
                        _random.Next()
                               .ToString(CultureInfo.InvariantCulture),
                Active = true
            };
            _cdc.RequestorTypes.InsertOnSubmit(rt);

            var qt = new QuestionType {
                Code = _random.Next(1000000)
                              .ToString(CultureInfo.InvariantCulture),
                Value = "VRInt-" +
                        _random.Next()
                               .ToString(CultureInfo.InvariantCulture),
                Active = true
            };
            _cdc.QuestionTypes.InsertOnSubmit(qt);

            var tg = new TumourGroup {
                Code = _random.Next(1000000)
                              .ToString(CultureInfo.InvariantCulture),
                Value = "VRInt-" +
                        _random.Next()
                               .ToString(CultureInfo.InvariantCulture),
                Active = true
            };
            _cdc.TumourGroups.InsertOnSubmit(tg);

            var r = new Region {
                Code = _random.Next(1000000)
                              .ToString(CultureInfo.InvariantCulture),
                Value = "VRInt-" +
                        _random.Next()
                               .ToString(CultureInfo.InvariantCulture),
                Active = true
            };
            _cdc.Regions.InsertOnSubmit(r);

            var k = new Keyword {
                KeywordValue = "VRInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
                Active = true
            };
            _cdc.Keywords.InsertOnSubmit(k);

            // Submit our changes so far.
            _cdc.SubmitChanges();

            // Create a test request in the DB
            var rc = new RequestContent {
                patientFName = "VRInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
                patientLName = "VRInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
                patientAgencyID = _random.Next()
                                         .ToString(CultureInfo.InvariantCulture),
                patientGender = Constants.Gender.Female,
                patientAge = 255,
                requestorTypeID = rt.RequestorTypeID,
                regionID = r.RegionID,
                requestorFirstName = "VRInt-" +
                                     _random.Next()
                                            .ToString(
                                                CultureInfo.InvariantCulture),
                requestorLastName = "VRInt-" +
                                    _random.Next()
                                           .ToString(
                                               CultureInfo.InvariantCulture),
                requestorEmail = _random.Next()
                                        .ToString(CultureInfo.InvariantCulture) +
                                 "@example.com",
                requestorPhoneNum = _random.Next()
                                           .ToString(
                                               CultureInfo.InvariantCulture),
                requestorPhoneExt = _random.Next()
                                           .ToString(
                                               CultureInfo.InvariantCulture)
            };

            var refCont = new ReferenceContent {
                referenceType = Constants.ReferenceType.Text,
                referenceString = "VRInt-" +
                                  _random.Next()
                                         .ToString(
                                             CultureInfo.InvariantCulture)
            };

            var qrc = new QuestionResponseContent {
                question = "VRInt-" +
                           _random.Next()
                                  .ToString(
                                      CultureInfo.InvariantCulture),
                response = "VRInt-" +
                           _random.Next()
                                  .ToString(
                                      CultureInfo.InvariantCulture),
                specialNotes = "VRInt-" +
                               _random.Next()
                                      .ToString(
                                          CultureInfo.InvariantCulture),
                consequence = Constants.Consequence.Certain,
                severity = Constants.Severity.Major,
                keywords = new List<string> {k.KeywordValue},
                referenceList = new List<ReferenceContent> {refCont},
                timeSpent = 255,
                questionTypeID = qt.QuestionTypeID,
                tumourGroupID = tg.TumourGroupID
            };
            rc.addQuestionResponse(qrc);
            var rmc = new RequestManagementController();
            long rid = rmc.create(rc);

            var dmc = new DropdownManagementController();

            // Attempt to go to the appropriate View Request Page Directly
            _driver.Navigate().GoToUrl(CommonTestingMethods.getURL());
            _driver.Navigate()
                   .GoToUrl(CommonTestingMethods.getURL() + "/Request/Details/" +
                            rid.ToString(CultureInfo.InvariantCulture));

            // Assert that we're not redirected
            StringAssert.Contains("/Request/Details", _driver.Url);

            // Go through fields and check values
            IWebElement element = _driver.FindElement(By.Id("status"));
            StringAssert.AreEqualIgnoringCase(rc.requestStatus.ToString(),
                                              element.Text);

            element = _driver.FindElement(By.Id("total-time-spent"));
            StringAssert.Contains(qrc.timeSpent.ToString(), element.Text);

            element = _driver.FindElement(By.Id("requestor-name"));
            StringAssert.Contains(rc.requestorFirstName, element.Text);
            StringAssert.Contains(rc.requestorLastName, element.Text);

            element = _driver.FindElement(By.Id("requestor-email"));
            StringAssert.AreEqualIgnoringCase(rc.requestorEmail, element.Text);

            element = _driver.FindElement(By.Id("requestor-phone"));
            StringAssert.Contains(rc.requestorPhoneNum, element.Text);
            StringAssert.Contains(rc.requestorPhoneExt, element.Text);

            element = _driver.FindElement(By.Id("caller-type"));
            StringAssert.Contains(rt.Code, element.Text);
            StringAssert.Contains(rt.Value, element.Text);

            element = _driver.FindElement(By.Id("region"));
            StringAssert.Contains(r.Code, element.Text);
            StringAssert.Contains(r.Value, element.Text);

            element = _driver.FindElement(By.Id("patient-name"));
            StringAssert.Contains(rc.patientFName, element.Text);
            StringAssert.Contains(rc.patientLName, element.Text);

            element = _driver.FindElement(By.Id("patient-gender"));
            StringAssert.AreEqualIgnoringCase(rc.patientGender.ToString(),
                                              element.Text);

            element = _driver.FindElement(By.Id("patient-id"));
            StringAssert.AreEqualIgnoringCase(rc.patientAgencyID, element.Text);

            element = _driver.FindElement(By.Id("patient-age"));
            StringAssert.AreEqualIgnoringCase(rc.patientAge.ToString(),
                                              element.Text);

            element = _driver.FindElement(By.ClassName("question"));
            StringAssert.AreEqualIgnoringCase(qrc.question, element.Text);

            element = _driver.FindElement(By.ClassName("response"));
            StringAssert.AreEqualIgnoringCase(qrc.response, element.Text);

            element = _driver.FindElement(By.ClassName("special-notes"));
            StringAssert.AreEqualIgnoringCase(qrc.specialNotes, element.Text);

            element = _driver.FindElement(By.ClassName("question-type"));
            StringAssert.Contains(qt.Code, element.Text);
            StringAssert.Contains(qt.Value, element.Text);

            element = _driver.FindElement(By.ClassName("tumour-group"));
            StringAssert.Contains(tg.Code, element.Text);
            StringAssert.Contains(tg.Value, element.Text);

            element = _driver.FindElement(By.ClassName("time-spent"));
            StringAssert.Contains(qrc.timeSpent.ToString(), element.Text);

            element = _driver.FindElement(By.ClassName("score"));
            StringAssert.AreEqualIgnoringCase(
                1.ToString(CultureInfo.InvariantCulture), element.Text);

            element = _driver.FindElement(By.ClassName("impact-sev"));
            StringAssert.AreEqualIgnoringCase(qrc.severity.ToString(),
                                              element.Text);

            element = _driver.FindElement(By.ClassName("impact-cons"));
            StringAssert.AreEqualIgnoringCase(qrc.consequence.ToString(),
                                              element.Text);

            element = _driver.FindElement(By.ClassName("reference-string"));
            StringAssert.AreEqualIgnoringCase(refCont.referenceString,
                                              element.Text);

            // Cleanup
            var cdc2 = new CAIRSDataContext();

            IQueryable<KeywordQuestion> kqs =
                cdc2.KeywordQuestions.Where(kq => kq.RequestID == rid);
            Assert.IsTrue(kqs.Any());
            cdc2.KeywordQuestions.DeleteAllOnSubmit(kqs);

            IQueryable<AuditLog> als =
                cdc2.AuditLogs.Where(al => al.RequestID == rid);
            Assert.IsTrue(als.Any());
            cdc2.AuditLogs.DeleteAllOnSubmit(als);

            IQueryable<QuestionResponse> qrs =
                cdc2.QuestionResponses.Where(dbQr => dbQr.RequestID == rid);
            Assert.IsTrue(qrs.Any());
            cdc2.QuestionResponses.DeleteAllOnSubmit(qrs);

            IQueryable<Request> rs =
                cdc2.Requests.Where(rq => rq.RequestID == rid);
            Assert.IsTrue(rs.Any());
            cdc2.Requests.DeleteAllOnSubmit(rs);

            IQueryable<Reference> refs =
                cdc2.References.Where(rf => rf.RequestID == rid);
            Assert.IsTrue(refs.Any());
            cdc2.References.DeleteAllOnSubmit(refs);

            IQueryable<RequestorType> rqts =
                cdc2.RequestorTypes.Where(
                    rqt => rqt.RequestorTypeID == rt.RequestorTypeID);
            Assert.IsTrue(rqts.Any());
            cdc2.RequestorTypes.DeleteAllOnSubmit(rqts);

            IQueryable<QuestionType> qts =
                cdc2.QuestionTypes.Where(
                    dbQt => dbQt.Value == qt.Value);
            Assert.IsTrue(qts.Any());
            cdc2.QuestionTypes.DeleteAllOnSubmit(qts);

            IQueryable<TumourGroup> tgs =
                cdc2.TumourGroups.Where(
                    dbTg => dbTg.TumourGroupID == tg.TumourGroupID);
            Assert.IsTrue(tgs.Any());
            cdc2.TumourGroups.DeleteAllOnSubmit(tgs);

            IQueryable<Region> regions =
                cdc2.Regions.Where(dbRg => dbRg.RegionID == r.RegionID);
            Assert.IsTrue(regions.Any());
            cdc2.Regions.DeleteAllOnSubmit(regions);

            IQueryable<Keyword> keywords =
                cdc2.Keywords.Where(kw => kw.KeywordID == k.KeywordID);
            Assert.IsTrue(keywords.Any());
            cdc2.Keywords.DeleteAllOnSubmit(keywords);

            IQueryable<Request> rqs =
                cdc2.Requests.Where(dbRq => dbRq.RequestID == rid);
            Assert.IsTrue(rqs.Any());
            cdc2.Requests.DeleteAllOnSubmit(rqs);

            cdc2.SubmitChanges();
        }
        /// <summary>
        ///     Creates a new Request in the database, with corresponding
        ///     QuestionResponses and References
        /// </summary>
        /// <param name="reqContent">
        ///     RequestContent containing
        ///     QuestionResponseContents, ReferenceContents and Keywords
        /// </param>
        public long create(RequestContent reqContent)
        {
            using (var trans = new TransactionScope()) {
                // Insert new Request entity
                Request req = createRequestEntity(reqContent);
                _db.Requests.InsertOnSubmit(req);
                _db.SubmitChanges();

                // For each QuestionResponse associated with the request
                foreach (QuestionResponseContent qrContent
                    in reqContent.questionResponseList) {
                    // Set the new RequestID
                    qrContent.requestID = req.RequestID;

                    // Insert new QuestionResponse entity
                    QuestionResponse qr =
                        createQuestionResponseEntity(qrContent);
                    _db.QuestionResponses.InsertOnSubmit(qr);
                    _db.SubmitChanges();

                    // For each Keyword associated with the
                    // QuestionResponse
                    foreach (String kw in qrContent.keywords) {
                        int kwId = getKeywordIdAndActivate(kw);

                        // Check if already associated with Question
                        var kq =
                            (from kqs in _db.KeywordQuestions
                             where kqs.KeywordID == kwId &&
                                   kqs.RequestID ==
                                   req.RequestID &&
                                   kqs.QuestionResponseID ==
                                   qr.QuestionResponseID
                             select kqs)
                                .SingleOrDefault();

                        if (kq != null) {
                            continue;
                        }

                        kq = new KeywordQuestion {
                            KeywordID = kwId,
                            RequestID = req.RequestID,
                            QuestionResponseID = qr.QuestionResponseID
                        };

                        _db.KeywordQuestions.InsertOnSubmit(kq);
                        _db.SubmitChanges();
                    }

                    // For each Reference associated with the
                    // QuestionResponse
                    foreach (ReferenceContent refContent
                        in qrContent.referenceList) {
                        // Set the new RequestID and
                        // QuestionResponseID
                        refContent.requestID = req.RequestID;
                        refContent.questionResponseID =
                            qr.QuestionResponseID;

                        // Insert new Reference entity
                        _db.References.InsertOnSubmit(
                            createReferenceEntity(refContent));
                        _db.SubmitChanges();
                    }
                }

                trans.Complete();

                return req.RequestID;
            }
        }
        /// <summary>
        ///     Retrieves all of the request information and content from the
        ///     database for a given request ID.
        /// </summary>
        /// <param name="requestId">ID of the specified request.</param>
        /// <returns>
        ///     RequestContent contaning QuestionResponseContents,
        ///     ReferenceContents and Keywords.
        /// </returns>
        public RequestContent getRequestDetails(long requestId)
        {
            IQueryable<Request> requests = (from reqs in _db.Requests
                                            where reqs.RequestID == requestId
                                            select reqs);

            if (requests.Any()) {
                Request reqResult = requests.First();

                List<QuestionResponse> qrResults =
                    (from qrs in _db.QuestionResponses
                     where qrs.RequestID == requestId
                     orderby qrs.QuestionResponseID
                     select qrs)
                        .ToList();

                List<Reference> refResults =
                    (from refs in _db.References
                     where refs.RequestID == requestId
                     orderby refs.QuestionResponseID
                     select refs)
                        .ToList();

                // Create RequestContent holder
                var reqContent = new RequestContent(reqResult);

                int refCounter = 0;

                // For each QuestionResponse in the database
                foreach (QuestionResponse qr in qrResults) {
                    // Create QuestionResponseContent holder
                    var qrContent =
                        new QuestionResponseContent(qr);
                    reqContent.addQuestionResponse(qrContent);

                    List<Keyword> kwResults =
                        (from kws in _db.Keywords
                         join kqs in _db.KeywordQuestions
                             on kws.KeywordID equals kqs.KeywordID
                         where kqs.RequestID == requestId &&
                               kqs.QuestionResponseID == qr.QuestionResponseID
                         select kws)
                            .ToList();

                    // For each Keyword for the current QuestionResponse
                    foreach (Keyword kw in kwResults) {
                        qrContent.addKeyword(kw.KeywordValue);
                    }

                    // For each Reference for the current QuestionResponse
                    while (refCounter < refResults.Count &&
                           qr.QuestionResponseID ==
                           refResults[refCounter].QuestionResponseID) {
                        // Create ReferenceContent holder
                        var refContent =
                            new ReferenceContent(refResults[refCounter++]);
                        qrContent.addReference(refContent);
                    }
                }

                return reqContent;
            } else {
                return null;
            }
        }
Example #17
0
        public void TestAdvancedSearchAny()
        {
            var kw1 = new Keyword {
                KeywordValue = "SInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture)
            };
            var kw2 = new Keyword {
                KeywordValue = "SInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture)
            };
            _cdc.Keywords.InsertAllOnSubmit(new List<Keyword> {kw1, kw2});
            _cdc.SubmitChanges();

            // Setup the request
            var qrc1 = new QuestionResponseContent {
                keywords = new List<string> {kw1.KeywordValue}
            };
            var rc1 = new RequestContent {
                patientFName = "SInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
                requestStatus = Constants.RequestStatus.Open
            };
            rc1.addQuestionResponse(qrc1);

            TumourGroup tg = _cdc.TumourGroups.FirstOrDefault(t => t.Active);
            if (tg == null) {
                Assert.Fail("No active TumourGroups in the system!");
            }
            var qrc2 = new QuestionResponseContent {
                keywords = new List<string> {kw2.KeywordValue},
                tumourGroupID = tg.TumourGroupID
            };
            var rc2 = new RequestContent {
                patientFName = "SInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
                requestStatus = Constants.RequestStatus.Completed
            };
            rc2.addQuestionResponse(qrc2);

            QuestionType qt = _cdc.QuestionTypes.FirstOrDefault(q => q.Active);
            if (qt == null) {
                Assert.Fail("No active QuestionTypes in the system!");
            }
            var qrc3 = new QuestionResponseContent {
                keywords = new List<string> {kw2.KeywordValue},
                questionTypeID = qt.QuestionTypeID
            };
            var rc3 = new RequestContent {
                patientFName = "SInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
                requestStatus = Constants.RequestStatus.Invalid
            };
            rc3.addQuestionResponse(qrc3);

            // Create the RequestContents
            var rmc = new RequestManagementController();
            long rid1 = rmc.create(rc1);
            long rid2 = rmc.create(rc2);
            long rid3 = rmc.create(rc3);

            //========================================
            // Vroom! Vroom!
            //========================================
            _driver.Navigate().GoToUrl(CommonTestingMethods.getURL());
            _ctm.findAndClick(Constants.UIString.ItemIDs.ADVANCED_SEARCH,
                              "/Search/Advanced");

            _driver.FindElement(By.Id("keywordString"))
                   .SendKeys(kw1.KeywordValue + ", " + kw2.KeywordValue + ", ");
            _ctm.findAndClick(Constants.UIString.ItemIDs.SUBMIT_BUTTON,
                              "/Search/Results");

            // Check Results
            ReadOnlyCollection<IWebElement> row1 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid1 + "']"));
            ReadOnlyCollection<IWebElement> row2 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid2 + "']"));
            ReadOnlyCollection<IWebElement> row3 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid3 + "']"));

            Assert.IsTrue(row1.Count > 0, "Request 1 not in results!");
            Assert.IsTrue(row2.Count > 0, "Request 2 not in results!");
            Assert.IsTrue(row3.Count > 0, "Request 3 not in results!");

            // Modify the Search
            _ctm.findAndClick(Constants.UIString.ItemIDs.MODIFY_SEARCH,
                              "/Search/Modify");
            _driver.FindElement(By.Id(Constants.RequestStatus.Open.ToString()))
                   .FindElement(By.ClassName("icon")).Click();
            _ctm.findAndClick(Constants.UIString.ItemIDs.SUBMIT_BUTTON,
                              "/Search/Results");

            // Check Results
            row1 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid1 + "']"));
            row2 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid2 + "']"));
            row3 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid3 + "']"));

            Assert.IsTrue(row1.Count > 0, "Request 1 not in results!");
            Assert.IsTrue(row2.Count == 0, "Request 2 in results!");
            Assert.IsTrue(row3.Count == 0, "Request 3 in results!");

            // Modify the Search
            _ctm.findAndClick(Constants.UIString.ItemIDs.MODIFY_SEARCH,
                              "/Search/Modify");

            // Change the Status from Open to Completed
            _driver.FindElement(By.Id(Constants.RequestStatus.Open.ToString()))
                   .FindElement(By.ClassName("icon")).Click();
            _driver.FindElement(
                By.Id(Constants.RequestStatus.Completed.ToString()))
                   .FindElement(By.ClassName("icon")).Click();

            // Add a Tumour Group Search
            _driver.FindElement(By.Id("tumour-group"))
                   .FindElement(
                       By.Id(
                           tg.TumourGroupID.ToString(
                               CultureInfo.InvariantCulture)))
                   .FindElement(By.ClassName("icon"))
                   .Click();

            _ctm.findAndClick(Constants.UIString.ItemIDs.SUBMIT_BUTTON,
                              "/Search/Results");

            // Check Results
            row1 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid1 + "']"));
            row2 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid2 + "']"));
            row3 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid3 + "']"));

            Assert.IsTrue(row1.Count == 0, "Request 1 in results!");
            Assert.IsTrue(row2.Count > 0, "Request 2 not in results!");
            Assert.IsTrue(row3.Count == 0, "Request 3 in results!");

            // Modify the Search
            _ctm.findAndClick(Constants.UIString.ItemIDs.MODIFY_SEARCH,
                              "/Search/Modify");

            // Change the Status from Completed to Invalid
            _driver.FindElement(
                By.Id(Constants.RequestStatus.Completed.ToString()))
                   .FindElement(By.ClassName("icon")).Click();
            _driver.FindElement(By.Id(Constants.RequestStatus.Invalid.ToString()))
                   .FindElement(By.ClassName("icon")).Click();

            // Remove the Tumour Group Search
            _driver.FindElement(By.Id("tumour-group"))
                   .FindElement(
                       By.Id(
                           tg.TumourGroupID.ToString(
                               CultureInfo.InvariantCulture)))
                   .FindElement(By.ClassName("icon"))
                   .Click();

            // Add a Question Type Search
            _driver.FindElement(By.Id("question-type"))
                   .FindElement(
                       By.Id(
                           qt.QuestionTypeID.ToString(
                               CultureInfo.InvariantCulture)))
                   .FindElement(By.ClassName("icon"))
                   .Click();

            _ctm.findAndClick(Constants.UIString.ItemIDs.SUBMIT_BUTTON,
                              "/Search/Results");

            // Check Results
            row1 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid1 + "']"));
            row2 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid2 + "']"));
            row3 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid3 + "']"));

            Assert.IsTrue(row1.Count == 0, "Request 1 in results!");
            Assert.IsTrue(row2.Count == 0, "Request 2 in results!");
            Assert.IsTrue(row3.Count > 0, "Request 3 not in results!");

            //========================================
            // Mr. Clean to the rescue!
            //========================================
            // Cleanup KeywordQuestion
            var cdc2 = new CAIRSDataContext();
            IQueryable<KeywordQuestion> keyq1 =
                cdc2.KeywordQuestions.Where(kq => kq.RequestID == rid1);
            IQueryable<KeywordQuestion> keyq2 =
                cdc2.KeywordQuestions.Where(kq => kq.RequestID == rid2);
            IQueryable<KeywordQuestion> keyq3 =
                cdc2.KeywordQuestions.Where(kq => kq.RequestID == rid3);
            if (keyq1 == null || keyq2 == null || keyq3 == null) {
                Assert.Fail("KeywordQuestion can't be found for Teardown!");
            }
            cdc2.KeywordQuestions.DeleteAllOnSubmit(keyq1);
            cdc2.KeywordQuestions.DeleteAllOnSubmit(keyq2);
            cdc2.KeywordQuestions.DeleteAllOnSubmit(keyq3);
            cdc2.SubmitChanges();

            // Cleanup Keyword
            Keyword kwDel1 =
                cdc2.Keywords.FirstOrDefault(k => k.KeywordID == kw1.KeywordID);
            Keyword kwDel2 =
                cdc2.Keywords.FirstOrDefault(k => k.KeywordID == kw2.KeywordID);
            if (kwDel1 == null || kwDel2 == null) {
                Assert.Fail("KeywordQuestion can't be found for Teardown!");
            }
            cdc2.Keywords.DeleteAllOnSubmit(new List<Keyword> {kwDel1, kwDel2});
            cdc2.SubmitChanges();

            // Cleanup QuestionResponse
            QuestionResponse qresp1 =
                cdc2.QuestionResponses.FirstOrDefault(qr => qr.RequestID == rid1);
            QuestionResponse qresp2 =
                cdc2.QuestionResponses.FirstOrDefault(qr => qr.RequestID == rid2);
            QuestionResponse qresp3 =
                cdc2.QuestionResponses.FirstOrDefault(qr => qr.RequestID == rid3);
            if (qresp1 == null || qresp2 == null || qresp3 == null) {
                Assert.Fail("QuestionResponse can't be found for Teardown!");
            }
            cdc2.QuestionResponses.DeleteAllOnSubmit(
                new List<QuestionResponse> {qresp1, qresp2, qresp3});
            cdc2.SubmitChanges();

            // Cleanup Request
            Request req1 = cdc2.Requests.FirstOrDefault(r => r.RequestID == rid1);
            Request req2 = cdc2.Requests.FirstOrDefault(r => r.RequestID == rid2);
            Request req3 = cdc2.Requests.FirstOrDefault(r => r.RequestID == rid3);
            if (req1 == null || req2 == null || req3 == null) {
                Assert.Fail("Request can't be found for Teardown!");
            }
            cdc2.Requests.DeleteAllOnSubmit(new List<Request> {req1, req2, req3});
            cdc2.SubmitChanges();
        }
Example #18
0
        public void TestAdvancedSearchNone()
        {
            var kw1 = new Keyword {
                KeywordValue = "SInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture)
            };
            var kw2 = new Keyword {
                KeywordValue = "SInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture)
            };
            _cdc.Keywords.InsertAllOnSubmit(new List<Keyword> {kw1, kw2});
            _cdc.SubmitChanges();

            // Setup the request
            var qrc1 = new QuestionResponseContent {
                keywords = new List<string> {kw1.KeywordValue}
            };
            var rc1 = new RequestContent {
                patientFName = "SInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
                requestStatus = Constants.RequestStatus.Open
            };
            rc1.addQuestionResponse(qrc1);

            var qrc2 = new QuestionResponseContent {
                keywords = new List<string> {kw2.KeywordValue}
            };
            var rc2 = new RequestContent {
                patientFName = "SInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture)
            };
            rc2.addQuestionResponse(qrc2);

            // Create the RequestContents
            var rmc = new RequestManagementController();
            long rid1 = rmc.create(rc1);
            long rid2 = rmc.create(rc2);

            //========================================================
            // The 2:08 train for Bug-Free Ville is now Departing
            //========================================================
            _driver.Navigate().GoToUrl(CommonTestingMethods.getURL());
            _ctm.findAndClick(Constants.UIString.ItemIDs.ADVANCED_SEARCH,
                              "/Search/Advanced");

            _driver.FindElement(By.Id("noneKeywords"))
                   .SendKeys(kw1.KeywordValue + ", ");
            _ctm.findAndClick(Constants.UIString.ItemIDs.SUBMIT_BUTTON,
                              "/Search/Results");

            // Check Results
            ReadOnlyCollection<IWebElement> row1 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid1 + "']"));
            ReadOnlyCollection<IWebElement> row2 =
                _driver.FindElements(By.CssSelector("[data-id='" + rid2 + "']"));

            Assert.IsTrue(row1.Count == 0, "Request 1 in results!");
            Assert.IsTrue(row2.Count > 0, "Request 2 not in results!");

            //=====================================================
            // Oh no! The train crashed! :( Away goes the data!
            //=====================================================
            // Cleanup KeywordQuestion
            var cdc2 = new CAIRSDataContext();
            IQueryable<KeywordQuestion> keyq1 =
                cdc2.KeywordQuestions.Where(
                    kq => kq.KeywordID == kw1.KeywordID);
            IQueryable<KeywordQuestion> keyq2 =
                cdc2.KeywordQuestions.Where(
                    kq => kq.KeywordID == kw2.KeywordID);
            if (keyq1 == null || keyq2 == null) {
                Assert.Fail("KeywordQuestion can't be found for Teardown!");
            }
            cdc2.KeywordQuestions.DeleteAllOnSubmit(keyq1);
            cdc2.KeywordQuestions.DeleteAllOnSubmit(keyq2);
            cdc2.SubmitChanges();

            // Cleanup Keyword
            Keyword kwDel1 =
                cdc2.Keywords.FirstOrDefault(k => k.KeywordID == kw1.KeywordID);
            Keyword kwDel2 =
                cdc2.Keywords.FirstOrDefault(k => k.KeywordID == kw2.KeywordID);
            if (kwDel1 == null || kwDel2 == null) {
                Assert.Fail("KeywordQuestion can't be found for Teardown!");
            }
            cdc2.Keywords.DeleteAllOnSubmit(new List<Keyword> {kwDel1, kwDel2});
            cdc2.SubmitChanges();

            // Cleanup QuestionResponse
            QuestionResponse qresp1 =
                cdc2.QuestionResponses.FirstOrDefault(qr => qr.RequestID == rid1);
            QuestionResponse qresp2 =
                cdc2.QuestionResponses.FirstOrDefault(qr => qr.RequestID == rid2);
            if (qresp1 == null || qresp2 == null) {
                Assert.Fail("QuestionResponse can't be found for Teardown!");
            }
            cdc2.QuestionResponses.DeleteAllOnSubmit(
                new List<QuestionResponse> {qresp1, qresp2});
            cdc2.SubmitChanges();

            // Cleanup Request
            Request req1 = cdc2.Requests.FirstOrDefault(r => r.RequestID == rid1);
            Request req2 = cdc2.Requests.FirstOrDefault(r => r.RequestID == rid2);
            if (req1 == null || req2 == null) {
                Assert.Fail("Request can't be found for Teardown!");
            }
            cdc2.Requests.DeleteAllOnSubmit(new List<Request> {req1, req2});
            cdc2.SubmitChanges();
        }
Example #19
0
        public void TestCreateRequestValid()
        {
            // Create a test request in the DB
            var rc1 = new RequestContent {
                patientFName = "DInt-" +
                               _random.Next()
                                      .ToString(CultureInfo.InvariantCulture),
                requestStatus = Constants.RequestStatus.Open,
                timeOpened = DateTime.Now
            };
            var rmc = new RequestManagementController();
            long rid1 = rmc.create(rc1);

            // Attempt to go to the Create Request Page
            _driver.Navigate().GoToUrl(CommonTestingMethods.getURL());
            _ctm.findAndClick(Constants.UIString.ItemIDs.CREATE_REQUEST,
                              "/Request/Create");

            String rFName = "CrInt-" + Membership.GeneratePassword(10, 0);
            String rLName = "CrInt-" + Membership.GeneratePassword(10, 0);
            String rEmail = "*****@*****.**";
            String rPhone = "CrInt-" + Membership.GeneratePassword(10, 0);
            String rExt = "CrInt-" + Membership.GeneratePassword(10, 0);
            String pFName = "CrInt-" + Membership.GeneratePassword(10, 0);
            String pLName = "CrInt-" + Membership.GeneratePassword(10, 0);
            String pId = "CrInt-" + Membership.GeneratePassword(10, 0);
            String pAge = "123";
            String timeSpent = "1234";
            String parentRequest = rid1.ToString();
            String reference = "CrInt-" + Membership.GeneratePassword(10, 0);

            _driver.FindElement(By.Id("requestorFirstName"))
                   .SendKeys(rFName);
            _driver.FindElement(By.Id("requestorLastName"))
                   .SendKeys(rLName);
            _driver.FindElement(By.Id("requestorEmail"))
                   .SendKeys(rEmail);
            _driver.FindElement(By.Id("requestorPhoneNum"))
                   .SendKeys(rPhone);
            _driver.FindElement(By.Id("requestorPhoneExt"))
                   .SendKeys(rExt);
            _driver.FindElement(By.Id("patientFName"))
                   .SendKeys(pFName);
            _driver.FindElement(By.Id("patientLName"))
                   .SendKeys(pLName);
            _driver.FindElement(By.Id("patientAgencyID"))
                   .SendKeys(pId);
            _driver.FindElement(By.Id("patientAge"))
                   .SendKeys(pAge);
            _driver.FindElement(By.ClassName("time-spent"))
                   .SendKeys(timeSpent);
            _driver.FindElement(By.Id("parentRequestID"))
                   .SendKeys(parentRequest);
            _driver.FindElement(By.ClassName("reference"))
                   .SendKeys(reference);

            // Submit the Form
            _driver.FindElement(By.Id("save_draft")).Click();
            StringAssert.Contains("/Request/Details", _driver.Url);

            Request newReq =
                _cdc.Requests.OrderByDescending(r => r.RequestID).FirstOrDefault(r => true);
            if (newReq == null) {
                Assert.Fail("Can't find newly-created Request.");
            }

            StringAssert.AreEqualIgnoringCase(rFName, newReq.RequestorFName);
            StringAssert.AreEqualIgnoringCase(rLName, newReq.RequestorLName);
            StringAssert.AreEqualIgnoringCase(rEmail, newReq.RequestorEmail);
            StringAssert.AreEqualIgnoringCase(rPhone, newReq.RequestorPhone);
            StringAssert.AreEqualIgnoringCase(rExt, newReq.RequestorPhoneExt);
            StringAssert.AreEqualIgnoringCase(pFName, newReq.PatientFName);
            StringAssert.AreEqualIgnoringCase(pLName, newReq.PatientLName);
            StringAssert.AreEqualIgnoringCase(pId, newReq.PatientAgencyID);
            StringAssert.AreEqualIgnoringCase(pAge, newReq.PatientAge.ToString());
            StringAssert.AreEqualIgnoringCase(parentRequest, newReq.ParentRequestID.ToString());
            StringAssert.AreEqualIgnoringCase(timeSpent, newReq.QuestionResponses.First().TimeSpent.ToString());
            StringAssert.AreEqualIgnoringCase(reference, newReq.QuestionResponses.First().References.First().ReferenceString);

            // Cleanup Time
            IQueryable<AuditLog> aus =
                _cdc.AuditLogs.Where(a => a.RequestID == newReq.RequestID);
            _cdc.AuditLogs.DeleteAllOnSubmit(aus);

            Reference rf =
                _cdc.References.FirstOrDefault(r => r.RequestID == newReq.RequestID);
            if (rf == null) {
                Assert.Fail("Can't find Reference for Cleanup");
            }
            _cdc.References.DeleteOnSubmit(rf);

            QuestionResponse qr =
                _cdc.QuestionResponses.FirstOrDefault(qr2 => qr2.RequestID == newReq.RequestID);
            if (qr == null) {
                Assert.Fail("Can't find QuestionResponse for Cleanup");
            }

            Request req1 = _cdc.Requests.FirstOrDefault(r => r.RequestID == rid1);
            if (req1 == null) {
                Assert.Fail("Can't find Request for Cleanup");
            }

            _cdc.QuestionResponses.DeleteOnSubmit(qr);
            _cdc.Requests.DeleteOnSubmit(newReq);
            _cdc.Requests.DeleteOnSubmit(req1);
            _cdc.SubmitChanges();
        }