private List <TrusteeDateOfBirth> MapTrusteesDataToViewModel(TabularData trusteeData) { var trusteeDatesOfBirth = new List <TrusteeDateOfBirth>(); if (trusteeData != null && trusteeData.DataRows != null) { foreach (var trustee in trusteeData.DataRows) { var trusteeDob = new TrusteeDateOfBirth { Id = trustee.Id, Name = trustee.Columns[0] }; if (trustee.Columns.Count > 1) { var shortDob = trustee.Columns[1]; trusteeDob.DobMonth = DateOfBirthFormatter.GetMonthNumberFromShortDateOfBirth(shortDob); trusteeDob.DobYear = DateOfBirthFormatter.GetYearFromShortDateOfBirth(shortDob); } trusteeDatesOfBirth.Add(trusteeDob); } } return(trusteeDatesOfBirth); }
private TabularData MapAnswersToTrusteesDob(TabularData trusteesData, List <Answer> answers) { if (trusteesData == null) { return(null); } if (trusteesData.HeadingTitles.Count < 2) { trusteesData.HeadingTitles.Add("Date of birth"); } foreach (var trustee in trusteesData.DataRows) { var dobMonthKey = $"{trustee.Id}_Month"; var dobYearKey = $"{trustee.Id}_Year"; var dobMonth = answers.FirstOrDefault(x => x.QuestionId == dobMonthKey); var dobYear = answers.FirstOrDefault(x => x.QuestionId == dobYearKey); if (dobMonth == null || dobYear == null) { break; } if (trustee.Columns.Count < 2) { trustee.Columns.Add(DateOfBirthFormatter.FormatDateOfBirth(dobMonth.Value, dobYear.Value)); } else { trustee.Columns[1] = DateOfBirthFormatter.FormatDateOfBirth(dobMonth.Value, dobYear.Value); } } return(trusteesData); }
public bool IsRowAlreadyPresent(TabularData currentTabularData, TabularDataRow newRow) { var isPresent = false; foreach (var row in currentTabularData.DataRows) { isPresent = true; if (row.Columns.Count != newRow.Columns.Count) { isPresent = false; } else { for (var i = 0; i < row.Columns.Count; i++) { if (newRow.Columns[i] == row.Columns[i]) { continue; } isPresent = false; break; } if (isPresent) { return(isPresent); } } } return(isPresent); }
/// <summary> /// Process the new data. /// </summary> private void ProcessData() { // Get the average velocity and direction CalcAvgVelDir(); // Get the boat speed AverageBoatSpeed(); // Pass the data to tabular TabularData.ProcessData(_ensemble); if (TabularDataExpanded != null) { TabularDataExpanded.ProcessData(_ensemble); } TimeSeriesPlot.AddEnsemble(_ensemble); // Plot 3D Velocity Plot Plot3dVelocityPlot(); // Update the Heatmap HeatmapPlot.AddEnsemble(_ensemble); if (HeatmapPlotExapnded != null) { HeatmapPlotExapnded.AddEnsemble(_ensemble); } // Plot the amplitude data AmplitudePlot.AddEnsemble(_ensemble); // Plot the correlation data CorrelationPlot.AddEnsemble(_ensemble); }
public static List <ValidationErrorDetail> ValidateTrusteeDatesOfBirth(TabularData trusteesData, List <Answer> answers) { var errorMessages = new List <ValidationErrorDetail>(); foreach (var trustee in trusteesData.DataRows) { var dobMonthKey = $"{trustee.Id}_Month"; var dobYearKey = $"{trustee.Id}_Year"; var dobMonth = answers.FirstOrDefault(x => x.QuestionId == dobMonthKey); var dobYear = answers.FirstOrDefault(x => x.QuestionId == dobYearKey); if (dobMonth == null && dobYear == null) { errorMessages.Add(new ValidationErrorDetail { ErrorMessage = DateOfBirthAnswerValidator.MissingDateOfBirthErrorMessage, Field = dobMonthKey }); return(errorMessages); } var prefix = trustee.Id + "_"; var validatorMessages = DateOfBirthAnswerValidator.ValidateDateOfBirth(dobMonth.Value, dobYear.Value, prefix); if (validatorMessages.Any()) { errorMessages.AddRange(validatorMessages); } } return(errorMessages); }
public void GetAnswers_when_TabularData_null_Returns_empty() { _tabularData = null; var result = TabularDataMapper.GetAnswers(_applicationId, _sequenceNumber, _sectionNumber, _pageId, _question, _tabularData); CollectionAssert.IsEmpty(result); }
bool IDataParser.TryParse(FileInfo info, out TabularData tabularData) { tabularData = new TabularData().Default(info); IParser parser = _Factory.Create(info); parser.Parse(tabularData); return(tabularData.IsOkay); }
public void GetAnswers_when_TabularData_empty_Returns_empty() { _tabularData = new TabularData(); var result = TabularDataMapper.GetAnswers(_applicationId, _pageId, _question, _tabularData); CollectionAssert.IsEmpty(result); }
bool IDataParser.TryParse(string body, out TabularData tabularData) { tabularData = new TabularData().Default(body); IParser parser = _Factory.Create(body); parser.Parse(tabularData); return(tabularData.IsOkay); }
//public override void RemoveConnectionByGroup(RemoveConntectionByGroupArgs e) //{ // if (m_connCache.ContainsKey(e.GroupId)) // { // if (!AllowClose()) // { // e.Canceled = true; // return; // } // Async.SafeClose(m_connCache[e.GroupId]); // m_connCache.Remove(e.GroupId); // } //} public override bool AllowCloseConnection(string connkey) { if (TabularData != null && TabularData.GetConnectionKey() == connkey) { return(AllowClose()); } return(true); }
public async Task get_list_of_whos_in_control_submitted_when_AddPeopleInControl_tag_filled(string name1, string dateOfBirth1, string name2, string dateOfBirth2) { var expectedPersonInControl2 = new PersonInControl { Name = name1, MonthYearOfBirth = dateOfBirth1 }; var expectedPersonInControl1 = new PersonInControl { Name = name2, MonthYearOfBirth = dateOfBirth2 }; var consumedTabularData = new TabularData { DataRows = new List <TabularDataRow> { new TabularDataRow { Columns = new List <string> { name1, dateOfBirth1 } }, new TabularDataRow { Columns = new List <string> { name2, dateOfBirth2 } } } }; _qnaApiClient .Setup(x => x.GetTabularDataByTag(_applicationId, RoatpWorkflowQuestionTags.AddPeopleInControl)) .ReturnsAsync(consumedTabularData); _qnaApiClient .Setup(x => x.GetTabularDataByTag(_applicationId, RoatpWorkflowQuestionTags.AddPartners)) .ReturnsAsync((TabularData)null); _qnaApiClient .Setup(x => x.GetAnswerByTag(_applicationId, RoatpWorkflowQuestionTags.SoleTradeDob, null)) .ReturnsAsync((Answer)null); _qnaApiClient .Setup(x => x.GetAnswerByTag(_applicationId, RoatpWorkflowQuestionTags.UkrlpLegalName, null)) .ReturnsAsync((Answer)null); var result = await _controller.GetWhosInControlFromSubmitted(_applicationId) as OkObjectResult; result.Value.Should().BeOfType <List <PersonInControl> >(); var peopleInControl = (List <PersonInControl>)result.Value; Assert.AreEqual(2, peopleInControl.Count); Assert.AreEqual(peopleInControl[0].Name, expectedPersonInControl1.Name); Assert.AreEqual(peopleInControl[0].MonthYearOfBirth, expectedPersonInControl1.MonthYearOfBirth); Assert.AreEqual(peopleInControl[1].Name, expectedPersonInControl2.Name); Assert.AreEqual(peopleInControl[1].MonthYearOfBirth, expectedPersonInControl2.MonthYearOfBirth); _qnaApiClient.Verify(x => x.GetTabularDataByTag(_applicationId, RoatpWorkflowQuestionTags.AddPeopleInControl), Times.Once); _qnaApiClient.Verify(x => x.GetTabularDataByTag(It.IsAny <Guid>(), RoatpWorkflowQuestionTags.AddPartners), Times.Never); _qnaApiClient.Verify(x => x.GetAnswerByTag(It.IsAny <Guid>(), RoatpWorkflowQuestionTags.SoleTradeDob, null), Times.Never); _qnaApiClient.Verify(x => x.GetAnswerByTag(It.IsAny <Guid>(), RoatpWorkflowQuestionTags.UkrlpLegalName, null), Times.Never); }
/// <summary> /// Shutdown the view model. /// </summary> public void Dispose() { TabularData.Dispose(); if (TabularDataExpanded != null) { TabularDataExpanded.Dispose(); } }
public async Task <IActionResult> AddPeopleInControlDetails(AddEditPeopleInControlViewModel model) { var errorMessages = PeopleInControlValidator.Validate(model); if (errorMessages.Any()) { model.ErrorMessages = errorMessages; return(View("~/Views/Roatp/WhosInControl/AddPeopleInControl.cshtml", model)); } var whosInControlSection = await _qnaApiClient.GetSectionBySectionNo(model.ApplicationId, RoatpWorkflowSequenceIds.YourOrganisation, RoatpWorkflowSectionIds.YourOrganisation.WhosInControl); var personInControlData = await _tabularDataRepository.GetTabularDataAnswer(model.ApplicationId, RoatpWorkflowQuestionTags.AddPeopleInControl); var personInControl = new TabularDataRow { Id = Guid.NewGuid().ToString(), Columns = new List <string> { model.PersonInControlName, DateOfBirthFormatter.FormatDateOfBirth(model.PersonInControlDobMonth, model.PersonInControlDobYear) } }; if (personInControlData == null) { personInControlData = new TabularData { HeadingTitles = new List <string> { "Name", "Date of birth" }, DataRows = new List <TabularDataRow> { personInControl } }; var result = await _tabularDataRepository.SaveTabularDataAnswer( model.ApplicationId, whosInControlSection.Id, RoatpWorkflowPageIds.WhosInControl.AddPeopleInControl, RoatpYourOrganisationQuestionIdConstants.AddPeopleInControl, personInControlData); } else { var result = await _tabularDataRepository.UpsertTabularDataRecord( model.ApplicationId, whosInControlSection.Id, RoatpWorkflowPageIds.WhosInControl.AddPeopleInControl, RoatpYourOrganisationQuestionIdConstants.AddPeopleInControl, RoatpWorkflowQuestionTags.AddPeopleInControl, personInControl); } return(RedirectToAction("ConfirmPeopleInControl", new { model.ApplicationId })); }
void NonExistentTestDataFileThrowsException(string inputPath) { // Arrange TabularData td = new TabularData(); // Act // Assert Assert.ThrowsAsync <FileNotFoundException>(async() => { var results = td.LoadDataToSort(inputPath).Result; }); }
void CanLoadTestData(string inputPath) { // Arrange TabularData td = new TabularData(); // Act var results = td.LoadDataToSort(inputPath); // Assert Assert.NotNull(results); }
public void Checking_Row_Already_Present_When_Table_And_Row_Empty_Returns_False() { var tabularData = new TabularData { DataRows = new List <TabularDataRow>() }; var tabularDataRow = new TabularDataRow(); var result = new TabularDataService().IsRowAlreadyPresent(tabularData, tabularDataRow); Assert.IsFalse(result); }
public async Task <QueryResult <GroupDto> > GetUserGroupsAsync(int userId, TabularData tabularData, Func <Sorting, string> sort = null) { var orderField = string.Empty; if (sort != null && tabularData.Sorting != null) { orderField = sort(tabularData.Sorting); } if (!string.IsNullOrWhiteSpace(tabularData.Search)) { tabularData.Search = UsersHelper.ReplaceWildcardCharacters(tabularData.Search); } var parameters = new DynamicParameters(); parameters.Add("@UserId", userId); parameters.Add("@Offset", tabularData.Pagination.Offset); parameters.Add("@Limit", tabularData.Pagination.Limit); parameters.Add("@OrderField", orderField); parameters.Add("@Search", tabularData.Search); parameters.Add("@Total", dbType: DbType.Int32, direction: ParameterDirection.Output); parameters.Add("@ErrorCode", dbType: DbType.Int32, direction: ParameterDirection.Output); var userGroups = await _connectionWrapper.QueryAsync <Group>("GetUsersGroups", parameters, commandType : CommandType.StoredProcedure); var total = parameters.Get <int?>("Total"); var errorCode = parameters.Get <int?>("ErrorCode"); if (errorCode.HasValue) { switch (errorCode.Value) { case (int)SqlErrorCodes.GeneralSqlError: throw new BadRequestException(ErrorMessages.GeneralErrorOfGettingUserGroups); case (int)SqlErrorCodes.UserLoginNotExist: throw new ResourceNotFoundException(ErrorMessages.UserNotExist, ErrorCodes.ResourceNotFound); } } if (!total.HasValue) { throw new BadRequestException(ErrorMessages.TotalNull); } var mappedGroups = GroupMapper.Map(userGroups); var queryDataResult = new QueryResult <GroupDto>() { Items = mappedGroups, Total = total.Value }; return(queryDataResult); }
protected virtual bool SetupDataTable(TabularData tabularData, List <string> lines) { bool b = false; Profiler profiler = new Profiler(); if (profiler.TryDiscover(lines, out DataTable dt)) { tabularData.Data = dt; b = true; } return(b); }
public void Checking_No_FallOver_If_TabularData_Empty() { var tabularData = new TabularData { DataRows = new List <TabularDataRow>() }; var tabularDataActual = new TabularDataService().DeduplicateData(tabularData); var isEqual = CompareTwoSources(tabularData, tabularDataActual); Assert.IsTrue(isEqual); }
public async Task EditManagementHierarchy_Get_ReturnsConfirmManagementHierarchy() { var index = 0; TabularData personTableData = null; _tabularDataRepository.Setup(x => x.GetTabularDataAnswer(It.IsAny <Guid>(), RoatpWorkflowQuestionTags.AddManagementHierarchy)).ReturnsAsync(personTableData); var result = await _controller.EditManagementHierarchy(_applicationId, index); var viewResult = result as RedirectToActionResult; viewResult.Should().NotBeNull(); viewResult.ActionName.Should().Be("ConfirmManagementHierarchy"); }
public override void Parse(TabularData tabularData) { List <string> lines = new List <string>(); if (tabularData.Info != null) { lines = tabularData.Info.AllLines(); } else if (!string.IsNullOrWhiteSpace(tabularData.Body)) { lines = new List <string>(tabularData.Body.AllLines()); } }
public async Task <IHttpActionResult> GetGroupMembers(int groupId, [FromUri] Pagination pagination, [FromUri] Sorting sorting) { pagination.Validate(); await _privilegesManager.Demand(Session.UserId, InstanceAdminPrivileges.ViewGroups); var tabularData = new TabularData { Pagination = pagination, Sorting = sorting }; var result = await _groupRepository.GetGroupMembersAsync(groupId, tabularData, SortingHelper.SortUsergroups); return(Ok(result)); }
void CanLoadAndSaveTestData(string inputPath, string outputPath) { // Arrange TabularData td = new TabularData(); // Act var results = td.LoadDataToSort(inputPath); td.SaveOrderedData(outputPath, results.Result); // Assert bool fileCreated = File.Exists(outputPath); Assert.True(fileCreated); }
public TabularData DeduplicateData(TabularData tabularData) { var tabularDataDeduplicated = new TabularData { DataRows = new List <TabularDataRow>() }; foreach (var row in tabularData.DataRows.Where(row => !IsRowAlreadyPresent(tabularDataDeduplicated, row))) { tabularDataDeduplicated.DataRows.Add(row); } tabularData.DataRows = tabularDataDeduplicated.DataRows; return(tabularData); }
public async Task <IHttpActionResult> GetGroupsAndUsers([FromUri] Pagination pagination, [FromUri] Sorting sorting, string search = null, int groupId = 0) { pagination.Validate(); SearchFieldValidator.Validate(search); await _privilegesManager.Demand(Session.UserId, InstanceAdminPrivileges.ViewGroups); var tabularData = new TabularData { Pagination = pagination, Sorting = sorting, Search = search }; var result = await _groupRepository.GetGroupUsersAsync(groupId, tabularData, SortingHelper.SortUsergroups); return(Ok(result)); }
public async Task GetProjectGroupsAsync_GroupsFound_NoErrors() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlGroupRepository(cxn.Object); var projectId = 100; int errorCode = 0; Group[] projectGroups = { new Group() { Name = "Group1" }, new Group() { Name = "Group2" }, new Group() { Name = "Group3" } }; var tabularData = new TabularData { Pagination = new Pagination { Limit = 10, Offset = 0 }, Sorting = new Sorting { Order = SortOrder.Asc, Sort = "name" } }; cxn.SetupQueryAsync("GetAvailableGroupsForProject", new Dictionary <string, object> { { "projectId", projectId } }, projectGroups, new Dictionary <string, object> { { "ErrorCode", errorCode } }); // Act await repository.GetProjectGroupsAsync(projectId, tabularData, SortingHelper.SortProjectGroups); // Assert cxn.Verify(); }
public void Checking_Row_Already_Present_When_Table_Empty_And_Row_Filled_Returns_False() { var tabularData = new TabularData { DataRows = new List <TabularDataRow>() }; var tabularDataRow = new TabularDataRow { Columns = new List <string> { "item 1", "item 2" } }; var result = new TabularDataService().IsRowAlreadyPresent(tabularData, tabularDataRow); Assert.IsFalse(result); }
public static TabularData Transform(TabularData tabularData) { var managementHierarchy = new TabularData { Caption = null, HeadingTitles = new List <string>(TransformHeadingTitles), DataRows = new List <TabularDataRow>() }; if (tabularData?.DataRows != null && tabularData.DataRows.Any()) { managementHierarchy.DataRows = new List <TabularDataRow>(tabularData.DataRows.Select(dr => { return(dr.TransformDataRow()); })); } return(managementHierarchy); }
public async Task <IHttpActionResult> GetProjectRoleAssignments(int projectId, [FromUri] Pagination pagination, [FromUri] Sorting sorting, string search = null) { pagination.Validate(); SearchFieldValidator.Validate(search); await _privilegesManager.DemandAny(Session.UserId, projectId, InstanceAdminPrivileges.AccessAllProjectsAdmin, ProjectAdminPrivileges.ViewGroupsAndRoles); var tabularData = new TabularData { Pagination = pagination, Sorting = sorting, Search = search }; var result = await _instanceRepository.GetProjectRoleAssignmentsAsync(projectId, tabularData, SortingHelper.SortProjectRolesAssignments); return(Ok(result)); }
public void Checking_Expected_Change_If_TabularData_Has_Duplicates() { var tabularDataEntered = new TabularData { DataRows = new List <TabularDataRow> { new TabularDataRow { Columns = new List <string> { "item 1", "item 2" } }, new TabularDataRow { Columns = new List <string> { "item 1", "item 2" } }, new TabularDataRow { Columns = new List <string> { "item 5", "item 6" } } } }; var tabularDataExpected = new TabularData { DataRows = new List <TabularDataRow> { new TabularDataRow { Columns = new List <string> { "item 1", "item 2" } }, new TabularDataRow { Columns = new List <string> { "item 5", "item 6" } } } }; var tabularDataActual = new TabularDataService().DeduplicateData(tabularDataEntered); var isEqual = CompareTwoSources(tabularDataExpected, tabularDataActual); Assert.IsTrue(isEqual); }