예제 #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 HandleAsync_WithNonInternalUser_ThrowsSecurityException()
        {
            // Arrange
            IWeeeAuthorization authorization = new AuthorizationBuilder().DenyInternalAreaAccess().Build();

            FetchInvoiceRunIbisZipFileHandler handler = new FetchInvoiceRunIbisZipFileHandler(
                authorization,
                A.Dummy<ICommonDataAccess>());

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

            // Assert
            await Assert.ThrowsAsync<SecurityException>(testCode);
        }
예제 #3
0
        public async Task HandleAsync_WithNonInternalUser_ThrowsSecurityException()
        {
            // Arrange
            IWeeeAuthorization authorization = new AuthorizationBuilder().DenyInternalAreaAccess().Build();

            FetchInvoiceRunIbisZipFileHandler handler = new FetchInvoiceRunIbisZipFileHandler(
                authorization,
                A.Dummy <ICommonDataAccess>());

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

            // Assert
            await Assert.ThrowsAsync <SecurityException>(testCode);
        }
예제 #4
0
        public async Task HandleAsync_WithInvoiceRunWithout1B1SFileData_ThrowsInvalidOperationException()
        {
            // Arrange
            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            UKCompetentAuthority authority = A.Dummy <UKCompetentAuthority>();

            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);

            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy <User>());

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

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

            FetchInvoiceRunIbisZipFileHandler handler = new FetchInvoiceRunIbisZipFileHandler(
                authorization,
                dataAccess);

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

            // Assert
            await Assert.ThrowsAsync <InvalidOperationException>(testCode);
        }
        public async Task HandleAsync_WithInvoiceRunWithout1B1SFileData_ThrowsInvalidOperationException()
        {
            // Arrange
            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            UKCompetentAuthority authority = A.Dummy<UKCompetentAuthority>();

            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);

            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy<User>());

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

            FetchInvoiceRunIbisZipFileHandler handler = new FetchInvoiceRunIbisZipFileHandler(
                authorization,
                dataAccess);

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

            // Assert
            await Assert.ThrowsAsync<InvalidOperationException>(testCode);
        }
        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);
        }