Ejemplo n.º 1
0
        public void CompareController_DownloadCompareData_WithYear_SameSortAsync()
        {
            // Arrange
            var routeData = new RouteData();

            routeData.Values.Add("Action", nameof(CompareController.DownloadCompareData));
            routeData.Values.Add("Controller", "Viewing");

            var controller = UiTestHelper.GetController <CompareController>(0, routeData);


            controller.CompareViewService.SortColumn    = "OrganisationSize";
            controller.CompareViewService.SortAscending = false;

            var firstReportingYear = Global.FirstReportingYear;

            var      mockOrg            = OrganisationHelper.GetOrganisationInScope("MockedOrg", firstReportingYear);
            DateTime accountingDateTime = mockOrg.SectorType.GetAccountingStartDate(firstReportingYear);

            //create the comparison data
            var expectedModel = ViewingServiceHelper.GetCompareTestData(5).ToList();

            //Setup the mocked business logic
            var mockOrgBL = new Mock <IOrganisationBusinessLogic>();

            mockOrgBL
            .Setup(x => x.GetCompareData(It.IsAny <IEnumerable <string> >(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <bool>()))
            .Returns(expectedModel);
            var expectedData = expectedModel.ToDataTable();

            mockOrgBL
            .Setup(x => x.GetCompareDatatable(It.IsAny <IEnumerable <CompareReportModel> >()))
            .Returns(expectedData);
            controller.OrganisationBusinessLogic = mockOrgBL.Object;

            // Act
            var result = controller.DownloadCompareData(firstReportingYear) as ContentResult;

            // Assert

            //Test the google analytics tracker was executed once on the controller
            var filename = $"Compared GPG Data {ReportingYearsHelper.FormatYearAsReportingPeriod(firstReportingYear)}.csv";

            controller.WebTracker.GetMockFromObject().Verify(mock => mock.TrackPageView(It.IsAny <Controller>(), filename, null), Times.Once());

            Assert.NotNull(result);
            Assert.AreEqual(result.ContentType, "text/csv");
            Assert.AreEqual(controller.Response.Headers["Content-Disposition"], $"attachment; filename=\"{filename}\"");

            Assert.AreEqual(controller.CompareViewService.SortColumn, "OrganisationSize");
            Assert.AreEqual(controller.CompareViewService.SortAscending, false);

            Assert.NotNull(result.Content);
            Assert.AreEqual(result.Content, expectedData.ToCSV());
        }
Ejemplo n.º 2
0
        public void CompareController_CompareEmployers_WithYear_SameSortAsync()
        {
            // Arrange
            var routeData = new RouteData();

            routeData.Values.Add("Action", nameof(CompareController.CompareEmployers));
            routeData.Values.Add("Controller", "Viewing");

            var controller = UiTestHelper.GetController <CompareController>(0, routeData);

            //Setup the mock url helper
            var testUri = new Uri("https://localhost/Viewing/compare-employers");

            controller.AddMockUriHelper(testUri.ToString(), "CompareEmployers");

            controller.CompareViewService.SortColumn    = "OrganisationSize";
            controller.CompareViewService.SortAscending = false;

            var firstReportingYear = Global.FirstReportingYear;

            var      mockOrg            = OrganisationHelper.GetOrganisationInScope("MockedOrg", firstReportingYear);
            DateTime accountingDateTime = mockOrg.SectorType.GetAccountingStartDate(firstReportingYear);

            //create the comparison data
            var expectedModel = ViewingServiceHelper.GetCompareTestData(5).ToList();

            //Setup the mocked business logic
            var mockOrgBL = new Mock <IOrganisationBusinessLogic>();

            mockOrgBL
            .Setup(x => x.GetCompareData(It.IsAny <IEnumerable <string> >(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <bool>()))
            .Returns(expectedModel);
            controller.OrganisationBusinessLogic = mockOrgBL.Object;

            // Act
            var result = controller.CompareEmployers(firstReportingYear) as ViewResult;

            // Assert
            Assert.NotNull(result);
            Assert.AreEqual(result.ViewName, "CompareEmployers");
            Assert.AreEqual(controller.ViewBag.ReturnUrl, testUri.PathAndQuery);
            Assert.AreEqual(controller.CompareViewService.SortColumn, "OrganisationSize");
            Assert.AreEqual(controller.CompareViewService.SortAscending, false);


            var actualModel = result.Model as CompareViewModel;

            Assert.NotNull(actualModel);
            Assert.NotNull(actualModel.CompareReports);
            Assert.IsTrue(actualModel.CompareReports.All(obj => actualModel.Year == firstReportingYear));
            actualModel.CompareReports.Compare(expectedModel);
        }