Пример #1
0
        public void TabChangeShouldResetUnitTypeBetweenExpenditureAndWorkforceTabs()
        {
            var mockDocumentDbService = new Mock <IFinancialDataService>();

            var mockEdubaseDataService = new Mock <IContextDataService>();

            var mockBenchmarkChartBuilder = new Mock <IBenchmarkChartBuilder>();

            mockBenchmarkChartBuilder
            .Setup(cb => cb.Build(It.IsAny <RevenueGroupType>(), It.IsAny <EstablishmentType>()))
            .Returns((RevenueGroupType revenueGroup, EstablishmentType schoolType) => new List <ChartViewModel>()
            {
                new ChartViewModel()
                {
                    ChartGroup = ChartGroupType.Staff
                }
            });

            mockBenchmarkChartBuilder
            .Setup(cb => cb.Build(It.IsAny <RevenueGroupType>(), It.IsAny <ChartGroupType>(), It.IsAny <EstablishmentType>()))
            .Returns((RevenueGroupType revenueGroup, ChartGroupType chartGroup, EstablishmentType schoolType) => new List <ChartViewModel>()
            {
                new ChartViewModel()
                {
                    Name = "Staff", ChartGroup = ChartGroupType.Staff
                }
            });

            var financialCalculationsService = new Mock <IFinancialCalculationsService>();

            var mockLaService = new Mock <ILocalAuthoritiesService>();

            var mockComparisonService = new Mock <IComparisonService>();

            var controller = new BenchmarkChartsController(mockBenchmarkChartBuilder.Object, mockDocumentDbService.Object, financialCalculationsService.Object, mockLaService.Object, null, mockEdubaseDataService.Object, null, mockComparisonService.Object);

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

            controller.TabChange(EstablishmentType.Maintained, UnitType.AbsoluteMoney, RevenueGroupType.Workforce);

            financialCalculationsService.Verify(f => f.PopulateBenchmarkChartsWithFinancialData(
                                                    It.IsAny <List <ChartViewModel> >(),
                                                    It.IsAny <List <SchoolFinancialDataModel> >(),
                                                    It.IsAny <IEnumerable <CompareEntityBase> >(),
                                                    It.IsAny <string>(),
                                                    UnitType.AbsoluteCount,
                                                    It.IsAny <bool>()));
        }
Пример #2
0
        public void GenerateFromAdvancedCriteriaWithOverwriteAddsTheBenchmarkSchoolToTheBenchmarkListIfNotAlreadyReturned()
        {
            var mockDocumentDbService = new Mock <IFinancialDataService>();
            var testResult            = new Document();

            testResult.SetPropertyValue("URN", "321");
            testResult.SetPropertyValue("School Name", "test");
            testResult.SetPropertyValue("FinanceType", "A");
            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     mockEdubaseDataService = new Mock <IContextDataService>();
            dynamic testEduResult          = new Document();

            testEduResult.URN = "321";
            mockEdubaseDataService.Setup(m => m.GetSchoolByUrn("321")).Returns((string urn) => testEduResult);

            var mockComparisonService     = new Mock <IComparisonService>();
            Task <ComparisonResult> cTask = Task.Run(() =>
            {
                return(new ComparisonResult()
                {
                    BenchmarkSchools = new List <Document>()
                    {
                        testResult
                    }
                });
            });

            mockComparisonService.Setup(m =>
                                        m.GenerateBenchmarkListWithAdvancedComparisonAsync(It.IsAny <BenchmarkCriteria>(),
                                                                                           It.IsAny <EstablishmentType>(), It.IsAny <Int32>()))
            .Returns((BenchmarkCriteria criteria, EstablishmentType estType, int basketSize) => cTask);

            var mockBenchmarkChartBuilder = new Mock <IBenchmarkChartBuilder>();

            mockBenchmarkChartBuilder
            .Setup(cb => cb.Build(It.IsAny <RevenueGroupType>(), It.IsAny <EstablishmentType>()))
            .Returns((RevenueGroupType revenueGroup, EstablishmentType schoolType) => new List <ChartViewModel>()
            {
                new ChartViewModel()
                {
                    ChartGroup = ChartGroupType.Staff
                }
            });

            var financialCalculationsService = new Mock <IFinancialCalculationsService>();

            var mockLaService = new Mock <ILocalAuthoritiesService>();

            mockLaService.Setup(m => m.GetLocalAuthorities()).Returns(() => "[{\"id\": \"0\",\"LANAME\": \"Hartlepool\",\"REGION\": \"1\",\"REGIONNAME\": \"North East A\"}]");

            var controller = new BenchmarkChartsController(mockBenchmarkChartBuilder.Object, mockDocumentDbService.Object, financialCalculationsService.Object, mockLaService.Object, null, mockEdubaseDataService.Object, null, mockComparisonService.Object);

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

            var result = controller.GenerateFromAdvancedCriteria(new BenchmarkCriteria(), EstablishmentType.All, null, "123", ComparisonArea.All);

            result.Wait();

            var cookie = JsonConvert.DeserializeObject <ComparisonListModel>(controller.Response.Cookies[CookieNames.COMPARISON_LIST].Value);

            Assert.AreEqual(2, cookie.BenchmarkSchools.Count);

            Assert.AreEqual("123", cookie.BenchmarkSchools[1].Urn);
        }