public async Task EstabSearch_PrepareDownload_Step3() { var ers = new Mock <IEstablishmentReadService>(MockBehavior.Strict); var eds = new Mock <IEstablishmentDownloadService>(MockBehavior.Strict); var cls = new Mock <ICachedLookupService>(MockBehavior.Loose); var request = new Mock <HttpRequestBase>(MockBehavior.Strict); var context = new Mock <HttpContextBase>(MockBehavior.Strict); var mockUrlHelper = new Mock <UrlHelper>(); var principal = new Mock <IPrincipal>(); var guid = Guid.NewGuid(); mockUrlHelper.Setup(x => x.RouteUrl(It.IsAny <RouteValueDictionary>())).Returns <RouteValueDictionary>(n => n.Select(s => string.Format("{0}={1}", s.Key, s.Value)).Aggregate((c, nx) => string.Format("{0}|{1}", c, nx))); request.SetupGet(x => x.QueryString).Returns(HttpUtility.ParseQueryString(string.Empty)); context.SetupGet(x => x.Request).Returns(request.Object); context.SetupGet(x => x.User).Returns(principal.Object); principal.Setup(x => x.IsInRole(It.IsAny <string>())).Returns(true); eds.Setup(x => x.SearchWithDownloadGenerationAsync(It.IsAny <EstablishmentSearchDownloadPayload>(), It.IsAny <IPrincipal>())).ReturnsAsync(guid); var subject = new EstablishmentsSearchController(ers.Object, eds.Object, cls.Object); subject.ControllerContext = new ControllerContext(context.Object, new RouteData(), subject); subject.Url = mockUrlHelper.Object; var viewModel = new EstablishmentSearchDownloadViewModel() { Dataset = eDataSet.Full, FileFormat = Edubase.Services.Enums.eFileFormat.XLSX }; var result = (RedirectToRouteResult)await subject.PrepareDownload(viewModel); Assert.That(result.RouteValues["action"], Is.EqualTo("Download")); Assert.That(result.RouteValues["id"], Is.EqualTo(guid)); }
public async Task EstabSearch_PrepareDownload_Step2() { var ers = new Mock <IEstablishmentReadService>(MockBehavior.Strict); var eds = new Mock <IEstablishmentDownloadService>(MockBehavior.Strict); var cls = new Mock <ICachedLookupService>(MockBehavior.Loose); var request = new Mock <HttpRequestBase>(MockBehavior.Strict); var context = new Mock <HttpContextBase>(MockBehavior.Strict); var mockUrlHelper = new Mock <UrlHelper>(); var principal = new Mock <IPrincipal>(); mockUrlHelper.Setup(x => x.RouteUrl(It.IsAny <RouteValueDictionary>())).Returns <RouteValueDictionary>(n => n.Select(s => string.Format("{0}={1}", s.Key, s.Value)).Aggregate((c, nx) => string.Format("{0}|{1}", c, nx))); request.SetupGet(x => x.QueryString).Returns(HttpUtility.ParseQueryString(string.Empty)); context.SetupGet(x => x.Request).Returns(request.Object); context.SetupGet(x => x.User).Returns(principal.Object); principal.Setup(x => x.IsInRole(It.IsAny <string>())).Returns(true); var subject = new EstablishmentsSearchController(ers.Object, eds.Object, cls.Object); subject.ControllerContext = new ControllerContext(context.Object, new RouteData(), subject); subject.Url = mockUrlHelper.Object; var viewModel = new EstablishmentSearchDownloadViewModel() { Dataset = eDataSet.Full }; var result = (ViewResult)await subject.PrepareDownload(viewModel); Assert.That(viewModel.AllowAnyExtraFields, Is.True); Assert.That(viewModel.AllowIncludeBringUpFields, Is.True); Assert.That(viewModel.AllowIncludeChildrensCentreFields, Is.True); Assert.That(viewModel.AllowIncludeEmailAddresses, Is.True); Assert.That(viewModel.AllowIncludeIEBTFields, Is.True); Assert.That(result.ViewName, Is.EqualTo("Downloads/SelectFormat")); }
public async Task <ActionResult> PrepareDownload(EstablishmentSearchDownloadViewModel viewModel) { viewModel.SearchSource = eLookupSearchSource.Establishments; viewModel.AllowIncludeEmailAddresses = User.InRole(R.EDUBASE, R.EDUBASE_CMT, R.APT, R.AP_AOS, R.EFADO, R.FST, R.IEBT, R.ISI, R.OFSTED, R.SOU, R.EDUBASE_CHILDRENS_CENTRE_POLICY, R.EDUBASE_LACCDO, R.EFAHNS, R.edubase_ddce, R.SFC, R.DUGE); viewModel.AllowIncludeIEBTFields = User.InRole(R.EDUBASE, R.EDUBASE_CMT, R.IEBT, R.ISI, R.OFSTED); viewModel.AllowIncludeBringUpFields = User.InRole(R.IEBT); viewModel.AllowIncludeChildrensCentreFields = User.InRole(R.EDUBASE, R.EDUBASE_CMT, R.EDUBASE_CHILDRENS_CENTRE_POLICY, R.EDUBASE_LACCDO); if (!viewModel.Dataset.HasValue) { viewModel.SearchQueryString = Request.QueryString.ToString(); return(View("Downloads/SelectDataset", viewModel)); } if (!viewModel.FileFormat.HasValue) { return(View("Downloads/SelectFormat", viewModel)); } var progressId = await _establishmentDownloadService.SearchWithDownloadGenerationAsync( new EstablishmentSearchDownloadPayload { SearchPayload = (await GetEstablishmentSearchPayload(viewModel)).Object, DataSet = viewModel.Dataset.Value, FileFormat = viewModel.FileFormat.Value, IncludeBringUpFields = viewModel.IncludeBringUpFields, IncludeChildrensCentreFields = viewModel.IncludeChildrensCentreFields, IncludeEmailAddresses = viewModel.IncludeEmailAddresses, IncludeIEBTFields = viewModel.IncludeIEBTFields, IncludeLinks = viewModel.IncludeLinks }, User); return(RedirectToAction(nameof(Download), new { id = progressId, fileFormat = viewModel.FileFormat.Value, viewModel.SearchQueryString, viewModel.SearchSource })); }
public async Task <ActionResult> PrepareDownload(EstablishmentSearchDownloadViewModel viewModel) { viewModel.SearchSource = eLookupSearchSource.Establishments; viewModel.AllowIncludeEmailAddresses = User.InRole(R.EDUBASE, R.EDUBASE_CMT, R.APT, R.AP_AOS, R.EFADO, R.FST, R.IEBT, R.ISI, R.OFSTED, R.SOU, R.EDUBASE_CHILDRENS_CENTRE_POLICY, R.EDUBASE_LACCDO, R.EFAHNS, R.edubase_ddce, R.SFC, R.DUGE); viewModel.AllowIncludeIEBTFields = User.InRole(R.EDUBASE, R.EDUBASE_CMT, R.IEBT, R.ISI, R.OFSTED); viewModel.AllowIncludeBringUpFields = User.InRole(R.IEBT); viewModel.AllowIncludeChildrensCentreFields = User.InRole(R.EDUBASE, R.EDUBASE_CMT, R.EDUBASE_CHILDRENS_CENTRE_POLICY, R.EDUBASE_LACCDO); if (!viewModel.Dataset.HasValue) { viewModel.SearchQueryString = Request.QueryString.ToString(); return(View("Downloads/SelectDataset", viewModel)); } if (viewModel.Dataset == eDataSet.Custom && !viewModel.SelectedCustomFields.Any()) { if (viewModel.ViewedCustomFields) { ModelState.AddModelError("CustomFieldsByCategory", "Select at least one field"); } // the SearchQueryString is used for the breadcrumb response. We dont want to retain the Dataset selection as part of that var queryString = new NameValueCollection(Request.QueryString); queryString.Remove("Dataset"); viewModel.SearchQueryString = queryString.ToQueryString(); viewModel.CustomFields = (await _establishmentDownloadService.GetSearchDownloadCustomFields(User)) .OrderBy(x => x.Name).ToList(); return(View("Downloads/SelectCustomFields", viewModel)); } if (!viewModel.FileFormat.HasValue) { return(View("Downloads/SelectFormat", viewModel)); } var progressId = await _establishmentDownloadService.SearchWithDownloadGenerationAsync( new EstablishmentSearchDownloadPayload { SearchPayload = (await GetEstablishmentSearchPayload(viewModel)).Object, DataSet = viewModel.Dataset.Value, FileFormat = viewModel.FileFormat.Value, IncludeBringUpFields = viewModel.IncludeBringUpFields, IncludeChildrensCentreFields = viewModel.IncludeChildrensCentreFields, IncludeEmailAddresses = viewModel.IncludeEmailAddresses, IncludeIEBTFields = viewModel.IncludeIEBTFields, IncludeLinks = viewModel.IncludeLinks, SelectedFields = viewModel.SelectedCustomFields.ToArray() }, User); return(RedirectToAction(nameof(Download), new { id = progressId, fileFormat = viewModel.FileFormat.Value, viewModel.SearchQueryString, viewModel.SearchSource })); }