public void Get_a_different_hashcode() { var collection = CreateDataCollection(); Session.Save(collection); Session.Flush(); var savedCollection = _dataCollectionRepository.Get(collection.Id); Assert.That(savedCollection, Is.Not.Null); var hashCode = savedCollection.NewDataCollectionHashCode(); Assert.That(string.IsNullOrWhiteSpace(hashCode.HashCode), Is.False); Session.Save(hashCode); Session.Flush(); var savedHashCode = _hashCodeRepository.Get(hashCode.Id); Assert.That(savedHashCode, Is.Not.Null); Assert.That(hashCode.HashCode, Is.EqualTo(savedHashCode.HashCode)); collection.Keywords = "New keywords"; Assert.That(savedHashCode.UpdateHashCode(collection), Is.True); Session.Save(savedHashCode); Session.Flush(); var updatedHashCode = _hashCodeRepository.Get(hashCode.Id); Assert.That(updatedHashCode, Is.Not.Null); Assert.That(savedHashCode.HashCode, Is.EqualTo(updatedHashCode.HashCode)); Assert.That(hashCode.HashCode, Is.Not.EqualTo(updatedHashCode.HashCode)); }
public void Return_empty_result_when_invalid_data_collection_id_passed_on_ajax_call_to_GetNewUrdmsUserForApproval_for_a_data_collection() { const string userId = "EE21168"; const int dataCollectionId = 1; _dataCollectionRepository.Get(dataCollectionId).Returns(x => null); _controller.WithCallTo(c => c.GetNewUrdmsUserForApproval(userId, dataCollectionId)).ShouldRenderEmptyResult(); }
public void Create_viewmodel_with_projectid_set() { var dataCollection = Builder <DataCollection> .CreateNew().Build(); _dataCollectionRepository.Get(dataCollection.Id).Returns(dataCollection); AddProjectIdToFormCollection(dataCollection); var bindingContext = GetBindingContext(); var binder = new DataCollectionApprovalViewModelStep1Binder { DataCollectionRepository = _dataCollectionRepository }; var viewModel = binder.BindModel(_context, bindingContext) as DataCollectionViewModelStep1; Assert.That(viewModel, Is.Not.Null, "Viewmodel is null"); Assert.That(viewModel.ProjectId, Is.EqualTo(dataCollection.ProjectId)); }
public void Send_a_export_to_vivo_response_on_message_of_export_to_vivo_message() { var handler = new ExportToVivoHandler(_vivoDataCollectionRepository, _dataCollectionRepository); _dataCollectionRepository.Get(Arg.Is(1)); Test.Handler(handler) .ExpectReply <ExportToVivoResponse>(m => m.DataCollectionId == 1) .OnMessage <ExportToVivo>(m => { m.DataCollectionId = 1; }); _dataCollectionRepository.Received().Get(Arg.Is(1)); _vivoDataCollectionRepository.Received().Save(Arg.Any <DataCollection>()); }
public ActionResult GetNewUrdmsUserForApproval(string term, int dataCollectionId) { if (string.IsNullOrWhiteSpace(term) || dataCollectionId < 1) { return(new EmptyResult()); } var dataCollection = _dataCollectionRepository.Get(dataCollectionId); if (dataCollection == null) { return(new EmptyResult()); } var manager = dataCollection.Parties.Single(p => p.Relationship == DataCollectionRelationshipType.Manager).Party; if (term.Equals(manager.UserId, StringComparison.InvariantCultureIgnoreCase)) { return(new EmptyResult()); } var urdmsUser = GetUser(term); if (urdmsUser == null) { return(new EmptyResult()); } var values = Enum.GetValues(typeof(DataCollectionRelationshipType)).Cast <DataCollectionRelationshipType>().Except(new[] { DataCollectionRelationshipType.Manager, DataCollectionRelationshipType.None }); ViewBag.Relationships = values.ToDictionary(o => (int)o, o => o.GetDescription()); var newRow = new UrdmsUserViewModel { Id = 0, UserId = urdmsUser.CurtinId, FullName = urdmsUser.FullName, Relationship = (int)DataCollectionRelationshipType.AssociatedResearcher }; return(PartialView("_UrdmsUser", newRow)); }
public ActionResult DataCollectionToCsv(CsvDumpViewModel model) { var formParams = ControllerContext.HttpContext.Request.Form; var collectionList = formParams["DataCollectionList"]; int collectionId; if (int.TryParse(collectionList, out collectionId)) { var dataCollection = _dataCollectionRepository.Get(collectionId); if (dataCollection != null) { var dataCollectionTable = _csvHelper.DataCollectionToDataTable(dataCollection); var reponse = this.ControllerContext.RequestContext.HttpContext.Response; var fileName = Regex.Replace(dataCollection.Title, @"\W+", "_").Trim('_'); reponse.AddHeader("Content-Disposition", "attachment;filename=" + fileName + "_DataCollection.csv"); return(File(Encoding.UTF8.GetBytes(_csvHelper.ExportToCsv(dataCollectionTable, _appSettingsService.CsvSeparator)), "text/csv")); } return(View("DataCollectionNotFound")); } return(RedirectToAction("Index")); }
public void Render_CSV_file_for_post_to_DataCollectionToCsv() { var vm = new CsvDumpViewModel { DataCollections = Builder <CollectionListViewModel> .CreateListOfSize(3).Build() }; _form["DataCollectionCsv"] = "Get Data Management Plan to CSV"; _form["DataCollectionList"] = "1"; var dataCollection = SetUpDataCollection("GA37493"); _dataCollectionRepository.Get(dataCollection.Id).Returns(dataCollection); _csvHelper.ExportToCsv(Arg.Any <DataTable>()).Returns(""); _csvHelper.DataCollectionToDataTable(Arg.Any <DataCollection>()).Returns(new DataTable()); _controller.WithCallTo(c => c.DataCollectionToCsv(vm)).ShouldRenderFile("text/csv"); _csvHelper.Received().ExportToCsv(Arg.Any <DataTable>(), Arg.Any <string>()); _csvHelper.Received().DataCollectionToDataTable(Arg.Any <DataCollection>()); const string headerValue = "attachment;filename=Feeding_habits_of_polarbears_2011_DataCollection.csv"; _context.HttpContext.Response.Received().AddHeader(Arg.Any <string>(), Arg.Is <string>(o => o == headerValue)); }
public void Handle(ExportToVivo message) { try { Log.InfoFormat("[URDMS] Retrieving Data Collection info for id: {0}.", message.DataCollectionId); var dataCollection = _dataCollectionRepository.Get(message.DataCollectionId); Log.Info("[URDMS] Updating Vivo database."); _vivoDataCollectionRepository.Save(dataCollection); Log.Info("[URDMS] Vivo database update completed successfully."); // When complete reply to Approval Service Bus.Reply <ExportToVivoResponse>(m => { m.RecordPublishedOn = DateTime.Now; m.DataCollectionId = message.DataCollectionId; }); } catch (Exception ex) { Log.ErrorFormat("[URDMS] Error publishing to Vivo. Exception: {0}", ex); throw; } }
public void Show_step1_if_user_is_a_qa_approver_with_a_submitted_collection() { CreateQaUser(); var project = CreateProject(); var collection = Builder <DataCollection> .CreateNew() .With(o => o.CurrentState = Builder <DataCollectionState> .CreateNew() .WithConstructor(() => new DataCollectionState(DataCollectionStatus.Submitted, DateTime.Now)).Build()) .And(o => o.ProjectId = project.Id) .Build(); var party = Builder <DataCollectionParty> .CreateNew() .With(o => o.Relationship = DataCollectionRelationshipType.Manager) .And(o => o.Party = Builder <Party> .CreateNew().Build()) .And(o => o.DataCollection = collection) .Build(); collection.Parties.Add(party); _dataCollectionRepository.Get(Arg.Is(collection.Id)).Returns(collection); _projectRepository.Get(Arg.Is(project.Id)).Returns(project); _controller.WithCallTo(c => c.Step1(collection.Id)).ShouldRenderView("DataCollectionStep1"); }