示例#1
0
        public async Task <ActionResult> ManagePendingCharges(CompetentAuthority authority, FormCollection formCollection)
        {
            using (IWeeeClient client = weeeClient())
            {
                IssuePendingCharges       request = new IssuePendingCharges(authority);
                IssuePendingChargesResult result  = await client.SendAsync(User.GetAccessToken(), request);

                if (Request.IsAjaxRequest())
                {
                    var jsonResult = new
                    {
                        Success      = result.Errors.Count == 0,
                        InvoiceRunId = result.InvoiceRunId,
                        Errors       = result.Errors
                    };
                    return(Json(jsonResult));
                }
                else
                {
                    if (result.Errors.Count == 0)
                    {
                        return(RedirectToAction("ChargesSuccessfullyIssued", new { authority, id = result.InvoiceRunId.Value }));
                    }
                    else
                    {
                        return(View("IssueChargesError", result.Errors));
                    }
                }
            }
        }
示例#2
0
        public async Task GetDownloadIssuedChargesCsv_Always_CallsApiAndReturnsFileResultWithCorrectFileName()
        {
            // Arrange
            CompetentAuthority authority = A.Dummy <CompetentAuthority>();
            int  complianceYear          = A.Dummy <int>();
            Guid schemeId = A.Dummy <Guid>();

            IWeeeClient weeeClient = A.Fake <IWeeeClient>();

            FileInfo fileInfo = new FileInfo("filename", new byte[] { 1, 2, 3 });

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <FetchIssuedChargesCsv> ._))
            .WhenArgumentsMatch(a => a.Get <FetchIssuedChargesCsv>("request").Authority == authority &&
                                a.Get <FetchIssuedChargesCsv>("request").ComplianceYear == complianceYear &&
                                a.Get <FetchIssuedChargesCsv>("request").SchemeId == schemeId)
            .Returns(fileInfo);

            ChargeController controller = new ChargeController(
                A.Dummy <IAppConfiguration>(),
                A.Dummy <BreadcrumbService>(),
                () => weeeClient);

            // Act
            ActionResult result = await controller.DownloadIssuedChargesCsv(authority, complianceYear, schemeId);

            // Assert
            FileResult fileResult = result as FileResult;

            Assert.NotNull(fileResult);

            Assert.Equal("filename", fileResult.FileDownloadName);
        }
示例#3
0
        public void UpdateTransitStateForNotification(Guid targetTransitStateId, Country country,
                                                      CompetentAuthority competentAuthority,
                                                      EntryOrExitPoint entryPoint,
                                                      EntryOrExitPoint exitPoint,
                                                      int?ordinalPosition)
        {
            var targetTransitState = TransitStatesCollection.Single(ts => ts.Id == targetTransitStateId);

            if (ordinalPosition.HasValue && ordinalPosition < 1)
            {
                ordinalPosition = null;
            }

            var allTransitStatesExceptTarget =
                TransitStatesCollection.Where(ts => ts.Id != targetTransitStateId).ToArray();

            if (ordinalPosition.HasValue &&
                allTransitStatesExceptTarget.Any(ts => ts.OrdinalPosition == ordinalPosition))
            {
                throw new InvalidOperationException(
                          string.Format(
                              "Attempted to edit a Transit State {0} to position {1} for TransportRoute {2}. The TransportRoute already has another Transit State at this position.",
                              targetTransitStateId,
                              ordinalPosition.Value,
                              Id));
            }

            targetTransitState.UpdateTransitState(country, competentAuthority, entryPoint, exitPoint, ordinalPosition);
        }
        public TransitState(Country country, CompetentAuthority competentAuthority, EntryOrExitPoint entryPoint, EntryOrExitPoint exitPoint, int ordinalPosition)
        {
            Guard.ArgumentNotNull(() => country, country);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => entryPoint, entryPoint);
            Guard.ArgumentNotNull(() => exitPoint, exitPoint);
            Guard.ArgumentNotZeroOrNegative(() => OrdinalPosition, ordinalPosition);

            if (country.Id != competentAuthority.Country.Id 
                || country.Id != entryPoint.Country.Id
                || country.Id != exitPoint.Country.Id)
            {
                throw new InvalidOperationException(string.Format("Transit State Competent Authority, Entry and Exit Point must all have the same country. Competent Authority: {0}. Entry: {1}. Exit: {2}. Country: {3}",
                    competentAuthority.Id,
                    entryPoint.Id,
                    exitPoint.Id,
                    country.Name));
            }

            Country = country;
            CompetentAuthority = competentAuthority;
            ExitPoint = exitPoint;
            EntryPoint = entryPoint;
            OrdinalPosition = ordinalPosition;
        }
示例#5
0
        public TransitState(Country country, CompetentAuthority competentAuthority, EntryOrExitPoint entryPoint, EntryOrExitPoint exitPoint, int ordinalPosition)
        {
            Guard.ArgumentNotNull(() => country, country);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => entryPoint, entryPoint);
            Guard.ArgumentNotNull(() => exitPoint, exitPoint);
            Guard.ArgumentNotZeroOrNegative(() => OrdinalPosition, ordinalPosition);

            if (country.Id != competentAuthority.Country.Id ||
                country.Id != entryPoint.Country.Id ||
                country.Id != exitPoint.Country.Id)
            {
                throw new InvalidOperationException(string.Format("Transit State Competent Authority, Entry and Exit Point must all have the same country. Competent Authority: {0}. Entry: {1}. Exit: {2}. Country: {3}",
                                                                  competentAuthority.Id,
                                                                  entryPoint.Id,
                                                                  exitPoint.Id,
                                                                  country.Name));
            }

            Country            = country;
            CompetentAuthority = competentAuthority;
            ExitPoint          = exitPoint;
            EntryPoint         = entryPoint;
            OrdinalPosition    = ordinalPosition;
        }
示例#6
0
        public async Task FetchInvoiceRunsAsync_Always_ReturnsResultsOrderedByIssuedDateDescending()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser  user   = helper.GetOrCreateUser("TestUser");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id   = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority = new CompetentAuthority();
                databaseAuthority.Id                 = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority.Name               = "Test Authority 1";
                databaseAuthority.Abbreviation       = "T1";
                databaseAuthority.Country            = country;
                databaseAuthority.Email              = "TestEmailAddress";
                databaseAuthority.AnnualChargeAmount = 0;
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority);

                InvoiceRun invoiceRun1 = new InvoiceRun();
                invoiceRun1.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRun1.CompetentAuthority = databaseAuthority;
                invoiceRun1.IssuedByUserId     = user.Id;
                invoiceRun1.IssuedDate         = new DateTime(2015, 1, 2);
                wrapper.Model.InvoiceRuns.Add(invoiceRun1);

                InvoiceRun invoiceRun2 = new InvoiceRun();
                invoiceRun2.Id = new Guid("728CDF55-1C3C-4BE0-80CB-0BC82CC9DFA3");
                invoiceRun2.CompetentAuthority = databaseAuthority;
                invoiceRun2.IssuedByUserId     = user.Id;
                invoiceRun2.IssuedDate         = new DateTime(2015, 1, 1);
                wrapper.Model.InvoiceRuns.Add(invoiceRun2);

                InvoiceRun invoiceRun3 = new InvoiceRun();
                invoiceRun3.Id = new Guid("B235CD4F-8188-4BC0-ADA2-55FD6B34BC01");
                invoiceRun3.CompetentAuthority = databaseAuthority;
                invoiceRun3.IssuedByUserId     = user.Id;
                invoiceRun3.IssuedDate         = new DateTime(2015, 1, 3);
                wrapper.Model.InvoiceRuns.Add(invoiceRun3);

                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority.Id);

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList <Domain.Charges.InvoiceRun> results = await dataAccess.FetchInvoiceRunsAsync(domainAuthority);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(3, results.Count);
                Assert.Collection(results,
                                  r1 => Assert.Equal(new DateTime(2015, 1, 3), r1.IssuedDate),
                                  r2 => Assert.Equal(new DateTime(2015, 1, 2), r2.IssuedDate),
                                  r3 => Assert.Equal(new DateTime(2015, 1, 1), r3.IssuedDate));
            }
        }
示例#7
0
        public async Task FetchInvoiceRunsAsync_WithSpecifiedAuthority_OnlyReturnsInvoiceRunsForTheSpecifiedAuthority()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser  user   = helper.GetOrCreateUser("TestUser");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id   = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority1 = new CompetentAuthority();
                databaseAuthority1.Id                 = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority1.Name               = "Test Authority 1";
                databaseAuthority1.Abbreviation       = "T1";
                databaseAuthority1.Country            = country;
                databaseAuthority1.Email              = "TestEmailAddress";
                databaseAuthority1.AnnualChargeAmount = 0;
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority1);

                CompetentAuthority databaseAuthority2 = new CompetentAuthority();
                databaseAuthority2.Id                 = new Guid("FBCEDC2F-0825-4066-B24E-86D3A2FD892B");
                databaseAuthority2.Name               = "Test Authority 2";
                databaseAuthority2.Abbreviation       = "T2";
                databaseAuthority2.Country            = country;
                databaseAuthority2.Email              = "TestEmailAddress2";
                databaseAuthority2.AnnualChargeAmount = 0;
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority2);

                InvoiceRun invoiceRunForAuthority1 = new InvoiceRun();
                invoiceRunForAuthority1.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRunForAuthority1.CompetentAuthority = databaseAuthority1;
                invoiceRunForAuthority1.IssuedByUserId     = user.Id;
                invoiceRunForAuthority1.IssuedDate         = new DateTime(2015, 1, 1);
                wrapper.Model.InvoiceRuns.Add(invoiceRunForAuthority1);

                InvoiceRun invoiceRunForAuthority2 = new InvoiceRun();
                invoiceRunForAuthority2.Id = new Guid("728CDF55-1C3C-4BE0-80CB-0BC82CC9DFA3");
                invoiceRunForAuthority2.CompetentAuthority = databaseAuthority2;
                invoiceRunForAuthority2.IssuedByUserId     = user.Id;
                invoiceRunForAuthority2.IssuedDate         = new DateTime(2015, 1, 1);
                wrapper.Model.InvoiceRuns.Add(invoiceRunForAuthority2);

                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority1 = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority1.Id);

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList <Domain.Charges.InvoiceRun> results = await dataAccess.FetchInvoiceRunsAsync(domainAuthority1);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.Equal(new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872"), results[0].Id);
            }
        }
        public async Task FetchInvoiceRunsAsync_WithSpecifiedAuthority_OnlyReturnsInvoiceRunsForTheSpecifiedAuthority()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser user = helper.GetOrCreateUser("TestUser");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority1 = new CompetentAuthority();
                databaseAuthority1.Id = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority1.Name = "Test Authority 1";
                databaseAuthority1.Abbreviation = "T1";
                databaseAuthority1.Country = country;
                databaseAuthority1.Email = "TestEmailAddress";
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority1);

                CompetentAuthority databaseAuthority2 = new CompetentAuthority();
                databaseAuthority2.Id = new Guid("FBCEDC2F-0825-4066-B24E-86D3A2FD892B");
                databaseAuthority2.Name = "Test Authority 2";
                databaseAuthority2.Abbreviation = "T2";
                databaseAuthority2.Country = country;
                databaseAuthority2.Email = "TestEmailAddress2";
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority2);

                InvoiceRun invoiceRunForAuthority1 = new InvoiceRun();
                invoiceRunForAuthority1.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRunForAuthority1.CompetentAuthority = databaseAuthority1;
                invoiceRunForAuthority1.IssuedByUserId = user.Id;
                invoiceRunForAuthority1.IssuedDate = new DateTime(2015, 1, 1);
                wrapper.Model.InvoiceRuns.Add(invoiceRunForAuthority1);

                InvoiceRun invoiceRunForAuthority2 = new InvoiceRun();
                invoiceRunForAuthority2.Id = new Guid("728CDF55-1C3C-4BE0-80CB-0BC82CC9DFA3");
                invoiceRunForAuthority2.CompetentAuthority = databaseAuthority2;
                invoiceRunForAuthority2.IssuedByUserId = user.Id;
                invoiceRunForAuthority2.IssuedDate = new DateTime(2015, 1, 1);
                wrapper.Model.InvoiceRuns.Add(invoiceRunForAuthority2);

                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority1 = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority1.Id);

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList<Domain.Charges.InvoiceRun> results = await dataAccess.FetchInvoiceRunsAsync(domainAuthority1);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.Equal(new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872"), results[0].Id);
            }
        }
示例#9
0
        private async Task <IEnumerable <SchemeData> > GetSchemesWithInvoices(CompetentAuthority authority)
        {
            FetchSchemesWithInvoices request = new FetchSchemesWithInvoices(authority);

            using (IWeeeClient client = weeeClient())
            {
                return(await client.SendAsync(User.GetAccessToken(), request));
            }
        }
示例#10
0
 public TestableUnitedKingdomCompetentAuthority(int id,
                                                CompetentAuthority competentAuthority,
                                                string unitedKingdomCountry,
                                                CompetentAuthorityBacsDetails bacsDetails)
 {
     this.Id = id;
     this.CompetentAuthority   = competentAuthority;
     this.UnitedKingdomCountry = unitedKingdomCountry;
     this.BacsDetails          = bacsDetails;
 }
        public async Task FetchInvoicedProducerSubmissionsAsync_ReturnsProducerSubmissionsForRemovedProducer_WhenProducerHasBeenInvoiced()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                var helper       = new ModelHelper(database.Model);
                var domainHelper = new DomainHelper(database.WeeeContext);

                // At least one user is required in the database.
                var user = helper.GetOrCreateUser("A user");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id   = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority competentAuthority = new CompetentAuthority();
                competentAuthority.Id                 = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                competentAuthority.Name               = "Test Authority 1";
                competentAuthority.Abbreviation       = "T1";
                competentAuthority.Country            = country;
                competentAuthority.Email              = "TestEmailAddress";
                competentAuthority.AnnualChargeAmount = 0;
                database.Model.CompetentAuthorities.Add(competentAuthority);

                InvoiceRun invoiceRunForAuthority = new InvoiceRun();
                invoiceRunForAuthority.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRunForAuthority.CompetentAuthority = competentAuthority;
                invoiceRunForAuthority.IssuedByUserId     = user.Id;
                invoiceRunForAuthority.IssuedDate         = new DateTime(2000, 12, 1);
                database.Model.InvoiceRuns.Add(invoiceRunForAuthority);

                var    scheme             = helper.CreateScheme();
                string registrationNumber = "AAAA";

                scheme.CompetentAuthorityId = competentAuthority.Id;
                var memberUpload = helper.CreateSubmittedMemberUpload(scheme, invoiceRunForAuthority);
                memberUpload.ComplianceYear = 2000;

                var producerSubmission = helper.CreateInvoicedProducer(memberUpload, registrationNumber);
                producerSubmission.RegisteredProducer.Removed = true;

                database.Model.SaveChanges();

                UKCompetentAuthority            domainAuthority = domainHelper.GetCompetentAuthority(competentAuthority.Id);
                FetchIssuedChargesCsvDataAccess dataAccess      = new FetchIssuedChargesCsvDataAccess(database.WeeeContext);

                // Act
                var results = await dataAccess.FetchInvoicedProducerSubmissionsAsync(domainAuthority, 2000, scheme.Id);

                // Assert
                Assert.Equal(1, results.Count());

                var producerResult = results.Single();
                Assert.Equal(producerSubmission.Id, producerResult.Id);
            }
        }
示例#12
0
        public async Task <ActionResult> IssuedCharges(CompetentAuthority authority, IssuedChargesViewModel viewModel)
        {
            ViewBag.Authority       = authority;
            ViewBag.TriggerDownload = ModelState.IsValid;

            viewModel.ComplianceYears = await GetComplianceYearsWithInvoices(authority);

            viewModel.Schemes = await GetSchemesWithInvoices(authority);

            return(View(viewModel));
        }
示例#13
0
        public ActionResult SelectAuthority(SelectAuthorityViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            CompetentAuthority authority = viewModel.SelectedAuthority.Value;

            return(RedirectToAction("ChooseActivity", new { authority }));
        }
示例#14
0
        public async Task <ActionResult> DownloadIssuedChargesCsv(CompetentAuthority authority, int complianceYear, Guid?schemeId)
        {
            FileInfo file;

            using (IWeeeClient client = weeeClient())
            {
                FetchIssuedChargesCsv request = new FetchIssuedChargesCsv(authority, complianceYear, schemeId);
                file = await client.SendAsync(User.GetAccessToken(), request);
            }

            return(File(file.Data, "text/csv", file.FileName));
        }
        public async Task FetchInvoicedProducerSubmissionsAsync_WithSpecifiedAuthorityYearAndSchemeName_OnlyReturnsProducerSubmissions()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                var helper = new ModelHelper(database.Model);
                // At least one user is required in the database.
                var user = helper.GetOrCreateUser("A user");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id   = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority1 = new CompetentAuthority();
                databaseAuthority1.Id                 = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority1.Name               = "Test Authority 1";
                databaseAuthority1.Abbreviation       = "T1";
                databaseAuthority1.Country            = country;
                databaseAuthority1.Email              = "TestEmailAddress";
                databaseAuthority1.AnnualChargeAmount = 0;
                database.Model.CompetentAuthorities.Add(databaseAuthority1);

                InvoiceRun invoiceRunForAuthority1 = new InvoiceRun();
                invoiceRunForAuthority1.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRunForAuthority1.CompetentAuthority = databaseAuthority1;
                invoiceRunForAuthority1.IssuedByUserId     = user.Id;
                invoiceRunForAuthority1.IssuedDate         = new DateTime(2016, 12, 1);
                database.Model.InvoiceRuns.Add(invoiceRunForAuthority1);

                var    scheme             = helper.CreateScheme();
                string registrationNumber = "AAAA";

                scheme.CompetentAuthorityId = databaseAuthority1.Id;
                var memberUpload = helper.CreateSubmittedMemberUpload(scheme, invoiceRunForAuthority1);

                var producerSubmission = helper.CreateInvoicedProducer(memberUpload, registrationNumber);

                database.Model.SaveChanges();
                UKCompetentAuthority            domainAuthority1 = database.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority1.Id);
                FetchIssuedChargesCsvDataAccess dataAccess       = new FetchIssuedChargesCsvDataAccess(database.WeeeContext);

                // Act
                IEnumerable <Domain.Producer.ProducerSubmission> results = await dataAccess.FetchInvoicedProducerSubmissionsAsync(domainAuthority1, 2016, scheme.Id);

                List <Domain.Producer.ProducerSubmission> producerSubmissionList = results.ToList();

                Domain.Producer.ProducerSubmission producer = results.FirstOrDefault(p => p.RegisteredProducer.ProducerRegistrationNumber == registrationNumber);
                // Assert
                Assert.NotNull(producer);
                Assert.Equal(producerSubmission.RegisteredProducer.ProducerRegistrationNumber, producer.RegisteredProducer.ProducerRegistrationNumber);
                Assert.Equal(1, producerSubmissionList.Count);
            }
        }
示例#16
0
        public async Task <ActionResult> InvoiceRuns(CompetentAuthority authority)
        {
            IReadOnlyList <InvoiceRunInfo> invoiceRuns;

            using (IWeeeClient client = weeeClient())
            {
                FetchInvoiceRuns request = new FetchInvoiceRuns(authority);
                invoiceRuns = await client.SendAsync(User.GetAccessToken(), request);
            }

            ViewBag.AllowDownloadOfInvoiceFiles = (authority == CompetentAuthority.England);
            return(View(invoiceRuns));
        }
示例#17
0
        public async Task FetchnvoicedMemberUploadsAsync_WithSpecifiedAuthority_OOnlyReturnsInvoicedMemberUploadsForTheSpecifiedAuthority()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser  user   = helper.GetOrCreateUser("TestUser");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id   = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority1 = new CompetentAuthority();
                databaseAuthority1.Id                 = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority1.Name               = "Test Authority 1";
                databaseAuthority1.Abbreviation       = "T1";
                databaseAuthority1.Country            = country;
                databaseAuthority1.Email              = "TestEmailAddress";
                databaseAuthority1.AnnualChargeAmount = 0;
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority1);

                InvoiceRun invoiceRunForAuthority1 = new InvoiceRun();
                invoiceRunForAuthority1.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRunForAuthority1.CompetentAuthority = databaseAuthority1;
                invoiceRunForAuthority1.IssuedByUserId     = user.Id;
                invoiceRunForAuthority1.IssuedDate         = new DateTime(2015, 1, 1);
                wrapper.Model.InvoiceRuns.Add(invoiceRunForAuthority1);

                var scheme = helper.CreateScheme();
                scheme.CompetentAuthorityId = databaseAuthority1.Id;
                var memberUpload = helper.CreateSubmittedMemberUpload(scheme, invoiceRunForAuthority1);

                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority1 = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority1.Id);

                CommonDataAccess dataAccess = new CommonDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList <Domain.Scheme.MemberUpload> results = await dataAccess.FetchInvoicedMemberUploadsAsync(domainAuthority1);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.Equal(memberUpload.Id, results[0].Id);
            }
        }
示例#18
0
        internal void UpdateTransitState(Country country, 
            CompetentAuthority competentAuthority, 
            EntryOrExitPoint entryPoint,
            EntryOrExitPoint exitPoint, 
            int? ordinalPosition)
        {
            Guard.ArgumentNotNull(() => country, country);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => entryPoint, entryPoint);
            Guard.ArgumentNotNull(() => exitPoint, exitPoint);

            this.CompetentAuthority = competentAuthority;
            this.Country = country;
            this.EntryPoint = entryPoint;
            this.ExitPoint = exitPoint;
            this.OrdinalPosition = ordinalPosition ?? this.OrdinalPosition;
        }
示例#19
0
        internal void UpdateTransitState(Country country,
                                         CompetentAuthority competentAuthority,
                                         EntryOrExitPoint entryPoint,
                                         EntryOrExitPoint exitPoint,
                                         int?ordinalPosition)
        {
            Guard.ArgumentNotNull(() => country, country);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => entryPoint, entryPoint);
            Guard.ArgumentNotNull(() => exitPoint, exitPoint);

            this.CompetentAuthority = competentAuthority;
            this.Country            = country;
            this.EntryPoint         = entryPoint;
            this.ExitPoint          = exitPoint;
            this.OrdinalPosition    = ordinalPosition ?? this.OrdinalPosition;
        }
        public async Task FetchnvoicedMemberUploadsAsync_WithSpecifiedAuthority_OOnlyReturnsInvoicedMemberUploadsForTheSpecifiedAuthority()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser user = helper.GetOrCreateUser("TestUser");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority1 = new CompetentAuthority();
                databaseAuthority1.Id = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority1.Name = "Test Authority 1";
                databaseAuthority1.Abbreviation = "T1";
                databaseAuthority1.Country = country;
                databaseAuthority1.Email = "TestEmailAddress";
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority1);

                InvoiceRun invoiceRunForAuthority1 = new InvoiceRun();
                invoiceRunForAuthority1.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRunForAuthority1.CompetentAuthority = databaseAuthority1;
                invoiceRunForAuthority1.IssuedByUserId = user.Id;
                invoiceRunForAuthority1.IssuedDate = new DateTime(2015, 1, 1);
                wrapper.Model.InvoiceRuns.Add(invoiceRunForAuthority1);

                var scheme = helper.CreateScheme();
                scheme.CompetentAuthorityId = databaseAuthority1.Id;
                var memberUpload = helper.CreateSubmittedMemberUpload(scheme, invoiceRunForAuthority1);

                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority1 = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority1.Id);

                CommonDataAccess dataAccess = new CommonDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList<Domain.Scheme.MemberUpload> results = await dataAccess.FetchInvoicedMemberUploadsAsync(domainAuthority1);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.Equal(memberUpload.Id, results[0].Id);
            }
        }
示例#21
0
        public async Task <ActionResult> ManagePendingCharges(CompetentAuthority authority)
        {
            using (IWeeeClient client = weeeClient())
            {
                var request = new FetchPendingCharges(authority);
                var managePendingCharges = await client.SendAsync(User.GetAccessToken(), request);

                var model = new ManagePendingChargesViewModel
                {
                    PendingCharges      = managePendingCharges.PendingCharges,
                    CanUserIssueCharges = managePendingCharges.CanUserIssueCharges
                };
                ViewBag.Authority = authority;

                return(View(model));
            }
        }
示例#22
0
        public async Task <ActionResult> DownloadInvoiceFiles(CompetentAuthority authority, Guid id)
        {
            if (authority != CompetentAuthority.England)
            {
                string errorMessage = "Invoice files can only be downloaded for invoice runs related to the Environment Agency.";
                throw new InvalidOperationException(errorMessage);
            }

            FileInfo fileInfo;

            using (IWeeeClient client = weeeClient())
            {
                FetchInvoiceRunIbisZipFile request = new FetchInvoiceRunIbisZipFile(id);
                fileInfo = await client.SendAsync(User.GetAccessToken(), request);
            }

            return(File(fileInfo.Data, "text/plain", fileInfo.FileName));
        }
示例#23
0
        public void Update(Country country, CompetentAuthority competentAuthority, EntryOrExitPoint exitPoint)
        {
            Guard.ArgumentNotNull(() => country, country);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => exitPoint, exitPoint);

            if (country.Id != competentAuthority.Country.Id || country.Id != exitPoint.Country.Id)
            {
                var message =
                    string.Format(
                        @"The country of the export state must be the same as the competent authority country and exit point country.
                                Country: {0} Competent Authority: {1} Exit Point: {2}", country.Id, competentAuthority.Country.Id, exitPoint.Country.Id);
                throw new InvalidOperationException(message);
            }

            Country = country;
            CompetentAuthority = competentAuthority;
            ExitPoint = exitPoint;
        }
示例#24
0
        public void Update(Country country, CompetentAuthority competentAuthority, EntryOrExitPoint exitPoint)
        {
            Guard.ArgumentNotNull(() => country, country);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => exitPoint, exitPoint);

            if (country.Id != competentAuthority.Country.Id || country.Id != exitPoint.Country.Id)
            {
                var message =
                    string.Format(
                        @"The country of the export state must be the same as the competent authority country and exit point country.
                                Country: {0} Competent Authority: {1} Exit Point: {2}", country.Id, competentAuthority.Country.Id, exitPoint.Country.Id);
                throw new InvalidOperationException(message);
            }

            Country            = country;
            CompetentAuthority = competentAuthority;
            ExitPoint          = exitPoint;
        }
示例#25
0
        public async Task FetchInvoiceRunsAsync_Always_EagerLoadsIssuedByUser()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser  user   = helper.GetOrCreateUser("TestUser");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id   = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority = new CompetentAuthority();
                databaseAuthority.Id                 = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority.Name               = "Test Authority 1";
                databaseAuthority.Abbreviation       = "T1";
                databaseAuthority.Country            = country;
                databaseAuthority.Email              = "TestEmailAddress";
                databaseAuthority.AnnualChargeAmount = 0;
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority);

                InvoiceRun invoiceRun = new InvoiceRun();
                invoiceRun.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRun.CompetentAuthority = databaseAuthority;
                invoiceRun.IssuedByUserId     = user.Id;
                invoiceRun.IssuedDate         = new DateTime(2015, 1, 2);
                wrapper.Model.InvoiceRuns.Add(invoiceRun);

                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority.Id);

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList <Domain.Charges.InvoiceRun> results = await dataAccess.FetchInvoiceRunsAsync(domainAuthority);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.NotNull(results[0].IssuedByUser);
            }
        }
示例#26
0
        public async Task GetIssuedCharges_Always_PopulatesViewBagWithAuthority()
        {
            // Arrange
            CompetentAuthority authority = A.Dummy <CompetentAuthority>();

            ChargeController controller = new ChargeController(
                A.Dummy <IAppConfiguration>(),
                A.Dummy <BreadcrumbService>(),
                () => A.Dummy <IWeeeClient>());

            // Act
            ActionResult result = await controller.IssuedCharges(authority);

            // Assert
            ViewResult viewResult = result as ViewResult;

            Assert.NotNull(viewResult);

            Assert.Equal(authority, viewResult.ViewBag.Authority);
        }
示例#27
0
        public NotificationCustomsOfficeTests()
        {
            transportRoute = new TransportRoute(Guid.Empty);

            europeanCountry1 = CreateCountry(new Guid("FB908C44-7AF1-4894-A0A5-860338468DFA"), true);
            europeanCountry2 = CreateCountry(new Guid("8057CD56-A12C-4C7D-BED4-B12D98DCADAB"), true);
            europeanCountry3 = CreateCountry(new Guid("BC0F57D1-6E22-4A15-A39E-1F34C91E49C6"), true);

            nonEuCountry1 = CreateCountry(new Guid("E9738924-B1EC-46E8-B45F-67D990E29D67"), false);
            nonEuCountry2 = CreateCountry(new Guid("04113907-94AF-41DB-A239-10803E067F68"), false);

            europeanCompetentAuthority1 = CreateCompetentAuthority(new Guid("532051C7-145E-4BA5-B950-CFC199B358A7"), europeanCountry1);
            europeanCompetentAuthority2 = CreateCompetentAuthority(new Guid("D274D346-E0F3-48EF-A54E-872319E37A97"), europeanCountry2);
            europeanCompetentAuthority3 = CreateCompetentAuthority(new Guid("02D11536-8564-4BAF-87A6-36CBAE7F6163"),
                                                                   europeanCountry3);

            nonEuCompetentAuthority1 = CreateCompetentAuthority(new Guid("2842CAAE-B34D-4311-A1DE-286EEF492AD6"), nonEuCountry1);
            nonEuCompetentAuthority2 = CreateCompetentAuthority(new Guid("F84CF9EF-A98A-4B8F-B4EC-C3185833226B"), nonEuCountry2);

            SetTransitStates();
        }
        public NotificationCustomsOfficeTests()
        {
            transportRoute = new TransportRoute(Guid.Empty);

            europeanCountry1 = CreateCountry(new Guid("FB908C44-7AF1-4894-A0A5-860338468DFA"), true);
            europeanCountry2 = CreateCountry(new Guid("8057CD56-A12C-4C7D-BED4-B12D98DCADAB"), true);
            europeanCountry3 = CreateCountry(new Guid("BC0F57D1-6E22-4A15-A39E-1F34C91E49C6"), true);

            nonEuCountry1 = CreateCountry(new Guid("E9738924-B1EC-46E8-B45F-67D990E29D67"), false);
            nonEuCountry2 = CreateCountry(new Guid("04113907-94AF-41DB-A239-10803E067F68"), false);

            europeanCompetentAuthority1 = CreateCompetentAuthority(new Guid("532051C7-145E-4BA5-B950-CFC199B358A7"), europeanCountry1);
            europeanCompetentAuthority2 = CreateCompetentAuthority(new Guid("D274D346-E0F3-48EF-A54E-872319E37A97"), europeanCountry2);
            europeanCompetentAuthority3 = CreateCompetentAuthority(new Guid("02D11536-8564-4BAF-87A6-36CBAE7F6163"),
                europeanCountry3);

            nonEuCompetentAuthority1 = CreateCompetentAuthority(new Guid("2842CAAE-B34D-4311-A1DE-286EEF492AD6"), nonEuCountry1);
            nonEuCompetentAuthority2 = CreateCompetentAuthority(new Guid("F84CF9EF-A98A-4B8F-B4EC-C3185833226B"), nonEuCountry2);

            SetTransitStates();
        }
示例#29
0
        public async Task GetIssuedCharges_Always_CallsApiAndPopulatesViewModel()
        {
            // Arrange
            CompetentAuthority authority = A.Dummy <CompetentAuthority>();

            IWeeeClient weeeClient = A.Fake <IWeeeClient>();

            List <int> complianceYears = A.Dummy <List <int> >();

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <FetchComplianceYearsWithInvoices> ._))
            .WhenArgumentsMatch(a => a.Get <FetchComplianceYearsWithInvoices>("request").Authority == authority)
            .Returns(complianceYears);

            List <SchemeData> schemes = A.Dummy <List <SchemeData> >();

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <FetchSchemesWithInvoices> ._))
            .WhenArgumentsMatch(a => a.Get <FetchSchemesWithInvoices>("request").Authority == authority)
            .Returns(schemes);

            ChargeController controller = new ChargeController(
                A.Dummy <IAppConfiguration>(),
                A.Dummy <BreadcrumbService>(),
                () => weeeClient);

            // Act
            ActionResult result = await controller.IssuedCharges(authority);

            // Assert
            ViewResult viewResult = result as ViewResult;

            Assert.NotNull(viewResult);

            IssuedChargesViewModel viewModel = viewResult.Model as IssuedChargesViewModel;

            Assert.NotNull(viewModel);

            Assert.Equal(complianceYears, viewModel.ComplianceYears);
            Assert.Equal(schemes, viewModel.Schemes);
        }
示例#30
0
        public ActionResult ChooseActivity(CompetentAuthority authority, ChooseActivityViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Authority = authority;
                return(View(viewModel));
            }

            switch (viewModel.SelectedActivity.Value)
            {
            case Activity.ManagePendingCharges:
                return(RedirectToAction("ManagePendingCharges", new { authority }));

            case Activity.ManageIssuedCharges:
                return(RedirectToAction("IssuedCharges", new { authority }));

            case Activity.ViewInvoiceRunHistory:
                return(RedirectToAction("InvoiceRuns", new { authority }));

            default:
                throw new NotSupportedException();
            }
        }
        public ActionResult ChooseActivity(CompetentAuthority authority, ChooseActivityViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Authority = authority;
                return View(viewModel);
            }

            switch (viewModel.SelectedActivity.Value)
            {
                case Activity.ManagePendingCharges:
                    return RedirectToAction("ManagePendingCharges", new { authority });

                case Activity.ManageIssuedCharges:
                    return RedirectToAction("IssuedCharges", new { authority });

                case Activity.ViewInvoiceRunHistory:
                    return RedirectToAction("InvoiceRuns", new { authority });

                default:
                    throw new NotSupportedException();
            }
        }
        public async Task FetchSubmittedNonInvoicedMemberUploadsAsync_WithSpecifiedAuthority_OnlyReturnsNonInvoicedMemberUploadsForTheSpecifiedAuthority()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
              
                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority1 = new CompetentAuthority();
                databaseAuthority1.Id = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority1.Name = "Test Authority 1";
                databaseAuthority1.Abbreviation = "T1";
                databaseAuthority1.Country = country;
                databaseAuthority1.Email = "TestEmailAddress";
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority1);
                
                var scheme = helper.CreateScheme();
                
                scheme.CompetentAuthorityId = databaseAuthority1.Id;             
                var memberUpload = helper.CreateSubmittedMemberUpload(scheme);              
                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority1 = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority1.Id);
                CommonDataAccess dataAccess = new CommonDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList<Domain.Scheme.MemberUpload> results = await dataAccess.FetchSubmittedNonInvoicedMemberUploadsAsync(domainAuthority1);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.Equal(memberUpload.Id, results[0].Id);
            }
        }
        public async Task<ActionResult> DownloadInvoiceFiles(CompetentAuthority authority, Guid id)
        {
            if (authority != CompetentAuthority.England)
            {
                string errorMessage = "Invoice files can only be downloaded for invoice runs related to the Environment Agency.";
                throw new InvalidOperationException(errorMessage);
            }

            FileInfo fileInfo;
            using (IWeeeClient client = weeeClient())
            {
                FetchInvoiceRunIbisZipFile request = new FetchInvoiceRunIbisZipFile(id);
                fileInfo = await client.SendAsync(User.GetAccessToken(), request);
            }

            return File(fileInfo.Data, "text/plain", fileInfo.FileName);
        }
        public void UpdateTransitStateForNotification(Guid targetTransitStateId, Country country,
            CompetentAuthority competentAuthority,
            EntryOrExitPoint entryPoint,
            EntryOrExitPoint exitPoint,
            int? ordinalPosition)
        {
            var targetTransitState = TransitStatesCollection.Single(ts => ts.Id == targetTransitStateId);

            if (ordinalPosition.HasValue && ordinalPosition < 1)
            {
                ordinalPosition = null;
            }

            var allTransitStatesExceptTarget =
                TransitStatesCollection.Where(ts => ts.Id != targetTransitStateId).ToArray();

            if (allTransitStatesExceptTarget.Any(ts => ts.Country.Id == country.Id))
            {
                throw new InvalidOperationException(
                    string.Format(
                        "Cannot edit a Transit State to put it in the same Country as another in the collection. TransportRoute {0}. Country {1}",
                        Id,
                        country.Name));
            }

            if (ordinalPosition.HasValue &&
                allTransitStatesExceptTarget.Any(ts => ts.OrdinalPosition == ordinalPosition))
            {
                throw new InvalidOperationException(
                    string.Format(
                        "Attempted to edit a Transit State {0} to position {1} for TransportRoute {2}. The TransportRoute already has another Transit State at this position.",
                        targetTransitStateId,
                        ordinalPosition.Value,
                        Id));
            }

            targetTransitState.UpdateTransitState(country, competentAuthority, entryPoint, exitPoint, ordinalPosition);

            CheckAllTransitStatesInEU();
        }
 public ActionResult ChargesSuccessfullyIssued(CompetentAuthority authority, Guid id)
 {
     ViewBag.AllowDownloadOfInvoiceFiles = (authority == CompetentAuthority.England);
     return View(id);
 }
        public async Task<ActionResult> ManagePendingCharges(CompetentAuthority authority, FormCollection formCollection)
        {
            using (IWeeeClient client = weeeClient())
            {
                IssuePendingCharges request = new IssuePendingCharges(authority);
                IssuePendingChargesResult result = await client.SendAsync(User.GetAccessToken(), request);

                if (Request.IsAjaxRequest())
                {
                    var jsonResult = new
                    {
                        Success = result.Errors.Count == 0,
                        InvoiceRunId = result.InvoiceRunId,
                        Errors = result.Errors
                    };
                    return Json(jsonResult);
                }
                else
                {
                    if (result.Errors.Count == 0)
                    {
                        return RedirectToAction("ChargesSuccessfullyIssued", new { authority, id = result.InvoiceRunId.Value });
                    }
                    else
                    {
                        return View("IssueChargesError", result.Errors);
                    }
                }
            }
        }
示例#37
0
 public FetchPendingCharges(CompetentAuthority authority)
 {
     Authority = authority;
 }
示例#38
0
        /// <summary>
        /// Fetches the domain object representing the specified competent authority.
        /// </summary>
        /// <param name="authority"></param>
        /// <returns></returns>
        public async Task <UKCompetentAuthority> FetchCompetentAuthority(CompetentAuthority authority)
        {
            string authorityName = authorityMapping[authority];

            return(await Context.UKCompetentAuthorities.SingleAsync(ca => ca.Name == authorityName));
        }
示例#39
0
 public ActionResult ChooseActivity(CompetentAuthority authority)
 {
     ViewBag.Authority = authority;
     return(View(new ChooseActivityViewModel()));
 }
 private async Task<IEnumerable<string>> GetSchemesWithInvoices(CompetentAuthority authority)
 {
     FetchSchemesWithInvoices request = new FetchSchemesWithInvoices(authority);
     using (IWeeeClient client = weeeClient())
     {
         return await client.SendAsync(User.GetAccessToken(), request);
     }
 }
 public ActionResult ChooseActivity(CompetentAuthority authority)
 {
     ViewBag.Authority = authority;
     return View(new ChooseActivityViewModel());
 }
示例#42
0
 public FetchSchemesWithInvoices(CompetentAuthority authority)
 {
     Authority = authority;
 }
        public async Task<ActionResult> DownloadIssuedChargesCsv(CompetentAuthority authority, int complianceYear, string schemeName)
        {
            FileInfo file;

            using (IWeeeClient client = weeeClient())
            {
                FetchIssuedChargesCsv request = new FetchIssuedChargesCsv(authority, complianceYear, schemeName);
                file = await client.SendAsync(User.GetAccessToken(), request);
            }

            return File(file.Data, "text/csv", file.FileName);
        }
示例#44
0
 public ActionResult ChargesSuccessfullyIssued(CompetentAuthority authority, Guid id)
 {
     ViewBag.AllowDownloadOfInvoiceFiles = (authority == CompetentAuthority.England);
     return(View(id));
 }
示例#45
0
 public FetchIssuedChargesCsv(CompetentAuthority authority, int complianceYear, Guid?schemeId)
 {
     Authority      = authority;
     ComplianceYear = complianceYear;
     SchemeId       = schemeId;
 }
        public async Task<ActionResult> InvoiceRuns(CompetentAuthority authority)
        {
            IReadOnlyList<InvoiceRunInfo> invoiceRuns;
            using (IWeeeClient client = weeeClient())
            {
                FetchInvoiceRuns request = new FetchInvoiceRuns(authority);
                invoiceRuns = await client.SendAsync(User.GetAccessToken(), request);
            }

            ViewBag.AllowDownloadOfInvoiceFiles = (authority == CompetentAuthority.England);
            return View(invoiceRuns);
        }
        public async Task<ActionResult> ManagePendingCharges(CompetentAuthority authority)
        {
            using (IWeeeClient client = weeeClient())
            {
                var request = new FetchPendingCharges(authority);
                var managePendingCharges = await client.SendAsync(User.GetAccessToken(), request);

                var model = new ManagePendingChargesViewModel
                {
                    PendingCharges = managePendingCharges.PendingCharges,
                    CanUserIssueCharges = managePendingCharges.CanUserIssueCharges
                };
                ViewBag.Authority = authority;

                return View(model);
            }
        }
        public async Task FetchInvoiceRunsAsync_Always_ReturnsResultsOrderedByIssuedDateDescending()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser user = helper.GetOrCreateUser("TestUser");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority = new CompetentAuthority();
                databaseAuthority.Id = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority.Name = "Test Authority 1";
                databaseAuthority.Abbreviation = "T1";
                databaseAuthority.Country = country;
                databaseAuthority.Email = "TestEmailAddress";
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority);

                InvoiceRun invoiceRun1 = new InvoiceRun();
                invoiceRun1.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRun1.CompetentAuthority = databaseAuthority;
                invoiceRun1.IssuedByUserId = user.Id;
                invoiceRun1.IssuedDate = new DateTime(2015, 1, 2);
                wrapper.Model.InvoiceRuns.Add(invoiceRun1);

                InvoiceRun invoiceRun2 = new InvoiceRun();
                invoiceRun2.Id = new Guid("728CDF55-1C3C-4BE0-80CB-0BC82CC9DFA3");
                invoiceRun2.CompetentAuthority = databaseAuthority;
                invoiceRun2.IssuedByUserId = user.Id;
                invoiceRun2.IssuedDate = new DateTime(2015, 1, 1);
                wrapper.Model.InvoiceRuns.Add(invoiceRun2);

                InvoiceRun invoiceRun3 = new InvoiceRun();
                invoiceRun3.Id = new Guid("B235CD4F-8188-4BC0-ADA2-55FD6B34BC01");
                invoiceRun3.CompetentAuthority = databaseAuthority;
                invoiceRun3.IssuedByUserId = user.Id;
                invoiceRun3.IssuedDate = new DateTime(2015, 1, 3);
                wrapper.Model.InvoiceRuns.Add(invoiceRun3);

                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority.Id);

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList<Domain.Charges.InvoiceRun> results = await dataAccess.FetchInvoiceRunsAsync(domainAuthority);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(3, results.Count);
                Assert.Collection(results,
                    r1 => Assert.Equal(new DateTime(2015, 1, 3), r1.IssuedDate),
                    r2 => Assert.Equal(new DateTime(2015, 1, 2), r2.IssuedDate),
                    r3 => Assert.Equal(new DateTime(2015, 1, 1), r3.IssuedDate));
            }
        }
        public async Task FetchInvoiceRunsAsync_Always_EagerLoadsIssuedByUser()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser user = helper.GetOrCreateUser("TestUser");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority = new CompetentAuthority();
                databaseAuthority.Id = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority.Name = "Test Authority 1";
                databaseAuthority.Abbreviation = "T1";
                databaseAuthority.Country = country;
                databaseAuthority.Email = "TestEmailAddress";
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority);

                InvoiceRun invoiceRun = new InvoiceRun();
                invoiceRun.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRun.CompetentAuthority = databaseAuthority;
                invoiceRun.IssuedByUserId = user.Id;
                invoiceRun.IssuedDate = new DateTime(2015, 1, 2);
                wrapper.Model.InvoiceRuns.Add(invoiceRun);

                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority.Id);

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList<Domain.Charges.InvoiceRun> results = await dataAccess.FetchInvoiceRunsAsync(domainAuthority);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.NotNull(results[0].IssuedByUser);
            }
        }
        public async Task<ActionResult> IssuedCharges(CompetentAuthority authority, IssuedChargesViewModel viewModel)
        {
            ViewBag.Authority = authority;
            ViewBag.TriggerDownload = ModelState.IsValid;

            viewModel.ComplianceYears = await GetComplianceYearsWithInvoices(authority);
            viewModel.SchemeNames = await GetSchemesWithInvoices(authority);

            return View(viewModel);
        }