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

            var request = new GetUkNonObligatedWeeeReceivedDataCsv(complianceYear);

            var data = await handler.HandleAsync(request);

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

            var request = new GetUkNonObligatedWeeeReceivedDataCsv(complianceYear);

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

            await Assert.ThrowsAsync <ArgumentException>(action);
        }
        public async Task HandleAsync_PassVariousComplianceYears_ReturnsFileContent(int complianceYear)
        {
            var request = new GetUkNonObligatedWeeeReceivedDataCsv(complianceYear);

            // Act
            var data = await handler.HandleAsync(request);

            // Assert
            Assert.NotEmpty(data.FileContent);
        }
        public async Task HandleAsync_NotInternalUser_ThrowsSecurityException()
        {
            const int complianceYear = 2016;

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

            var handler = new GetUkNonObligatedWeeeReceivedDataCsvHandler(authorization, context, csvWriterFactory);
            var request = new GetUkNonObligatedWeeeReceivedDataCsv(complianceYear);

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

            await Assert.ThrowsAsync <SecurityException>(action);
        }
        public async Task HandleAsync_GivenMandatoryParametersAndLocalArea_FileNameShouldBeCorrect(string expectedText, bool includeResubmissions)
        {
            var request = new GetUkNonObligatedWeeeReceivedDataCsv(fixture.Create <int>());

            var date = new DateTime(2019, 05, 18, 11, 12, 0);

            SystemTime.Freeze(date);

            var data = await handler.HandleAsync(request);

            data.FileName.Should().Be($"{ request.ComplianceYear}_UK non-obligated WEEE received at AATFs__{ date:ddMMyyyy_HHmm}.csv");

            SystemTime.Unfreeze();
        }
        public async Task HandleAsync_Returns_MatchingFileContent()
        {
            const int    complianceYear = 2019;
            const string quarter        = "Q1";

            var csvData1 = new UkNonObligatedWeeeReceivedData
            {
                Category = "1. Large Household Appliances",
                Quarter  = quarter,
                TotalNonObligatedWeeeReceived        = 99,
                TotalNonObligatedWeeeReceivedFromDcf = 98
            };

            var csvData2 = new UkNonObligatedWeeeReceivedData
            {
                Category = "2. Small Household Appliances",
                Quarter  = quarter,
                TotalNonObligatedWeeeReceived        = 97,
                TotalNonObligatedWeeeReceivedFromDcf = 96
            };

            var csvData3 = new UkNonObligatedWeeeReceivedData
            {
                Category = "3. IT and Telecomms Equipment",
                Quarter  = quarter,
                TotalNonObligatedWeeeReceived        = 95,
                TotalNonObligatedWeeeReceivedFromDcf = 94
            };

            A.CallTo(() => storedProcedures
                     .GetUkNonObligatedWeeeReceivedByComplianceYear(A <int> ._))
            .Returns(new List <UkNonObligatedWeeeReceivedData> {
                csvData1, csvData2, csvData3
            });

            var request = new GetUkNonObligatedWeeeReceivedDataCsv(complianceYear);

            // Act
            var data = await handler.HandleAsync(request);

            data.FileContent.Should().Contain("Q1,1. Large Household Appliances,99,98");
            data.FileContent.Should().Contain("Q1,2. Small Household Appliances,97,96");
            data.FileContent.Should().Contain("Q1,3. IT and Telecomms Equipment,95,94");
        }