示例#1
0
        public IEnumerable<SiteDto> Search(SearchSitesRequest request)
        {
            var sites = _siteRepository.Search(
                request.CompanyId,
                request.NameStartsWith,
                request.AllowedSiteIds,
                request.PageLimit);

            return new SiteDtoMapper().Map(sites.Cast<Site>());
        }
        public void When_GetViewModel_Then_Calls_SiteService_Take()
        {
            // Given
            var target = new EmployeeSearchViewModelFactory(
                _employeeService.Object,
                _siteService.Object,
                _lookupService.Object);
            const int companyId = 100;
            var searchSitesRequest = new SearchSitesRequest()
                                         {
                                             CompanyId = companyId,

                                         };

            // When
            target.WithCompanyId(companyId).w.GetViewModel();

            // Then
            _siteService.Verify(x => x.Search(searchSitesRequest));
        }
        public void Given_DocumentUploaded_When_the_User_has_a_subset_of_all_sites_as_their_AllowedSites_Then_ViewModel_only_has_those_allowed_sites()
        {
            // Given
            var passedSearchSitesRequest = new SearchSitesRequest();
            _siteService
                .Setup(x => x.Search(It.IsAny<SearchSitesRequest>()))
                .Callback<SearchSitesRequest>(y => passedSearchSitesRequest = y)
                .Returns(new List<SiteDto>());

            // When
            var result = _target.DocumentUploaded(
                It.IsAny<long>(),
                It.IsAny<string>(),
                It.IsAny<int>(),
                It.IsAny<int>(),
                It.IsAny<bool>(),
                AttachDocumentReturnView.AddedDocuments);
            var viewModel = result.Model as NewlyAddedDocumentGridRowViewModel;

            // Then
            Assert.That(passedSearchSitesRequest.CompanyId, Is.EqualTo(TestControllerHelpers.CompanyIdAssigned));
            Assert.That(passedSearchSitesRequest.PageLimit, Is.EqualTo(100));
            Assert.That(passedSearchSitesRequest.AllowedSiteIds, Is.EqualTo(_allowedSites));
        }
示例#4
0
        public void Given_get_Then_viewmodel_should_return_sites_collection_dropdown()
        {
            // Given
            var docHandler = new Mock<IDocHandlerDocumentTypeService>();
            var clientDocumentService = new Mock<IClientDocumentService>();
            var siteService = new Mock<ISiteService>();
            var sites = new List<SiteDto>()
                            {
                                new SiteDto{ Id = 1, Name = "Test"}
                            };

            docHandler.Setup(x => x.GetForDocumentGroup(DocHandlerDocumentTypeGroup.BusinessSafeSystem)).Returns(new DocHandlerDocumentTypeDto[0]);
            var passedSearchSitesRequest = new SearchSitesRequest();
            siteService
                .Setup(x => x.Search(It.IsAny<SearchSitesRequest>()))
                .Callback<SearchSitesRequest>(y => passedSearchSitesRequest = y)
                .Returns(sites);
            clientDocumentService.Setup(x => x.Search(It.IsAny<SearchClientDocumentsRequest>())).Returns(new ClientDocumentDto[0]);

            var factory = new DocumentLibraryViewModelFactory(clientDocumentService.Object, docHandler.Object, null, null, siteService.Object, _cacheHelper);
            var controller = CreateControllerWithUserAndFactory(factory);

            // When
            var result = controller.Index(_companyId, _documentTypeId, _title) as ViewResult;
            var model = result.Model as BusinessSafeSystemDocumentsLibraryViewModel;

            // Then
            siteService.Verify(x => x.Search(It.IsAny<SearchSitesRequest>()), Times.Once());
            Assert.That(model.Sites, Is.Not.Null);
            Assert.That(passedSearchSitesRequest.CompanyId, Is.EqualTo(_companyId));
            Assert.That(passedSearchSitesRequest.AllowedSiteIds, Is.EqualTo(_allowedSites));
        }
        public void Given_search_with_parameters_When_GetViewModel_return_only_allowed_sites_in_viewModel()
        {
            //Given
            const long categoryId = 123L;
            const long siteId = 1L;
            const long siteGroupId = 157473L;
            const bool deleted = true;
            var from = DateTime.Now.AddDays(-124);
            var to = DateTime.Now.AddDays(-3231);
            const string title = "title";
            IList<long> allowedSites = new List<long>() { siteId };
            var target = CreateTarget();

            var site1 = new SiteDto() { Id = siteId };
            
            _siteService
                .Setup(x => x.Search(It.IsAny<SearchSitesRequest>()))
                .Returns(new List<SiteDto>() { site1 });

            var searchSitesRequest = new SearchSitesRequest();
            _siteService
                .Setup(x => x.Search(It.IsAny<SearchSitesRequest>()))
                    .Returns(new List<SiteDto>() { site1 })
                        .Callback<SearchSitesRequest>(y => searchSitesRequest = y);

            //When
            var result = target
                .WithCategoryId(categoryId)
                .WithCreatedFrom(from)
                .WithCreatedTo(to)
                .WithTitle(title)
                .WithSiteId(siteId)
                .WithSiteGroupId(siteGroupId)
                .WithShowDeleted(deleted)
                .WithAllowedSiteIds(allowedSites)
                .GetViewModel();

            //Then
            Assert.That(result.CategoryId, Is.EqualTo(categoryId));
            Assert.That(result.SiteId, Is.EqualTo(siteId));
            Assert.That(result.SiteGroupId, Is.EqualTo(siteGroupId));
            Assert.That(result.IsShowDeleted, Is.EqualTo(deleted));
            Assert.That(DateTime.Parse(result.CreatedFrom), Is.EqualTo(from.Date));
            Assert.That(DateTime.Parse(result.CreatedTo), Is.EqualTo(to.Date));
            Assert.That(result.Title, Is.EqualTo(title));
            Assert.That(result.Sites.Count(), Is.EqualTo(2)); //One for autocomplete
            Assert.That(result.Sites.Last().value, Is.EqualTo(siteId.ToString()));
            Assert.That(searchSitesRequest.AllowedSiteIds.Count, Is.EqualTo(allowedSites.Count));
        }
示例#6
0
        public void When_GetViewModel_Then_populate_viewmodel_from_allowed_sites()
        {
            // Given
            var employeeService = new Mock<IEmployeeService>();
            employeeService.Setup(x => x.Search(It.IsAny<SearchEmployeesRequest>())).Returns(new List<EmployeeDto>());

            var passedSearchSitesRequest = new SearchSitesRequest();
            var siteService = new Mock<ISiteService>();
            siteService
                .Setup(x => x.Search(It.IsAny<SearchSitesRequest>()))
                .Callback<SearchSitesRequest>(y => passedSearchSitesRequest = y)
                .Returns(new List<SiteDto>());

            var lookupService = new Mock<ILookupService>();
            lookupService.Setup(x => x.GetEmploymentStatuses()).Returns(new List<LookupDto>());

            var sessionManager = new Mock<IBusinessSafeSessionManager>();
            var session = new Mock<ISession>();
            sessionManager.SetupGet(x => x.Session).Returns(session.Object);

            var controller = CreateEmployeeSearchControllerWithUserAndFactory(new EmployeeSearchViewModelFactory(employeeService.Object, siteService.Object, lookupService.Object, sessionManager.Object));

            const string employeeReference = "Reference";
            const string forename = "Forname";
            const string surname = "Surname";
            const int siteId = 1;

            // When
            controller.Index(_companyId, employeeReference, forename, surname, siteId);

            // Then
            siteService.Verify(x => x.Search(It.IsAny<SearchSitesRequest>()));
            Assert.That(passedSearchSitesRequest.CompanyId, Is.EqualTo(_companyId));
            Assert.That(passedSearchSitesRequest.PageLimit, Is.EqualTo(100));
            Assert.That(passedSearchSitesRequest.AllowedSiteIds, Is.EqualTo(_allowedSites));
        }
 private IEnumerable<LookupDto> GetRequestedSites()
 {
     var request = new SearchSitesRequest
                       {
                           CompanyId = _companyId,
                           AllowedSiteIds = _siteIds
                       };
     var result = _siteService.Search(request);
     return result.Select(x => new LookupDto
                                   {
                                       Id = x.Id,
                                       Name = x.Name
                                   }).ToList();
 } 
        public void Given_search_for_current_user_with_allowed_site_ids_When_GetViewModel_is_called_Then_returns_model()
        {
            //Given
            var target = CreateTarget();

            var responsibility = new ResponsibilityDto
            {
                Id = 1L,
                ResponsibilityTasks = new List<ResponsibilityTaskDto>
                                                                   {
                                                                       new ResponsibilityTaskDto
                                                                           {
                                                                               Id = 1L,
                                                                               Description = "my description",
                                                                               TaskAssignedTo = new EmployeeDto{FullName = "Test"},
                                                                               CreatedDate = DateTime.Now.ToShortDateString(),
                                                                               TaskCompletionDueDate = DateTime.Now.ToShortDateString(),
                                                                               TaskStatusString = string.Empty,
                                                                               Site = new SiteDto{Id = 1L}
                                                                           }
                                                                   }
            };

            var reasons = new List<ResponsibilityReasonDto>
                                 {
                                     new ResponsibilityReasonDto {Id = default(long)}
                                 };

            var categories = new List<ResponsibilityCategoryDto>
                                 {
                                     new ResponsibilityCategoryDto {Id = default(long)}
                                 };

            var employess = new List<EmployeeDto>
                                {
                                    new EmployeeDto{Id = new Guid()}
                                };
            var site1 = new SiteDto() { Id = 1L };
            var site2 = new SiteDto() { Id = 2L };
            var site3 = new SiteDto() { Id = 3L };

            var allowedSites = new List<long>() { 1L, 2L };

            var sites = new List<SiteDto>
                            {
                                site1, site2, site3
                            };

            _responsibilitiesService
                .Setup(x => x.GetResponsibility(It.IsAny<long>(), _companyId))
                .Returns(() => responsibility);

            _responsibilitiesService
                .Setup(x => x.GetResponsibilityReasons())
                .Returns(() => reasons);

            _responsibilitiesService
                .Setup(x => x.GetResponsibilityCategories())
                .Returns(() => categories);

            _employeeService
                .Setup(x => x.Search(It.IsAny<SearchEmployeesRequest>()))
                .Returns(() => employess);

            _employeeService
               .Setup(x => x.GetEmployeeNames(It.IsAny<long>()))
               .Returns(() => employess.Select(x => new EmployeeName() { Id = x.Id }).ToList());

            var searchSitesRequest = new SearchSitesRequest();
            _siteService
                .Setup(x => x.Search(It.IsAny<SearchSitesRequest>())).Returns(sites).Callback<SearchSitesRequest>(y => searchSitesRequest = y);

            //When
            var result = target.WithCompanyId(_companyId)
                .WithResponsibilityId(_responsibilityId)
                .WithAllowedSiteIds(allowedSites)
                .GetViewModel();

            //Then
            Assert.That(searchSitesRequest.AllowedSiteIds.Count, Is.EqualTo(allowedSites.Count));

        }