/// <summary> /// Create a QuestionResponse entity based off of the /// QuestionResponseContent. /// </summary> /// <param name="content">QuestionResponse content holder.</param> /// <returns>QuestionResponse entity based off of content.</returns> private QuestionResponse createQuestionResponseEntity( QuestionResponseContent content) { var qr = new QuestionResponse(); if (content.questionResponseID != -1) { // Existing QuestionResponse; has a QuestionResponseID qr = (from q in _db.QuestionResponses where q.QuestionResponseID == content.questionResponseID && q.RequestID == content.requestID select q).Single(); } qr.RequestID = content.requestID; qr.Question = content.question; qr.Response = content.response; qr.TimeSpent = content.timeSpent; qr.SpecialNotes = content.specialNotes; qr.QuestionTypeID = content.questionTypeID; qr.TumourGroupID = content.tumourGroupID; qr.Severity = (byte?) content.severity; qr.Consequence = (byte?) content.consequence; return qr; }
public ActionResult NewQuestionResponse(String json) { // Don't want to load a partial with a Not Authorized message if (!Roles.IsUserInRole(Constants.Roles.REQUEST_EDITOR)) { return RedirectToAction("Index", "Home", new { status = Constants.URLStatus.NoRequestEditorRole }); } var dc = new DropdownManagementController(); QuestionResponseContent qrContent; if (String.IsNullOrEmpty(json)) { qrContent = new QuestionResponseContent(); } else { qrContent = new JavaScriptSerializer() .Deserialize<QuestionResponseContent>(json); } // Used to set dynamic model binding index ViewBag.Guid = HtmlPrefixScopeExtensions.CreateItemIndex( "questionResponseList"); ViewBag.QuestionTypes = new SelectList( dc.getEntries(Constants.DropdownTable.QuestionType), "id", "text"); ViewBag.TumourGroups = new SelectList( dc.getEntries(Constants.DropdownTable.TumourGroup), "id", "text"); ViewBag.Severitys = new SelectList(Constants.severityOptions); ViewBag.Consequences = new SelectList(Constants.consequenceOptions); return View("Partial/NewQuestionResponse", qrContent); }
/// <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; } }
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(); }
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(); }
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 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(); }
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)); } }
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> /// Add a QuestionResponseContent to the List /// </summary> /// <param name="newQr">The new QuestionResponse</param> public void addQuestionResponse(QuestionResponseContent newQr) { _questionResponseList.Add(newQr); }
public void setUp() { Random random = new Random(); _randomRequestInt = random.Next(1, 100000000); _randomRequestInt2 = random.Next(1, 10000000); _randomRequestInt3 = random.Next(1, 100000000); _randomKeyword = new Keyword { KeywordID = random.Next(1,100000000), KeywordValue = ("TSMC" + random.Next(1, 100000000).ToString(CultureInfo.InvariantCulture)) }; _randomKeyword2 = new Keyword { KeywordID = random.Next(1,100000000), KeywordValue = ("TSMC" + random.Next(1, 100000000).ToString(CultureInfo.InvariantCulture)) }; _randomKeyword3 = new Keyword { KeywordValue = ("TSMC" + random.Next(1, 100000000).ToString(CultureInfo.InvariantCulture)) }; _randomKeyword4 = new Keyword { KeywordID = random.Next(1,100000000), KeywordValue = ("TSMC" + random.Next(1, 100000000).ToString(CultureInfo.InvariantCulture)) }; QuestionResponseContent testQrc = new QuestionResponseContent(); testQrc.requestID = _randomRequestInt; testQrc.keywords.Add(_randomKeyword.KeywordValue); testQrc.keywords.Add(_randomKeyword2.KeywordValue); testQrc.severity = Constants.Severity.Minor; testQrc.consequence = Constants.Consequence.Certain; QuestionResponseContent testQrc2 = new QuestionResponseContent(); testQrc2.requestID = _randomRequestInt2; testQrc2.keywords.Add(_randomKeyword3.KeywordValue); testQrc2.severity = Constants.Severity.Moderate; testQrc2.consequence = Constants.Consequence.Possible; QuestionResponseContent testQrc3 = new QuestionResponseContent(); testQrc2.requestID = _randomRequestInt3; testQrc2.keywords.Add(_randomKeyword4.KeywordValue); testQrc.severity = Constants.Severity.Major; testQrc3.consequence = Constants.Consequence.Possible; RequestManagementController rmc = new RequestManagementController(); RequestManagementController rmc2 = new RequestManagementController(); RequestManagementController rmc3 = new RequestManagementController(); rmc.create(new RequestContent { patientFName = "TSMC Test", questionResponseList = { testQrc, testQrc3 }, requestStatus = Constants.RequestStatus.Open, requestorFirstName = "10", requestorLastName = "100", }); rmc3.create(new RequestContent { patientFName = "TSMC Test2", requestorFirstName = "20", requestorLastName = "100", questionResponseList = { testQrc2, testQrc }, requestStatus = Constants.RequestStatus.Open }); rmc2.create(new RequestContent { patientFName = "TSMC Test3", requestorFirstName = "30", requestorLastName = "100", questionResponseList = { testQrc3 }, requestStatus = Constants.RequestStatus.Open }); _rq = _dc.Requests.FirstOrDefault( request => request.PatientFName == "TSMC Test"); _rq2 = _dc.Requests.FirstOrDefault( request => request.PatientFName == "TSMC Test2"); _rq3 = _dc.Requests.FirstOrDefault( request => request.PatientFName == "TSMC Test3"); }