Пример #1
0
        public ViewResult Index(AccidentRecordsIndexViewModel model)
        {
            
            _searchAccidentRecordViewModelFactory
                .WithCompanyId(CurrentUser.CompanyId)
                .WithTitle(model.Title)
                .WithShowDeleted(model.IsShowDeleted)
                .WithPageNumber(model.Page)
                .WithAllowedSites(CurrentUser.GetSitesFilter())
                .WithPageSize(model.Size)
                .WithOrderBy(model.OrderBy);
            
            if (model.SiteId.HasValue)
                _searchAccidentRecordViewModelFactory.WithSiteId(model.SiteId.Value);
           
            if (!string.IsNullOrEmpty(model.CreatedFrom))
                _searchAccidentRecordViewModelFactory.WithCreatedFrom(DateTime.Parse(model.CreatedFrom));

            if (!string.IsNullOrEmpty(model.CreatedTo))
                _searchAccidentRecordViewModelFactory.WithCreatedTo(DateTime.Parse(model.CreatedTo));

            if (!string.IsNullOrEmpty(model.InjuredPersonForename))
                _searchAccidentRecordViewModelFactory.WithInjuredPersonForename(model.InjuredPersonForename);

            if (!string.IsNullOrEmpty(model.InjuredPersonSurname))
                _searchAccidentRecordViewModelFactory.WithInjuredPersonSurname(model.InjuredPersonSurname);

            model = _searchAccidentRecordViewModelFactory               
                                    .GetViewModel();

            return View("Index", model);
        }  
        public void Given_accident_records_search_criteria_when_print_then_correct_search_request_generated()
        {
            //GIVEN
            var searchCriteria = new AccidentRecordsIndexViewModel() { SiteId = 145145L, CreatedFrom = "14/04/2013", CreatedTo = "15/04/2014"};
            var accidentRecordDtos = new List<AccidentRecordDto>() { new AccidentRecordDto() { Id = 12312 }, new AccidentRecordDto() { Id = 12312 } };

            SearchAccidentRecordsRequest searchRequest = null;

            _accidentRecordService.Setup(x => x.Search(It.IsAny<SearchAccidentRecordsRequest>()))
                .Callback<SearchAccidentRecordsRequest>((p1)=> searchRequest = p1)
               .Returns(() => accidentRecordDtos);


            var target = GetTarget();

            //WHEN
            target.Pdf(searchCriteria);

            //THEN
            Assert.That(searchRequest.CompanyId, Is.EqualTo(target.CurrentUser.CompanyId));
            Assert.That(searchRequest.SiteId, Is.EqualTo(searchCriteria.SiteId));
            Assert.That(searchRequest.CreatedFrom, Is.EqualTo(DateTime.Parse(searchCriteria.CreatedFrom)));
            Assert.That(searchRequest.CreatedTo, Is.EqualTo(DateTime.Parse(searchCriteria.CreatedTo)));
            Assert.That(searchRequest.AllowedSiteIds, Is.EqualTo(target.CurrentUser.GetSitesFilter()));

        }
        public void Given_accident_records_search_criteria_when_print_then_file_is_generated_and_returned()
        {
            //GIVEN
            var searchCriteria = new AccidentRecordsIndexViewModel() {SiteId = 145145L};
            var accidentRecordDtos = new List<AccidentRecordDto>() {new AccidentRecordDto() {Id = 4}, new AccidentRecordDto() {Id = 5}};

            _accidentRecordService.Setup(x => x.Search(It.IsAny<SearchAccidentRecordsRequest>()))
                .Returns(() => accidentRecordDtos);
            
            object[] reportParameters = null;

            _sqlReportFacade
                .Setup(x => x.GetReport(It.IsAny<SqlReportHelper.ReportType>(), It.IsAny<object[]>(), It.IsAny<SqlReportHelper.ReportFormatType>()))
                .Callback<SqlReportHelper.ReportType, object[], SqlReportHelper.ReportFormatType>((p1, p2, p3) => reportParameters = p2)
                .Returns(() => _documentViewModel);

            var target = GetTarget();

            //WHEN
            target.Pdf(searchCriteria);

            //THEN
            _sqlReportFacade.Verify(x => x.GetReport(SqlReportHelper.ReportType.AccidentRecords, It.IsAny<object[]>(), SqlReportHelper.ReportFormatType.PDF));
            Assert.That(reportParameters.Length, Is.EqualTo(1));
            Assert.That(((string)reportParameters[0]), Is.EqualTo("4,5"));
        }
Пример #4
0
        public void Given_get_When_Index_Then_Returns_View()
        {
            // Given
            var target = GetTarget();

            // When
            AccidentRecordsIndexViewModel model = new AccidentRecordsIndexViewModel() { Title = "some test title" };

            var result = target.Index(model);

            // Then
            Assert.IsInstanceOf<ViewResult>(result);
        }
 public FileResult Pdf(AccidentRecordsIndexViewModel viewModel)
 {
    
     long[] accidentRecords = _factory
                                 .WithCompanyId(CurrentUser.CompanyId)
                                 .WithShowDeleted(viewModel.IsShowDeleted)
                                 .WithSiteId(viewModel.SiteId)
                                 .WithStartDate(string.IsNullOrEmpty(viewModel.CreatedFrom)
                                                    ? (DateTime?) null
                                                    : DateTime.Parse(viewModel.CreatedFrom))
                                 .WithEndDate(string.IsNullOrEmpty(viewModel.CreatedTo)
                                                  ? (DateTime?) null
                                                  : DateTime.Parse(viewModel.CreatedTo))
                                 .WithAllowedSiteIds(CurrentUser.GetSitesFilter().ToList())
                                 .GetAccidentRecords();
     
     return CreateFile( accidentRecords );
 }
        public ViewModels.AccidentRecordsIndexViewModel GetViewModel()
        {
            var request = new SearchAccidentRecordsRequest()
                              {
                                  CompanyId = _companyId,
                                  ShowDeleted = _showDeleted,
                                  SiteId = _siteId,
                                  Title = _title,
                                  CreatedFrom =
                                      string.IsNullOrEmpty(_createdFrom)
                                          ? (DateTime?) null
                                          : DateTime.Parse(_createdFrom),
                                  CreatedTo = string.IsNullOrEmpty(_createdTo) ? (DateTime?) null : DateTime.Parse(_createdTo),
                                  InjuredPersonForename = _injuredPersonForename,
                                  InjuredPersonSurname = _injuredPersonSurname,
                                  Page = _page != default(int) ? _page : 1,
                                  PageSize = _pageSize != default(int) ? _pageSize : DEFAULT_PAGE_SIZE,
                                  OrderBy = GetOrderBy(),
                                  Ascending = Ascending(),
                                  AllowedSiteIds = _sites
                              };

            var count = _accidentRecordsService.Count(request);
            var DTOs = _accidentRecordsService.Search(request);

            var viewModel = new AccidentRecordsIndexViewModel()
            {
                CreatedFrom = _createdFrom,
                CreatedTo = _createdTo,
                IsShowDeleted = _showDeleted,
                SiteId = _siteId,
                Title = _title,
                
                InjuredPersonForename = _injuredPersonForename,
                InjuredPersonSurname = _injuredPersonSurname,
                Size = _pageSize != default(int) ? _pageSize : DEFAULT_PAGE_SIZE,
                Total = count
            };

            
            viewModel.AccidentRecords  = DTOs.Select( x => new SearchAccidentRecordResultViewModel()
                                                        {
                                                            Id              = x.Id,
                                                            Reference       = x.Reference,
                                                            Title           = x.Title,                                                                                                                
                                                            Description     = x.DescriptionHowAccidentHappened != null ? x.DescriptionHowAccidentHappened.TruncateWithEllipsis(50) : null,
                                                            InjuredPerson   = x. InjuredPersonFullName,
                                                            Severity        = x.SeverityOfInjury == null    ? String.Empty : EnumHelper.GetEnumDescription( x.SeverityOfInjury ),
                                                            Site            = GetSiteDisplay(x),
                                                            ReportedBy      = x.CreatedBy == null           ? String.Empty : x.CreatedBy.Name,
                                                            DateCreated     = x.CreatedOn == null           ? String.Empty : x.CreatedOn.Value.ToShortDateString(),
                                                            DateOfAccident  = x.DateAndTimeOfAccident == null ? String.Empty : x.DateAndTimeOfAccident.Value.ToShortDateString(),
                                                            IsDeleted       = x.IsDeleted,
                                                            Status          = x.Status ? AccidentRecordStatusEnum.Open : AccidentRecordStatusEnum.Closed
                                                        }

                                                    ).ToList();

            var sites = _siteService.Search(new SearchSitesRequest
            {
                CompanyId = _companyId,
                AllowedSiteIds = _sites
            });

            viewModel.Sites = sites.Select(AutoCompleteViewModel.ForSite)
                                    .AddDefaultOption(String.Empty)
                                    .WithOtherOption( new AutoCompleteViewModel("Off-site", "-1") )
                                    .ToList();
        
            return viewModel;
        }