Beispiel #1
0
        public async Task HandleAysnc_HappyPath_ReturnsFileInfoWithCorrectFileName()
        {
            // Arrange
            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            UKCompetentAuthority authority = new UKCompetentAuthority(
                A.Dummy <Guid>(),
                "Environment Agency",
                "EA",
                A.Dummy <Country>(),
                "*****@*****.**",
                0);

            Scheme scheme = A.Dummy <Scheme>();

            A.CallTo(() => scheme.CompetentAuthority).Returns(authority);

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy <Guid>(),
                scheme,
                A.Dummy <string>(),
                A.Dummy <string>());

            memberUpload.Submit(A.Dummy <User>());

            List <MemberUpload> memberUploads = new List <MemberUpload>();

            memberUploads.Add(memberUpload);

            SystemTime.Freeze(new DateTime(2015, 12, 31));
            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy <User>());

            SystemTime.Unfreeze();

            ulong fileID = 123;

            IbisFileData ibisFileData = new IbisFileData(fileID, "Customer File.dat", "data", "Transaction File.dat", "data");

            invoiceRun.SetIbisFileData(ibisFileData);

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

            A.CallTo(() => dataAccess.FetchInvoiceRunAsync(A <Guid> ._)).Returns(invoiceRun);

            FetchInvoiceRunIbisZipFileHandler handler = new FetchInvoiceRunIbisZipFileHandler(
                authorization,
                dataAccess);

            // Act
            FileInfo fileInfo = await handler.HandleAsync(A.Dummy <Requests.Charges.FetchInvoiceRunIbisZipFile>());

            // Assert
            Assert.NotNull(fileInfo);
            Assert.Equal("WEEE invoice files 00123 2015-12-31.zip", fileInfo.FileName);
        }
        public async Task <IssuePendingChargesResult> HandleAsync(Requests.Charges.IssuePendingCharges message)
        {
            authorization.EnsureCanAccessInternalArea(true);
            authorization.EnsureUserInRole(Roles.InternalAdmin);

            UKCompetentAuthority authority = await dataAccess.FetchCompetentAuthority(message.Authority);

            IReadOnlyList <MemberUpload> memberUploads = await dataAccess.FetchSubmittedNonInvoicedMemberUploadsAsync(authority);

            User issuingUser = await domainUserContext.GetCurrentUserAsync();

            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, issuingUser);

            var result = new IssuePendingChargesResult();

            result.Errors = new List <string>();

            if (authority.Name == "Environment Agency")
            {
                ulong fileId = await GetNextIbisFileId();

                IbisFileDataGeneratorResult ibisFileDataGeneratorResult = await ibisFileDataGenerator.CreateFileDataAsync(fileId, invoiceRun);

                result.Errors.AddRange(ibisFileDataGeneratorResult.Errors);
                if (result.Errors.Count == 0)
                {
                    IbisFileData ibisFileData = ibisFileDataGeneratorResult.IbisFileData;
                    invoiceRun.SetIbisFileData(ibisFileData);
                }
            }

            if (result.Errors.Count == 0)
            {
                await dataAccess.SaveAsync(invoiceRun);

                result.InvoiceRunId = invoiceRun.Id;
            }

            return(result);
        }
        public async Task HandleAysnc_HappyPath_ReturnsFileInfoWithCorrectFileName()
        {
            // Arrange
            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            UKCompetentAuthority authority = new UKCompetentAuthority(
                A.Dummy<Guid>(),
                "Environment Agency",
                "EA",
                A.Dummy<Country>(),
                "*****@*****.**");

            Scheme scheme = A.Dummy<Scheme>();
            A.CallTo(() => scheme.CompetentAuthority).Returns(authority);

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy<Guid>(),
                scheme,
                A.Dummy<string>(),
                A.Dummy<string>());

            memberUpload.Submit(A.Dummy<User>());

            List<MemberUpload> memberUploads = new List<MemberUpload>();
            memberUploads.Add(memberUpload);

            SystemTime.Freeze(new DateTime(2015, 12, 31));
            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy<User>());
            SystemTime.Unfreeze();

            ulong fileID = 123;

            IbisFileData ibisFileData = new IbisFileData(fileID, "Customer File.dat", "data", "Transaction File.dat", "data");
            invoiceRun.SetIbisFileData(ibisFileData);

            ICommonDataAccess dataAccess = A.Fake<ICommonDataAccess>();
            A.CallTo(() => dataAccess.FetchInvoiceRunAsync(A<Guid>._)).Returns(invoiceRun);

            FetchInvoiceRunIbisZipFileHandler handler = new FetchInvoiceRunIbisZipFileHandler(
                authorization,
                dataAccess);

            // Act
            FileInfo fileInfo = await handler.HandleAsync(A.Dummy<Requests.Charges.FetchInvoiceRunIbisZipFile>());

            // Assert
            Assert.NotNull(fileInfo);
            Assert.Equal("WEEE invoice files 00123 2015-12-31.zip", fileInfo.FileName);
        }