Пример #1
0
        public async System.Threading.Tasks.Task UpdateActionCallsCookieManagerWhenComparisonListClearedAsync()
        {
            var request  = new Mock <HttpRequestBase>(MockBehavior.Strict);
            var response = new Mock <HttpResponseBase>(MockBehavior.Strict);
            var context  = new Mock <HttpContextBase>(MockBehavior.Strict);

            context.SetupGet(x => x.Request).Returns(request.Object);
            context.SetupGet(x => x.Response).Returns(response.Object);
            var requestCookies = new HttpCookieCollection();
            var listCookie     = new SchoolComparisonListModel();

            listCookie.BenchmarkSchools = new List <BenchmarkSchoolModel>()
            {
                new BenchmarkSchoolModel()
                {
                    Urn = "123", Name = "test"
                }
            };
            requestCookies.Add(new HttpCookie(CookieNames.COMPARISON_LIST, JsonConvert.SerializeObject(listCookie)));
            context.SetupGet(x => x.Request.Cookies).Returns(requestCookies);
            var responseCookies = new HttpCookieCollection();

            context.SetupGet(x => x.Response.Cookies).Returns(responseCookies);
            var rc = new RequestContext(context.Object, new RouteData());

            dynamic apiResponse = new System.Dynamic.ExpandoObject();

            apiResponse.Results         = new object[0];
            apiResponse.NumberOfResults = 0;
            apiResponse.Facets          = string.Empty;

            var     mockEdubaseDataService = new Mock <IContextDataService>();
            dynamic serviceResponse        = new System.Dynamic.ExpandoObject();

            serviceResponse.Results         = new object[0];
            serviceResponse.NumberOfResults = 0;
            serviceResponse.Facets          = string.Empty;

            var mockFinancialDataService = new Mock <IFinancialDataService>();

            var mockCookieManager        = new Mock <ISchoolBenchmarkListService>();
            var fakeSchoolComparisonList = new SchoolComparisonListModel();

            fakeSchoolComparisonList.HomeSchoolUrn           = "123";
            fakeSchoolComparisonList.HomeSchoolName          = "test";
            fakeSchoolComparisonList.HomeSchoolType          = "test";
            fakeSchoolComparisonList.HomeSchoolFinancialType = "Academies";
            fakeSchoolComparisonList.BenchmarkSchools.Add(new BenchmarkSchoolModel {
                Urn = "123", EstabType = "Academies"
            });
            mockCookieManager.Setup(m => m.GetSchoolBenchmarkList()).Returns(fakeSchoolComparisonList);

            var controller = new BenchmarkListController(mockEdubaseDataService.Object, mockCookieManager.Object, mockFinancialDataService.Object);

            controller.ControllerContext = new ControllerContext(rc, controller);

            var result = await controller.UpdateBenchmarkBasket(null, CookieActions.RemoveAll);

            mockCookieManager.Verify(m => m.ClearSchoolBenchmarkList(), Times.Once);
        }
        public void SetupContext()
        {
            var request  = new Mock <HttpRequestBase>(MockBehavior.Strict);
            var response = new Mock <HttpResponseBase>(MockBehavior.Strict);
            var context  = new Mock <HttpContextBase>(MockBehavior.Strict);

            context.SetupGet(x => x.Request).Returns(request.Object);
            context.SetupGet(x => x.Response).Returns(response.Object);
            var requestCookies = new HttpCookieCollection();
            var listCookie     = new SchoolComparisonListModel();

            listCookie.HomeSchoolUrn           = "123";
            listCookie.HomeSchoolName          = "test";
            listCookie.HomeSchoolType          = "test";
            listCookie.HomeSchoolFinancialType = "Academies";
            listCookie.BenchmarkSchools        = new List <BenchmarkSchoolModel>()
            {
                new BenchmarkSchoolModel()
                {
                    Urn = "123", Name = "test", EstabType = "Academies"
                }
            };
            requestCookies.Add(new HttpCookie(CookieNames.COMPARISON_LIST, JsonConvert.SerializeObject(listCookie)));
            context.SetupGet(x => x.Request.Cookies).Returns(requestCookies);
            var responseCookies = new HttpCookieCollection();

            context.SetupGet(x => x.Response.Cookies).Returns(responseCookies);
            _rc = new RequestContext(context.Object, new RouteData());
        }
Пример #3
0
        private void BuildOtherSchoolsLines(SchoolComparisonListModel comparisonList, List <ChartViewModel> benchmarkCharts, StringBuilder csv)
        {
            var otherSchools = comparisonList.BenchmarkSchools.Where(b => b.Urn != comparisonList.HomeSchoolUrn);

            foreach (var school in otherSchools)
            {
                var valuesLine    = new StringBuilder();
                var data          = benchmarkCharts.First().BenchmarkData.Find(d => d.Urn == school.Urn);
                var term          = benchmarkCharts.First().BenchmarkData.Find(d => d.Urn == school.Urn).Term;
                var formattedTerm = FormatTerm(term, (EstablishmentType)Enum.Parse(typeof(EstablishmentType), school.EstabType));
                valuesLine.Append($"\"{school.Name}\",{data.Urn},{formattedTerm},{data.PupilCount},{data.TeacherCount},");

                foreach (var chart in benchmarkCharts.Where(bc => bc.Downloadable))
                {
                    var amount = chart.BenchmarkData.Find(d => d.Urn == school.Urn).Amount;
                    valuesLine.Append(amount == null ? "N/A" : amount.ToString());
                    valuesLine.Append(",");
                    if (chart.TableColumns != null)
                    {
                        foreach (var col in chart.TableColumns)
                        {
                            var colAmount = col.BenchmarkData.Find(d => d.Urn == school.Urn).Amount;
                            valuesLine.Append(colAmount == null ? "N/A" : colAmount.ToString());
                            valuesLine.Append(",");
                        }
                    }
                }

                csv.AppendLine(valuesLine.ToString().TrimEnd(','));
            }
        }
Пример #4
0
        private void BuildHomeSchoolLine(SchoolComparisonListModel comparisonList, List <ChartViewModel> benchmarkCharts, StringBuilder csv)
        {
            if (!string.IsNullOrEmpty(comparisonList.HomeSchoolUrn) && comparisonList.BenchmarkSchools.Any(s => s.Urn == comparisonList.HomeSchoolUrn))
            {
                var valuesLine = new StringBuilder();
                var data       = benchmarkCharts.First().BenchmarkData.Find(d => d.Urn == comparisonList.HomeSchoolUrn);
                var term       = data.Term;

                var formattedTerm = FormatTerm(term, (EstablishmentType)Enum.Parse(typeof(EstablishmentType), comparisonList.HomeSchoolFinancialType));
                valuesLine.Append($"Your school,{data.Urn},{formattedTerm},{data.PupilCount},{data.TeacherCount},");

                foreach (var chart in benchmarkCharts.Where(bc => bc.Downloadable))
                {
                    var amount = chart.BenchmarkData.Find(d => d.Urn == comparisonList.HomeSchoolUrn).Amount;
                    valuesLine.Append(amount == null ? "N/A" : amount.ToString());
                    valuesLine.Append(",");
                    if (chart.TableColumns != null)
                    {
                        foreach (var col in chart.TableColumns)
                        {
                            var colAmount = col.BenchmarkData.Find(d => d.Urn == comparisonList.HomeSchoolUrn).Amount;
                            valuesLine.Append(colAmount == null ? "N/A" : colAmount.ToString());
                            valuesLine.Append(",");
                        }
                    }
                }

                csv.AppendLine(valuesLine.ToString().TrimEnd(','));
            }
        }
        public async Task AskForOverwriteStrategyIfMultipleSchoolsInComparisonListAsync()
        {
            var mockCookieManager        = new Mock <ISchoolBenchmarkListService>();
            var fakeSchoolComparisonList = new SchoolComparisonListModel();

            fakeSchoolComparisonList.BenchmarkSchools.Add(new BenchmarkSchoolModel()
            {
                Name = "test"
            });
            fakeSchoolComparisonList.BenchmarkSchools.Add(new BenchmarkSchoolModel()
            {
                Name = "test"
            });
            mockCookieManager.Setup(m => m.GetSchoolBenchmarkList()).Returns(fakeSchoolComparisonList);

            var mockComparisonService = new Mock <IComparisonService>();

            var controller = new BenchmarkCriteriaController(null, null, null, null, mockCookieManager.Object, mockComparisonService.Object, new ValidationService());

            var response = await controller.OverwriteStrategy(10000, ComparisonType.Advanced, EstablishmentType.Maintained, new BenchmarkCriteriaVM(new BenchmarkCriteria()
            {
                Gender = new[] { "Boys" }
            }), ComparisonArea.All, 306, "test", 10);

            Assert.IsNotNull(response);
            Assert.IsNotNull((response as ViewResult).Model);
            Assert.AreEqual("", (response as ViewResult).ViewName);
        }
Пример #6
0
        public string BuildCSVContentForSchools(SchoolComparisonListModel comparisonList, List <ChartViewModel> benchmarkCharts)
        {
            var csv = new StringBuilder();

            BuildHeaderLine(benchmarkCharts, csv, EstablishmentType.Maintained);

            BuildHomeSchoolLine(comparisonList, benchmarkCharts, csv);

            BuildOtherSchoolsLines(comparisonList, benchmarkCharts, csv);

            return(csv.ToString());
        }
Пример #7
0
        public SchoolComparisonListModel ExtractManualComparisonListFromCookie()
        {
            SchoolComparisonListModel comparisonList = new SchoolComparisonListModel();
            var cookie = HttpContext.Current.Request.Cookies[CookieNames.COMPARISON_LIST_MANUAL];

            if (cookie != null)
            {
                comparisonList = JsonConvert.DeserializeObject <SchoolComparisonListModel>(cookie.Value, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
            }
            return(comparisonList);
        }
Пример #8
0
        private HttpCookie AddSchoolToCookie(BenchmarkSchoolModel benchmarkSchool, string cookieName)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];

            if (cookie == null)
            {
                cookie = new HttpCookie(cookieName);
                var listCookie = new SchoolComparisonListModel();
                listCookie.BenchmarkSchools = new List <BenchmarkSchoolModel>()
                {
                    benchmarkSchool
                };
                cookie.Value = JsonConvert.SerializeObject(listCookie, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
            }
            else
            {
                var listCookie = JsonConvert.DeserializeObject <SchoolComparisonListModel>(cookie.Value, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
                if (listCookie.BenchmarkSchools.Any(s => s.Id == benchmarkSchool.Id))
                {
                    throw new ApplicationException(ErrorMessages.DuplicateSchool);
                }
                if (listCookie.BenchmarkSchools.Count < ComparisonListLimit.LIMIT || listCookie.HomeSchoolUrn == benchmarkSchool.Urn)
                {
                    if (listCookie.BenchmarkSchools.Any(s => s.Name == benchmarkSchool.Name))
                    {
                        benchmarkSchool.Name += " ";
                    }

                    listCookie.BenchmarkSchools.Add(benchmarkSchool);
                }
                cookie.Value = JsonConvert.SerializeObject(listCookie, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
            }

            cookie.HttpOnly = false;
            cookie.Secure   = HttpContext.Current.Request.IsSecureConnection;
            return(cookie);
        }
Пример #9
0
        private HttpCookie SetDefaultSchoolInCookie(BenchmarkSchoolModel benchmarkSchool, string cookieName)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];

            if (cookie == null)
            {
                cookie = new HttpCookie(cookieName);
                var listCookie = new SchoolComparisonListModel();
                listCookie.HomeSchoolUrn           = benchmarkSchool.Urn;
                listCookie.HomeSchoolName          = benchmarkSchool.Name;
                listCookie.HomeSchoolType          = benchmarkSchool.Type;
                listCookie.HomeSchoolFinancialType = benchmarkSchool.EstabType;
                listCookie.BenchmarkSchools        = new List <BenchmarkSchoolModel>()
                {
                    benchmarkSchool
                };
                cookie.Value = JsonConvert.SerializeObject(listCookie, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
            }
            else
            {
                var listCookie = JsonConvert.DeserializeObject <SchoolComparisonListModel>(cookie.Value, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
                listCookie.HomeSchoolUrn           = benchmarkSchool.Urn;
                listCookie.HomeSchoolName          = benchmarkSchool.Name;
                listCookie.HomeSchoolType          = benchmarkSchool.Type;
                listCookie.HomeSchoolFinancialType = benchmarkSchool.EstabType;
                if (benchmarkSchool.Urn != null && listCookie.BenchmarkSchools.Count < ComparisonListLimit.LIMIT && listCookie.BenchmarkSchools.All(s => s.Urn != benchmarkSchool.Urn))
                {
                    listCookie.BenchmarkSchools.Add(benchmarkSchool);
                }
                cookie.Value = JsonConvert.SerializeObject(listCookie, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
            }

            cookie.HttpOnly = false;
            cookie.Secure   = HttpContext.Current.Request.IsSecureConnection;
            return(cookie);
        }
Пример #10
0
        private ActionResult ErrorViewForHomePage(string searchType, string errorMessage, SchoolComparisonListModel schoolComparisonList)
        {
            var searchVM = new SearchViewModel(schoolComparisonList, searchType)
            {
                SearchType   = searchType,
                ErrorMessage = errorMessage,
                Authorities  = _laService.GetLocalAuthorities()
            };

            return(View("~/Views/Home/index.cshtml", searchVM));
        }
        private ActionResult ErrorView(string searchType, string referrer, string errorMessage, SchoolComparisonListModel schoolComparisonList)
        {
            var searchVM = new SearchViewModel(schoolComparisonList, searchType)
            {
                SearchType   = searchType,
                ErrorMessage = errorMessage,
                Authorities  = _laService.GetLocalAuthorities()
            };

            return(View("../" + referrer, searchVM));
        }
 public SearchViewModel(SchoolComparisonListModel comparisonList, string queryKey)
 {
     base.ComparisonList = comparisonList;
     this.QueryKey       = queryKey;
 }
 public void SetSchoolAsDefaultInManualBenchmarkList(SchoolComparisonListModel schoolComparisonList)
 {
     UpdateManualComparisonListCookie(CookieActions.SetDefault, new BenchmarkSchoolModel(schoolComparisonList));
 }
        protected SearchedSchoolListViewModel GetSearchedSchoolViewModelList(dynamic response, SchoolComparisonListModel schoolComparisonListModel, string orderBy, int page, string searchType, string nameKeyword, string locationKeyword, string laKeyword)
        {
            var schoolListVm = new List <SchoolSearchResultViewModel>();
            var vm           = new SearchedSchoolListViewModel(schoolListVm, null, searchType, nameKeyword, locationKeyword, laKeyword, orderBy);

            if (response != null)
            {
                foreach (var result in response.Results)
                {
                    var schoolVm = new SchoolSearchResultViewModel(result);
                    schoolListVm.Add(schoolVm);
                }

                vm.SchoolComparisonList = schoolComparisonListModel;

                _filterBuilder.AddSchoolLevelFilters(response.Facets, Request.QueryString);
                _filterBuilder.AddSchoolTypeFilters(response.Facets, Request.QueryString);
                _filterBuilder.AddOfstedRatingFilters(response.Facets, Request.QueryString);
                _filterBuilder.AddReligiousCharacterFilters(response.Facets, Request.QueryString);
                if (Request.QueryString?["searchType"] == SearchTypes.SEARCH_BY_LOCATION && Request.QueryString?["openOnly"] != "true")
                {
                    _filterBuilder.AddStatusFilters(response.Facets, Request.QueryString);
                }
                var filters = _filterBuilder.GetResult();
                vm.Filters = filters;
                vm.FilterSelectionState = DetermineSelectionState(filters);

                vm.Pagination = new Pagination
                {
                    Start             = (SearchDefaults.RESULTS_PER_PAGE * (page - 1)) + 1,
                    Total             = response.NumberOfResults,
                    PageLinksPerPage  = SearchDefaults.LINKS_PER_PAGE,
                    MaxResultsPerPage = SearchDefaults.RESULTS_PER_PAGE,
                    PagedEntityType   = PagedEntityType.School
                };
            }

            return(vm);
        }
        public async Task DoNotAskForOverwriteStrategyIfOnlyBenchmarkSchoolInListAsync()
        {
            var mockCookieManager        = new Mock <ISchoolBenchmarkListService>();
            var fakeSchoolComparisonList = new SchoolComparisonListModel();

            fakeSchoolComparisonList.HomeSchoolUrn  = "100";
            fakeSchoolComparisonList.HomeSchoolName = "home school";
            fakeSchoolComparisonList.BenchmarkSchools.Add(new BenchmarkSchoolModel()
            {
                Name = "test", Urn = "100"
            });

            mockCookieManager.Setup(m => m.GetSchoolBenchmarkList()).Returns(fakeSchoolComparisonList);

            var _mockDocumentDbService = new Mock <IFinancialDataService>();
            var testResult             = new SchoolTrustFinancialDataObject();

            testResult.URN        = 321;
            testResult.SchoolName = "test";
            Task <List <SchoolTrustFinancialDataObject> > task = Task.Run(() =>
            {
                return(new List <SchoolTrustFinancialDataObject> {
                    testResult
                });
            });

            _mockDocumentDbService.Setup(m => m.SearchSchoolsByCriteriaAsync(It.IsAny <BenchmarkCriteria>(), It.IsAny <EstablishmentType>(), false, true))
            .Returns((BenchmarkCriteria criteria, EstablishmentType estType, bool excludePartial, bool excludeFeds) => task);

            Task <int> GetLatestFinancialDataYearPerEstabTypeAsyncTask = Task.Run(() => {
                return(2015);
            });

            var _mockDataCollectionManager = new Mock <IDataCollectionManager>();

            _mockDataCollectionManager.Setup(m => m.GetLatestFinancialDataYearPerEstabTypeAsync(It.IsAny <EstablishmentType>()))
            .Returns(GetLatestFinancialDataYearPerEstabTypeAsyncTask);

            var _mockEdubaseDataService = new Mock <IContextDataService>();
            Task <EdubaseDataObject> GetSchoolDataObjectByUrnAsyncTask = Task.Run(() => {
                return(new EdubaseDataObject
                {
                    URN = 100,
                    EstablishmentName = "test"
                });
            });

            _mockEdubaseDataService.Setup(m => m.GetSchoolDataObjectByUrnAsync(100)).Returns((string urn) => GetSchoolDataObjectByUrnAsyncTask);

            var mockComparisonService = new Mock <IComparisonService>();

            var controller = new BenchmarkCriteriaController(null, _mockDocumentDbService.Object, _mockEdubaseDataService.Object, null, mockCookieManager.Object, mockComparisonService.Object, new ValidationService());

            var result = await controller.OverwriteStrategy(10000, ComparisonType.Advanced, EstablishmentType.Maintained, new BenchmarkCriteriaVM(new BenchmarkCriteria()
            {
                Gender = new[] { "Boys" }
            }), ComparisonArea.All, 306, "test", 10);

            Assert.AreEqual("BenchmarkCharts", (result as RedirectToRouteResult).RouteValues["Controller"]);
            Assert.AreEqual("GenerateNewFromAdvancedCriteria", (result as RedirectToRouteResult).RouteValues["Action"]);
        }