public async Task GetAllAatfReuseSitesCsvHandler_ComplianceYear_ReturnsFileContent()
        {
            const int complianceYear = 2016;

            var request = new GetAllAatfReuseSitesCsv(complianceYear, null, null);

            var data = await handler.HandleAsync(request);

            Assert.NotEmpty(data.FileContent);
        }
        public async Task GetAllAatfReuseSitesCsvHandler_NoComplianceYear_ThrowsArgumentException()
        {
            const int complianceYear = 0;

            var request = new GetAllAatfReuseSitesCsv(complianceYear, null, null);

            Func <Task> action = async() => await handler.HandleAsync(request);

            await Assert.ThrowsAsync <ArgumentException>(action);
        }
        public async Task HandleAsync_GivenComplianceYearRequest_FileNamedShouldBeCorrectFileContent()
        {
            var request = new GetAllAatfReuseSitesCsv(2019, null, null);

            SystemTime.Freeze(new DateTime(2019, 2, 1, 11, 1, 2));

            var data = await handler.HandleAsync(request);

            data.FileName.Should().Be("2019_AATF using reuse sites_01022019_1101.csv");

            SystemTime.Unfreeze();
        }
        public async Task GetAllAatfReuseSitesCsvHandler_NotInternalUser_ThrowsSecurityException()
        {
            const int complianceYear = 2016;

            var authorization = new AuthorizationBuilder().DenyInternalAreaAccess().Build();

            var handler = new GetAllAatfReuseSitesCsvHandler(authorization, context, csvWriterFactory, commonDataAccess);
            var request = new GetAllAatfReuseSitesCsv(complianceYear, null, null);

            Func <Task> action = async() => await handler.HandleAsync(request);

            await Assert.ThrowsAsync <SecurityException>(action);
        }
Esempio n. 5
0
        public async Task <ActionResult> DownloadAatfReuseSitesCsv(int complianceYear, Guid?authorityId, Guid?panArea)
        {
            CSVFileData fileData;

            var request = new GetAllAatfReuseSitesCsv(complianceYear, authorityId, panArea);

            using (var client = apiClient())
            {
                fileData = await client.SendAsync(User.GetAccessToken(), request);
            }

            var data = new UTF8Encoding().GetBytes(fileData.FileContent);

            return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(fileData.FileName)));
        }
        public async Task HandleAsync_GivenRequest_MatchingFileContent()
        {
            var storedProcedures = A.Fake <IStoredProcedures>();

            A.CallTo(() => context.StoredProcedures).Returns(storedProcedures);

            var csvData1 = new AatfReuseSitesData()
            {
                ComplianceYear = 2019,
                Quarter        = "Q1",
                SubmittedBy    = "Test User",
                SubmittedDate  = new DateTime(2019, 2, 1, 11, 1, 2),
                OrgName        = "Org 1",
                Abbreviation   = "EA",
                PanName        = "North",
                LaName         = "Surrey",
                SiteName       = "Test Site",
                SiteAddress    = "1 address, address2, town, county, UK-England"
            };
            var csvData2 = new AatfReuseSitesData()
            {
                ComplianceYear = 2019,
                Quarter        = "Q1",
                SubmittedBy    = "Test User",
                SubmittedDate  = new DateTime(2019, 2, 1, 11, 1, 2),
                OrgName        = "Org 1",
                Abbreviation   = "EA",
                PanName        = "North",
                LaName         = "Surrey",
                SiteName       = "Test Site 2",
                SiteAddress    = "1 address, address2, town, county, UK-England"
            };

            var request = new GetAllAatfReuseSitesCsv(2019, null, null);

            A.CallTo(() => storedProcedures.GetAllAatfReuseSitesCsvData(request.ComplianceYear, request.AuthorityId, request.PanArea)).Returns(new List <AatfReuseSitesData> {
                csvData1, csvData2
            });

            var data = await handler.HandleAsync(request);

            data.FileContent.Should().Contain("Appropriate authority,WROS Pan Area Team,EA Area,Compliance year,Quarter,Submitted by,Date submitted (GMT),Name of AATF,Approval number,Organisation name,Reuse site name,Reuse site address");
            data.FileContent.Should().Contain($"{csvData1.Abbreviation},{csvData1.PanName},{csvData1.LaName},{csvData1.ComplianceYear},{csvData1.Quarter},{csvData1.SubmittedBy},{csvData1.SubmittedDate},{csvData1.Name},{csvData1.ApprovalNumber},{csvData1.OrgName},{csvData1.SiteName},\"{csvData1.SiteAddress}\"");
            data.FileContent.Should().Contain($"{csvData2.Abbreviation},{csvData2.PanName},{csvData2.LaName},{csvData2.ComplianceYear},{csvData2.Quarter},{csvData2.SubmittedBy},{csvData2.SubmittedDate},{csvData2.Name},{csvData2.ApprovalNumber},{csvData2.OrgName},{csvData2.SiteName},\"{csvData2.SiteAddress}\"");
        }