Exemple #1
0
        public async Task HandleAsync_Always_CreatesFileNameWithSchemeApprovalNumberComplianceYearAndCurrentTime()
        {
            // Arrange
            Domain.Scheme.Scheme scheme = new Domain.Scheme.Scheme(A.Dummy <Organisation>());
            scheme.UpdateScheme(
                "Scheme name",
                "WEE/AB1234CD/SCH",
                A.Dummy <string>(),
                A.Dummy <Domain.Obligation.ObligationType?>(),
                A.Dummy <UKCompetentAuthority>());

            IFetchSummaryCsvDataAccess dataAccess = A.Fake <IFetchSummaryCsvDataAccess>();

            A.CallTo(() => dataAccess.FetchSchemeAsync(A <Guid> ._))
            .Returns(scheme);

            FetchSummaryCsvHandler handler = new FetchSummaryCsvHandler(
                A.Dummy <IWeeeAuthorization>(),
                A.Dummy <CsvWriterFactory>(),
                dataAccess);

            // Act
            Requests.DataReturns.FetchSummaryCsv request = new Requests.DataReturns.FetchSummaryCsv(
                A.Dummy <Guid>(),
                2017);

            SystemTime.Freeze(new DateTime(2016, 1, 2, 15, 22, 59), true);
            FileInfo result = await handler.HandleAsync(request);

            SystemTime.Unfreeze();

            // Assert
            Assert.NotNull(result);
            Assert.Equal("WEE/AB1234CD/SCH_EEE_WEEE_data_2017_02012016_1522.csv", result.FileName);
        }
Exemple #2
0
        public async Task HandleAsync_WithNoInternalOrOrganisationAccess_ThrowsSecurityException()
        {
            // Arrange
            IWeeeAuthorization authorization = new AuthorizationBuilder()
                                               .DenyInternalOrOrganisationAccess()
                                               .Build();

            FetchSummaryCsvHandler handler = new FetchSummaryCsvHandler(
                authorization,
                A.Dummy <CsvWriterFactory>(),
                A.Dummy <IFetchSummaryCsvDataAccess>());

            // Act
            Func <Task <FileInfo> > testCode = async() => await handler.HandleAsync(A.Dummy <Requests.DataReturns.FetchSummaryCsv>());

            // Assert
            await Assert.ThrowsAsync <SecurityException>(testCode);
        }