public void Given_Task_Service_is_initialized_with_spy_repository_When_Search_is_called_Then_repo_search_called_accordingly() { //Given var riskAssessmentService = CreateRiskAssessmentService(); var request = new SearchRiskAssessmentsRequest() { Title = "title", CompanyId = 123, CreatedFrom = DateTime.Now.AddDays(-1), CreatedTo = DateTime.Now, ShowArchived = true, ShowDeleted = false }; _riskAssessmentRepository.Setup(rr => rr.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())).Returns(new GeneralRiskAssessment()); _riskAssessmentRepository .Setup(rr => rr.Search(It.IsAny<string>(), It.IsAny<long>(), null, It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<long?>(), It.IsAny<long?>() , It.IsAny<Guid>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<RiskAssessmentOrderByColumn>(), It.IsAny<OrderByDirection>())) .Returns(new List<GeneralRiskAssessment>()); //When riskAssessmentService.Search(request); //Then _riskAssessmentRepository.Verify(x => x.Search(request.Title, request.CompanyId, null, request.CreatedFrom, request.CreatedTo, null, null, request.CurrentUserId, request.ShowDeleted, request.ShowArchived, It.IsAny<int>(), It.IsAny<int>(), request.OrderBy, request.OrderByDirection), Times.Once()); }
public virtual IEnumerable<GeneralRiskAssessmentDto> Search(SearchRiskAssessmentsRequest request) { var riskAssessments = _generalRiskAssessmentRepository.Search( request.Title, request.CompanyId, request.AllowedSiteIds, request.CreatedFrom, request.CreatedTo, request.SiteGroupId, request.SiteId, request.CurrentUserId, request.ShowDeleted, request.ShowArchived, request.Page, request.PageSize, request.OrderBy, request.OrderByDirection ); var riskAssessmentDtos = new RiskAssessmentDtoMapper().MapWithSiteAndRiskAssessor(riskAssessments); var generalRiskAssessmentDto = riskAssessmentDtos.Select(riskAssessmentDto => riskAssessmentDto as GeneralRiskAssessmentDto); return generalRiskAssessmentDto; }
private SearchRiskAssessmentsRequest CreateRiskAssessmentsSearchRequest() { var riskAssessmentsSearchRequest = new SearchRiskAssessmentsRequest { Title = _title, CompanyId = _companyId, CreatedFrom = string.IsNullOrEmpty(_createdFrom) ? (DateTime?)null : DateTime.Parse(_createdFrom), CreatedTo = string.IsNullOrEmpty(_createdTo) ? (DateTime?)null : DateTime.Parse(_createdTo), SiteGroupId = _siteGroupId, ShowDeleted = _showDeleted, ShowArchived = _showArchived, AllowedSiteIds = _allowedSiteIds, CurrentUserId = _currentUserId, SiteId = _siteId, Page = _page != default(int) ? _page : 1, PageSize = _pageSize != default(int) ? _pageSize : DEFAULT_PAGE_SIZE, OrderBy = RiskAssessmentTelerikOrderByHelper.GetOrderBy(_orderBy), OrderByDirection = RiskAssessmentTelerikOrderByHelper.GetOrderByDirection(_orderBy) }; return riskAssessmentsSearchRequest; }
public int Count(SearchRiskAssessmentsRequest request) { return _personalRiskAssessmentRepository.Count( request.Title, request.CompanyId, request.AllowedSiteIds, request.CreatedFrom, request.CreatedTo, request.SiteGroupId, request.SiteId, request.CurrentUserId, request.ShowDeleted, request.ShowArchived ); }
public void When_values_are_passed_Then_riskAssessmentService_Search_receives_passed_values() { // Given var companyId = 123; var from = DateTime.Now.AddDays(-1); var to = DateTime.Now; var showDeleted = true; var showArchived = true; _target = (SearchRiskAssessmentViewModelFactory)_target .WithCompanyId(companyId) .WithCreatedFrom(from.ToShortDateString()) .WithCreatedTo(to.ToShortDateString()) .WithShowDeleted(showDeleted) .WithShowArchived(showArchived); var passedSearchRiskAssessmentsRequest = new SearchRiskAssessmentsRequest(); _riskAssessmentService .Setup(x => x.Search(It.IsAny<SearchRiskAssessmentsRequest>())) .Returns(new List<FireRiskAssessmentDto>()) .Callback<SearchRiskAssessmentsRequest>(y => passedSearchRiskAssessmentsRequest = y); // When _target.GetViewModel(); // Then Assert.That(passedSearchRiskAssessmentsRequest.CompanyId, Is.EqualTo(companyId)); Assert.That(passedSearchRiskAssessmentsRequest.CreatedFrom.Value, Is.EqualTo(from.Date)); Assert.That(passedSearchRiskAssessmentsRequest.CreatedTo.Value, Is.EqualTo(to.Date)); Assert.That(passedSearchRiskAssessmentsRequest.ShowDeleted, Is.EqualTo(showDeleted)); Assert.That(passedSearchRiskAssessmentsRequest.ShowArchived, Is.EqualTo(showArchived)); }
public virtual int Count(SearchRiskAssessmentsRequest request) { var count = _fireRiskAssessmentRepository.Count( request.Title, request.CompanyId, request.AllowedSiteIds, request.CreatedFrom, request.CreatedTo, request.SiteGroupId, request.SiteId, request.CurrentUserId, request.ShowDeleted, request.ShowArchived ); return count; }
public void Given_search_criteria_contains_user_id_and_user_does_not_have_permission_for_all_sites_When_search_called_correct_methods_called() { //Given var companyId = 346L; var createdFrom = DateTime.Now; var createdTo = DateTime.Now; var userId = Guid.NewGuid(); var title = "title"; _riskAssessmentRepository .Setup(x => x.Search(title, companyId, It.Is<List<long>>(y => y.Count == 3 && y.Contains(345L) && y.Contains(346L) && y.Contains(347L)), createdFrom, createdTo, null, null, userId, false, false, It.IsAny<int>(), It.IsAny<int>(), It.IsAny<RiskAssessmentOrderByColumn>(), It.IsAny<OrderByDirection>())) .Returns(new List<GeneralRiskAssessment>()); var riskAssessmentService = CreateRiskAssessmentService(); var request = new SearchRiskAssessmentsRequest { Title = title, CompanyId = companyId, CreatedFrom = createdFrom, CreatedTo = createdTo, AllowedSiteIds = new List<long>() { 345L, 346L, 347L}, ShowArchived = false, ShowDeleted = false, CurrentUserId = userId }; //When riskAssessmentService.Search(request); //Then _riskAssessmentRepository.Verify(x => x.Search(title, companyId, null, createdFrom, createdTo, null, null, userId, false, false, It.IsAny<int>(), It.IsAny<int>(), It.IsAny<RiskAssessmentOrderByColumn>(), It.IsAny<OrderByDirection>()), Times.Never()); }