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);
        }
コード例 #2
0
        public void AskForOverwriteStrategyIfMultipleSchoolsInComparisonList()
        {
            var request = new Mock <HttpRequestBase>(MockBehavior.Strict);
            var context = new Mock <HttpContextBase>(MockBehavior.Strict);

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

            listCookie.BenchmarkSchools = new List <BenchmarkSchoolViewModel>()
            {
                new BenchmarkSchoolViewModel()
                {
                    Name = "test"
                }, new BenchmarkSchoolViewModel()
                {
                    Name = "test"
                }
            };
            requestCookies.Add(new HttpCookie(CookieNames.COMPARISON_LIST, JsonConvert.SerializeObject(listCookie)));
            context.SetupGet(x => x.Request.Cookies).Returns(requestCookies);
            var rc = new RequestContext(context.Object, new RouteData());

            var controller = new BenchmarkCriteriaController(null, null, null, null);

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

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


            Assert.IsNotNull(response);
            Assert.IsNotNull((response as ViewResult).Model);
            Assert.AreEqual("", (response as ViewResult).ViewName);
        }
コード例 #3
0
        public void DoNotAskForOverwriteStrategyIfOnlyBenchmarkSchoolInList()
        {
            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 responseCookies = new HttpCookieCollection();
            var listCookie      = new ComparisonListModel();

            listCookie.HomeSchoolUrn    = "100";
            listCookie.HomeSchoolName   = "home school";
            listCookie.BenchmarkSchools = new List <BenchmarkSchoolViewModel>()
            {
                new BenchmarkSchoolViewModel()
                {
                    Urn = "100", Name = "test"
                }
            };
            requestCookies.Add(new HttpCookie(CookieNames.COMPARISON_LIST, JsonConvert.SerializeObject(listCookie)));
            context.SetupGet(x => x.Request.Cookies).Returns(requestCookies);
            context.SetupGet(x => x.Response.Cookies).Returns(responseCookies);
            var rc = new RequestContext(context.Object, new RouteData());

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

            testResult.SetPropertyValue("URN", "321");
            testResult.SetPropertyValue("School Name", "test");
            Task <List <Document> > task = Task.Run(() =>
            {
                return(new List <Document> {
                    testResult
                });
            });

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

            var _mockDataCollectionManager = new Mock <IDataCollectionManager>();

            _mockDataCollectionManager.Setup(m => m.GetLatestFinancialDataYearPerSchoolType(It.IsAny <SchoolFinancialType>()))
            .Returns(2015);

            var     _mockEdubaseDataService = new Mock <IContextDataService>();
            dynamic testEduResult           = new Document();

            testEduResult.URN = "100";
            testEduResult.EstablishmentName = "test";
            _mockEdubaseDataService.Setup(m => m.GetSchoolByUrn("100")).Returns((string urn) => testEduResult);

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

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

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

            Assert.IsNotNull(response);
            Assert.AreEqual("BenchmarkCharts", (result as RedirectToRouteResult).RouteValues["Controller"]);
            Assert.AreEqual("GenerateNewFromAdvancedCriteria", (result as RedirectToRouteResult).RouteValues["Action"]);
        }
        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"]);
        }