public async Task HandleAsync_SendsEmailToCompetentAuthorityNotificationAddress()
        {
            // Arrange
            string emailAddress = "*****@*****.**";
            var competentAuthority = new UKCompetentAuthority(Guid.NewGuid(), "Name", "Abbreviation", A.Dummy<Country>(), emailAddress);

            Scheme scheme = A.Fake<Scheme>();
            A.CallTo(() => scheme.CompetentAuthority)
                .Returns(competentAuthority);

            MemberUpload memberUpload = A.Fake<MemberUpload>();
            A.CallTo(() => memberUpload.Scheme)
                .Returns(scheme);
            A.CallTo(() => memberUpload.ComplianceYear)
                .Returns(2015);

            var schemeSubmissionEvent = new SchemeMemberSubmissionEvent(memberUpload);

            var emailService = A.Fake<IWeeeEmailService>();
            var handler = new SchemeMemberSubmissionEventHandler(emailService);

            // Act
            await handler.HandleAsync(schemeSubmissionEvent);

            // Assert
            A.CallTo(() => emailService.SendSchemeMemberSubmitted(emailAddress, A<string>._, A<int>._, A<int>._))
                .MustHaveHappened(Repeated.Exactly.Once);
        }
        private ImportNotification CreateImportNotification(Guid id, UKCompetentAuthority competentAuthority, string notificationNumber)
        {
            var importNotification = new ImportNotification(NotificationType.Recovery, competentAuthority, notificationNumber);

            EntityHelper.SetEntityId(importNotification, id);
            return(importNotification);
        }
Example #3
0
        public async void ProcessXmlfile_BusinessErrors_TriesToCalculateCharges()
        {
            IEnumerable <MemberUploadError> errors = new[]
            {
                new MemberUploadError(ErrorLevel.Error, UploadErrorType.Business, "any description"),
            };

            var competentAuthority = new UKCompetentAuthority(Guid.NewGuid(), A.Dummy <string>(), "EA", A.Dummy <Country>(), A.Dummy <string>(), 100);

            var scheme = schemesDbSet.ElementAt(0);

            scheme.UpdateScheme(
                "Test scheme",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy <ObligationType>(),
                competentAuthority);

            decimal?totalCharges = 0;

            SetupSchemeTypeComplianceYear();
            A.CallTo(() => xmlValidator.Validate(Message)).Returns(errors);

            await handler.HandleAsync(Message);

            A.CallTo(() => totalChargeCalculator.TotalCalculatedCharges(Message, scheme, 2019, true, ref totalCharges)).MustHaveHappened(Repeated.Exactly.Once);
        }
Example #4
0
        public void Constructor_WithMemberUploadForDifferentAuthority_ThrowsInvalidOperationException()
        {
            // Arrange
            UKCompetentAuthority authorityA = A.Dummy <UKCompetentAuthority>();
            UKCompetentAuthority authorityB = A.Dummy <UKCompetentAuthority>();

            Scheme schemeForAuthorityA = A.Fake <Scheme>();

            A.CallTo(() => schemeForAuthorityA.CompetentAuthority).Returns(authorityA);

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

            MemberUpload memberUploadForAuthorityA = new MemberUpload(
                new Guid("A2A01A99-A97D-4219-9060-D7CDF7435114"),
                schemeForAuthorityA,
                "data",
                "filename");

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

            memberUploads.Add(memberUploadForAuthorityA);

            // Act
            Func <InvoiceRun> testCode = () => new InvoiceRun(authorityB, memberUploads, A.Dummy <User>());

            // Assert
            Assert.Throws <InvalidOperationException>(testCode);
        }
Example #5
0
 public byte[] GenerateFinancialGuaranteeDocument(UKCompetentAuthority competentAuthority)
 {
     using (var memoryStream = DocumentHelper.ReadDocumentStreamShared(GetFinancialGuaranteeDocumentName(competentAuthority)))
     {
         return(memoryStream.ToArray());
     }
 }
Example #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));
            }
        }
 public byte[] GenerateFinancialGuaranteeDocument(UKCompetentAuthority competentAuthority)
 {
     using (var memoryStream = DocumentHelper.ReadDocumentStreamShared(GetFinancialGuaranteeDocumentName(competentAuthority)))
     {
         return memoryStream.ToArray();
     }
 }
        public async Task HandleAsync_SendsEmailToCompetentAuthorityNotificationAddress()
        {
            // Arrange
            string emailAddress       = "*****@*****.**";
            var    competentAuthority = new UKCompetentAuthority(Guid.NewGuid(), "Name", "Abbreviation", A.Dummy <Country>(), emailAddress, 0);

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

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

            MemberUpload memberUpload = A.Fake <MemberUpload>();

            A.CallTo(() => memberUpload.Scheme)
            .Returns(scheme);
            A.CallTo(() => memberUpload.ComplianceYear)
            .Returns(2015);

            var schemeSubmissionEvent = new SchemeMemberSubmissionEvent(memberUpload);

            var emailService = A.Fake <IWeeeEmailService>();
            var handler      = new SchemeMemberSubmissionEventHandler(emailService);

            // Act
            await handler.HandleAsync(schemeSubmissionEvent);

            // Assert
            A.CallTo(() => emailService.SendSchemeMemberSubmitted(emailAddress, A <string> ._, A <int> ._, A <int> ._))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
Example #9
0
        public async Task HandleAsync_SendsEmailWithDataReturnYear()
        {
            // Arrange
            string emailAddress       = "*****@*****.**";
            var    competentAuthority = new UKCompetentAuthority(Guid.NewGuid(), "Name", "Abbreviation", A.Dummy <Country>(), emailAddress, 0);

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

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

            Quarter quarter = new Quarter(2015, QuarterType.Q1);

            DataReturn        dataReturn        = new DataReturn(scheme, quarter);
            DataReturnVersion dataReturnVersion = new DataReturnVersion(dataReturn);

            dataReturnVersion.Submit("testUserId");

            var schemeSubmissionEvent = new SchemeDataReturnSubmissionEvent(dataReturnVersion);

            var emailService = A.Fake <IWeeeEmailService>();
            var dataAccess   = A.Dummy <ISchemeDataReturnSubmissionEventHandlerDataAccess>();
            var handler      = new SchemeDataReturnSubmissionEventHandler(emailService, dataAccess);

            // Act
            await handler.HandleAsync(schemeSubmissionEvent);

            // Assert
            A.CallTo(() => emailService.SendSchemeDataReturnSubmitted(A <string> ._, A <string> ._, 2015, A <int> ._, A <bool> ._))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
Example #10
0
        public async Task HandleAsync_InvokesDataAccess_GetNumberOfDataReturnSubmissionsAsync_WithCorrectParameters()
        {
            // Arrange
            string emailAddress       = "*****@*****.**";
            var    competentAuthority = new UKCompetentAuthority(Guid.NewGuid(), "Name", "Abbreviation", A.Dummy <Country>(), emailAddress, 0);

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

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

            Quarter quarter = new Quarter(2016, QuarterType.Q2);

            DataReturn        dataReturn        = new DataReturn(scheme, quarter);
            DataReturnVersion dataReturnVersion = new DataReturnVersion(dataReturn);

            dataReturnVersion.Submit("testUserId");

            var dataAccess   = A.Fake <ISchemeDataReturnSubmissionEventHandlerDataAccess>();
            var emailService = A.Fake <IWeeeEmailService>();
            var handler      = new SchemeDataReturnSubmissionEventHandler(emailService, dataAccess);

            var schemeSubmissionEvent = new SchemeDataReturnSubmissionEvent(dataReturnVersion);

            // Act
            await handler.HandleAsync(schemeSubmissionEvent);

            // Assert
            A.CallTo(() => dataAccess.GetNumberOfDataReturnSubmissionsAsync(scheme, 2016, QuarterType.Q2))
            .MustHaveHappened();
        }
        private string GetFileName(UKCompetentAuthority competentAuthority)
        {
            string filename = string.Empty;

            if (competentAuthority == UKCompetentAuthority.England)
            {
                filename = "EaAddress.pdf";
            }

            if (competentAuthority == UKCompetentAuthority.NorthernIreland)
            {
                filename = "NieaAddress.pdf";
            }

            if (competentAuthority == UKCompetentAuthority.Scotland)
            {
                filename = "SepaAddress.pdf";
            }

            if (competentAuthority == UKCompetentAuthority.Wales)
            {
                filename = "NrwAddress.pdf";
            }

            return filename;
        }
 private static bool IsNumberValid(UKCompetentAuthority competentAuthority, int number)
 {
     return (competentAuthority == UKCompetentAuthority.England && number < EaNumberSystemStart)
         || (competentAuthority == UKCompetentAuthority.Scotland && number < SepaNumberSystemStart)
         || (competentAuthority == UKCompetentAuthority.NorthernIreland && number < NieaNumberSystemStart)
         || (competentAuthority == UKCompetentAuthority.Wales && number < NrwNumberSystemStart);
 }
 public byte[] GeneratePostageLabel(UKCompetentAuthority competentAuthority)
 {
     using (var memoryStream = DocumentHelper.ReadDocumentStreamShared(GetFileName(competentAuthority)))
     {
         return memoryStream.ToArray();
     }
 }
Example #14
0
        public InvoiceRun(
            UKCompetentAuthority competentAuthority,
            IReadOnlyList <MemberUpload> memberUploads,
            User issuingUser)
        {
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => memberUploads, memberUploads);
            Guard.ArgumentNotNull(() => issuingUser, issuingUser);

            CompetentAuthority = competentAuthority;
            IssuedDate         = SystemTime.UtcNow;
            IssuedByUser       = issuingUser;

            if (memberUploads.Count == 0)
            {
                string errorMessage = "An invoice run must contain at least one member upload.";
                throw new InvalidOperationException(errorMessage);
            }

            foreach (MemberUpload memberUpload in memberUploads)
            {
                if (memberUpload.Scheme.CompetentAuthority != competentAuthority)
                {
                    string errorMessage = "All member uploads assigned to an invoice run must be related " +
                                          "to schemes with the same authority as the invoice run.";
                    throw new InvalidOperationException(errorMessage);
                }

                memberUpload.AssignToInvoiceRun(this);
            }

            MemberUploads = new List <MemberUpload>(memberUploads);
        }
Example #15
0
        private string GetFileName(UKCompetentAuthority competentAuthority)
        {
            string filename = string.Empty;

            if (competentAuthority == UKCompetentAuthority.England)
            {
                filename = "EaAddress.pdf";
            }

            if (competentAuthority == UKCompetentAuthority.NorthernIreland)
            {
                filename = "NieaAddress.pdf";
            }

            if (competentAuthority == UKCompetentAuthority.Scotland)
            {
                filename = "SepaAddress.pdf";
            }

            if (competentAuthority == UKCompetentAuthority.Wales)
            {
                filename = "NrwAddress.pdf";
            }

            return(filename);
        }
 private static string CreateSqlQuery(UKCompetentAuthority competentAuthority)
 {
     var stringBuilder = new StringBuilder();
     stringBuilder.Append("SELECT NEXT VALUE FOR ");
     stringBuilder.AppendFormat(NotificationNumberSequenceFormat, EnumHelper.GetShortName(competentAuthority));
     return stringBuilder.ToString();
 }
 public async Task<IEnumerable<ExportNotificationOwnerDisplay>> GetInternalUnsubmittedByCompetentAuthority(UKCompetentAuthority competentAuthority)
 {
     return await context.Database.SqlQuery<ExportNotificationOwnerDisplay>(@"
         SELECT 
             N.Id AS NotificationId,
             N.NotificationNumber AS Number,
             E.Name AS ExporterName,
             I.Name AS ImporterName,
             P.Name AS ProducerName,
             ANU.FirstName + ' ' + ANU.Surname AS OwnerName
         FROM 
             [Notification].[Notification] N
             INNER JOIN [Notification].[NotificationAssessment] NA ON N.Id = NA.NotificationApplicationId AND NA.Status = 1
             LEFT JOIN [Notification].[Exporter] E ON N.Id = E.NotificationId
             LEFT JOIN [Notification].[Importer] I ON N.Id = I.NotificationId
             LEFT JOIN [Notification].[ProducerCollection] PC ON N.Id = PC.NotificationId
             LEFT JOIN [Notification].[Producer] P ON PC.Id = P.ProducerCollectionId AND P.IsSiteOfExport = 1
             INNER JOIN [Person].[InternalUser] IU ON IU.UserId = N.UserId
             INNER JOIN [Identity].[AspNetUsers] ANU ON ANU.Id = IU.UserId
         WHERE 
             N.CompetentAuthority = @Ca
         ORDER BY
             N.NotificationNumber ASC",
         new SqlParameter("@Ca", competentAuthority)).ToListAsync();
 }
        public async Task HandleAsync_SendsEmailWithDataReturnYear()
        {
            // Arrange
            string emailAddress = "*****@*****.**";
            var competentAuthority = new UKCompetentAuthority(Guid.NewGuid(), "Name", "Abbreviation", A.Dummy<Country>(), emailAddress);

            Scheme scheme = A.Fake<Scheme>();
            A.CallTo(() => scheme.CompetentAuthority)
                .Returns(competentAuthority);

            Quarter quarter = new Quarter(2015, QuarterType.Q1);

            DataReturn dataReturn = new DataReturn(scheme, quarter);
            DataReturnVersion dataReturnVersion = new DataReturnVersion(dataReturn);
            dataReturnVersion.Submit("testUserId");

            var schemeSubmissionEvent = new SchemeDataReturnSubmissionEvent(dataReturnVersion);

            var emailService = A.Fake<IWeeeEmailService>();
            var dataAccess = A.Dummy<ISchemeDataReturnSubmissionEventHandlerDataAccess>();
            var handler = new SchemeDataReturnSubmissionEventHandler(emailService, dataAccess);

            // Act
            await handler.HandleAsync(schemeSubmissionEvent);

            // Assert
            A.CallTo(() => emailService.SendSchemeDataReturnSubmitted(A<string>._, A<string>._, 2015, A<int>._, A<bool>._))
                .MustHaveHappened(Repeated.Exactly.Once);
        }
        public async Task CanOnlyEnterNumbersLessThanSystemStart(NotificationType notificationType,
            UKCompetentAuthority competentAuthority, int number)
        {
            var notification = await factory.CreateLegacy(notificationType, competentAuthority, number);

            Assert.IsType<NotificationApplication>(notification);
        }
Example #20
0
 private static bool IsNumberValid(UKCompetentAuthority competentAuthority, int number)
 {
     return((competentAuthority == UKCompetentAuthority.England && number < EaNumberSystemStart) ||
            (competentAuthority == UKCompetentAuthority.Scotland && number < SepaNumberSystemStart) ||
            (competentAuthority == UKCompetentAuthority.NorthernIreland && number < NieaNumberSystemStart) ||
            (competentAuthority == UKCompetentAuthority.Wales && number < NrwNumberSystemStart));
 }
Example #21
0
 public byte[] GeneratePostageLabel(UKCompetentAuthority competentAuthority)
 {
     using (var memoryStream = DocumentHelper.ReadDocumentStreamShared(GetFileName(competentAuthority)))
     {
         return(memoryStream.ToArray());
     }
 }
Example #22
0
        public async Task HandleAsync_WhereApprovalNumberIsAValueThatAlreadyExists_ReturnsFailureResult()
        {
            // Arrange
            UKCompetentAuthority environmentAgency = A.Dummy <UKCompetentAuthority>();

            typeof(UKCompetentAuthority).GetProperty("Id").SetValue(environmentAgency, new Guid("42D3130C-4CDB-4F74-866A-BFF839A347B5"));

            A.CallTo(() => dataAccess.CheckSchemeApprovalNumberInUseAsync("WEE/ZZ9999ZZ/SCH")).Returns(true);

            // Act
            CreateScheme request = new CreateScheme(
                A.Dummy <Guid>(),
                "New scheme name",
                "WEE/ZZ9999ZZ/SCH",
                "WEE7453956",
                ObligationType.B2B,
                new Guid("559B69CE-865C-465F-89ED-D6A58AA8B0B9"),
                SchemeStatus.Approved);

            CreateOrUpdateSchemeInformationResult result = await handler.HandleAsync(request);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(CreateOrUpdateSchemeInformationResult.ResultType.ApprovalNumberUniquenessFailure, result.Result);
        }
Example #23
0
 public static NotificationMovementsSummary Load(Guid notificationId,
                                                 string notificationNumber,
                                                 NotificationType notificationType,
                                                 int intendedTotalShipments,
                                                 int currentTotalShipments,
                                                 int activeLoadsPermitted,
                                                 int currentActiveLoads,
                                                 decimal intendedQuantity,
                                                 decimal quantityReceived,
                                                 ShipmentQuantityUnits units,
                                                 FinancialGuaranteeStatus financialGuaranteeStatus,
                                                 UKCompetentAuthority competentAuthority,
                                                 NotificationStatus notificationStatus,
                                                 ShipmentQuantity averageTonnageInfo)
 {
     return(new NotificationMovementsSummary
     {
         NotificationId = notificationId,
         NotificationNumber = notificationNumber,
         NotificationType = notificationType,
         IntendedTotalShipments = intendedTotalShipments,
         CurrentTotalShipments = currentTotalShipments,
         ActiveLoadsPermitted = activeLoadsPermitted,
         CurrentActiveLoads = currentActiveLoads,
         IntendedQuantity = intendedQuantity,
         QuantityReceived = quantityReceived,
         Units = units,
         FinancialGuaranteeStatus = financialGuaranteeStatus,
         CompetentAuthority = competentAuthority,
         NotificationStatus = notificationStatus,
         AverageDataUnit = averageTonnageInfo.Units,
         AverageTonnage = averageTonnageInfo.Quantity
     });
 }
Example #24
0
        public async Task <ManagePendingCharges> HandleAsync(Requests.Charges.FetchPendingCharges message)
        {
            authorization.EnsureCanAccessInternalArea(true);

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

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

            var groups = memberUploads.GroupBy(mu => new { mu.Scheme, mu.ComplianceYear });

            List <PendingCharge> pendingCharges = new List <PendingCharge>();

            foreach (var group in groups)
            {
                PendingCharge pendingCharge = new PendingCharge()
                {
                    SchemeName           = group.Key.Scheme.SchemeName,
                    SchemeApprovalNumber = group.Key.Scheme.ApprovalNumber,
                    ComplianceYear       = group.Key.ComplianceYear.Value,
                    TotalGBP             = group.Sum(p => p.TotalCharges),
                    SubmittedDate        = group.FirstOrDefault().SubmittedDate.Value
                };

                pendingCharges.Add(pendingCharge);
            }

            var managePendingCharges = new ManagePendingCharges
            {
                PendingCharges      = pendingCharges,
                CanUserIssueCharges = authorization.CheckUserInRole(Roles.InternalAdmin)
            };

            return(managePendingCharges);
        }
        public async Task<IEnumerable<NotificationAttentionSummary>> GetByCompetentAuthority(UKCompetentAuthority competentAuthority)
        {
            var result = await context.NotificationAssessments
                .Where(x => 
                    x.Status == NotificationStatus.DecisionRequiredBy
                    || x.Status == NotificationStatus.Unlocked
                    || x.Status == NotificationStatus.Reassessment)
                .Join(context.NotificationApplications,
                    assessment => assessment.NotificationApplicationId,
                    notification => notification.Id,
                    (a, n) => new { Assessment = a, Notification = n })
                .Where(x => x.Notification.CompetentAuthority == competentAuthority)
                .Select(x => new
                {
                    x.Notification.Id,
                    x.Notification.NotificationNumber,
                    x.Assessment.Dates.NameOfOfficer,
                    x.Assessment.Dates.AcknowledgedDate
                }).ToArrayAsync();

            return result.Select(x =>
                    NotificationAttentionSummary.Load(x.Id,
                        x.NotificationNumber,
                        x.NameOfOfficer,
                        x.AcknowledgedDate.Value));
        }
Example #26
0
 public async Task <IEnumerable <FinancialGuaranteesData> > GetBlanketBonds(UKCompetentAuthority competentAuthority,
                                                                            string financialGuaranteeReferenceNumber, string exporterName, string importerName,
                                                                            string producerName)
 {
     return(await context.Database.SqlQuery <FinancialGuaranteesData>(@"
         SELECT [ReferenceNumber]
               ,[ApprovedDate]
               ,[ActiveLoadsPermitted]
               ,[CurrentActiveLoads]
               ,[NotificationNumber]
               ,[ExporterName]
               ,[ImporterName]
               ,[ProducerName]
               ,[IsBlanketBond]
               ,[CoverAmount]
               ,[CalculationContinued]
               ,[OverActiveLoads]
           FROM [Reports].[BlanketBonds]
          WHERE [CompetentAuthority] = @ca
            AND (@financialGuaranteeReferenceNumber IS NULL OR [ReferenceNumber] LIKE '%' + @financialGuaranteeReferenceNumber + '%')
            AND (@exporterName IS NULL OR [ExporterName] LIKE '%' + @exporterName + '%')
            AND (@importerName IS NULL OR [ImporterName] LIKE '%' + @importerName + '%')
            AND (@producerName IS NULL OR [ProducerName] LIKE '%' + @producerName + '%')",
                                                                      new SqlParameter("@ca", (int)competentAuthority),
                                                                      new SqlParameter("@financialGuaranteeReferenceNumber", (object)financialGuaranteeReferenceNumber ?? DBNull.Value),
                                                                      new SqlParameter("@exporterName", (object)exporterName ?? DBNull.Value),
                                                                      new SqlParameter("@importerName", (object)importerName ?? DBNull.Value),
                                                                      new SqlParameter("@producerName", (object)producerName ?? DBNull.Value)).ToArrayAsync());
 }
Example #27
0
        public async Task CanOnlyEnterNumbersLessThanSystemStart(NotificationType notificationType,
                                                                 UKCompetentAuthority competentAuthority, int number)
        {
            var notification = await factory.CreateLegacy(notificationType, competentAuthority, number);

            Assert.IsType <NotificationApplication>(notification);
        }
Example #28
0
        public async Task <IEnumerable <DataImportNotification> > Get(DateTime @from, DateTime to,
                                                                      UKCompetentAuthority competentAuthority)
        {
            return(await context.Database.SqlQuery <DataImportNotification>(
                       @"SELECT	[NotificationNumber],
                            [NotificationType],
                            [Status],
                            [Preconsented],
                            [NotificationReceived],
                            [PaymentReceived],
                            [AssessmentStarted],
                            [ApplicationCompleted],
                            [Acknowledged],
                            [DecisionDate],
                            [Consented],
                            [Officer],
                            [ConsentTo]
                    FROM	[Reports].[DataImportNotifications]

                    WHERE	[CompetentAuthorityId] = @ca
                    AND     [NotificationReceived] BETWEEN @from AND @to",
                       new SqlParameter("@ca", (int)competentAuthority),
                       new SqlParameter("@from", from),
                       new SqlParameter("@to", to)).ToArrayAsync());
        }
Example #29
0
        public InvoiceRun(
            UKCompetentAuthority competentAuthority,
            IReadOnlyList<MemberUpload> memberUploads,
            User issuingUser)
        {
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => memberUploads, memberUploads);
            Guard.ArgumentNotNull(() => issuingUser, issuingUser);

            CompetentAuthority = competentAuthority;
            IssuedDate = SystemTime.UtcNow;
            IssuedByUser = issuingUser;

            if (memberUploads.Count == 0)
            {
                string errorMessage = "An invoice run must contain at least one member upload.";
                throw new InvalidOperationException(errorMessage);
            }

            foreach (MemberUpload memberUpload in memberUploads)
            {
                if (memberUpload.Scheme.CompetentAuthority != competentAuthority)
                {
                    string errorMessage = "All member uploads assigned to an invoice run must be related " +
                        "to schemes with the same authority as the invoice run.";
                    throw new InvalidOperationException(errorMessage);
                }

                memberUpload.AssignToInvoiceRun(this);
            }

            MemberUploads = new List<MemberUpload>(memberUploads);
        }
        private UKCompetentAuthority FakeCompetentAuthorityData()
        {
            UKCompetentAuthority competentAuthority =
                new UKCompetentAuthority(Guid.NewGuid(), "Environment Agency", "EA", new Country(Guid.NewGuid(), "UK - England"), "*****@*****.**", 12500.00M);

            return(competentAuthority);
        }
Example #31
0
        public async Task <IEnumerable <Shipment> > Get(DateTime from, DateTime to, UKCompetentAuthority competentAuthority,
                                                        ShipmentsReportDates dateType, ShipmentReportTextFields?textFieldType,
                                                        TextFieldOperator?textFieldOperatorType, string textSearch)
        {
            var textFilter = TextFilterHelper.GetTextFilter(textFieldType, textFieldOperatorType, textSearch);

            textFilter = !string.IsNullOrEmpty(textFilter) ? string.Format("AND {0}", textFilter) : string.Empty;

            var query = @"SELECT DISTINCT 
                    [NotificationNumber],
                    [ImportOrExport],
                    [Exporter],
                    [Importer],
                    [Facility],
                    [BaselOecdCode],
                    [ShipmentNumber],
                    [ActualDateOfShipment],
                    [ConsentFrom],
                    [ConsentTo],
                    [PrenotificationDate],
                    [ReceivedDate],
                    [CompletedDate],
                    [QuantityReceived],
                    [QuantityReceivedUnitId] AS [Units],
                    [ChemicalCompositionTypeId],
                    [ChemicalComposition],
                    [LocalArea],
                    [TotalQuantity],
                    [TotalQuantityUnitsId],
                    [EntryPort],
                    [DestinationCountry],
                    [ExitPort],
                    [OriginatingCountry],
                    [Status],
                    [EwcCodes],
                    [OperationCodes],
                    CASE WHEN YCode IS NULL THEN 'NA' ELSE YCode END AS [YCode],
                    CASE WHEN HCode IS NULL THEN 'NA' ELSE HCode END AS [HCode],
                    CASE WHEN UNClass IS NULL THEN 'NA' ELSE UNClass END AS [UNClass]
                FROM [Reports].[ShipmentsCache]
                WHERE [CompetentAuthorityId] = @ca
                AND (@dateType = 'NotificationReceivedDate' and  [NotificationReceivedDate] BETWEEN @from AND @to
                     OR @dateType = 'ConsentFrom' and  [ConsentFrom] BETWEEN @from AND @to
                     OR @dateType = 'ConsentTo' and  [ConsentTo] BETWEEN @from AND @to
                     OR @dateType = 'ReceivedDate' and  [ReceivedDate] BETWEEN @from AND @to
                     OR @dateType = 'CompletedDate' and  [CompletedDate] BETWEEN @from AND @to
                     OR @dateType = 'ActualDateOfShipment' and  [ActualDateOfShipment] BETWEEN @from AND @to
                     OR @dateType = 'RejectedShipmentDate' and  [RejectedShipmentDate] BETWEEN @from AND @to)
                {0}
                ORDER BY
                    [NotificationNumber],
                    [ShipmentNumber]";

            return(await context.Database.SqlQuery <Shipment>(string.Format(query, textFilter),
                                                              new SqlParameter("@from", from),
                                                              new SqlParameter("@to", to),
                                                              new SqlParameter("@ca", (int)competentAuthority),
                                                              new SqlParameter("@dateType", dateType.ToString())).ToArrayAsync());
        }
        public async Task GetAllInvoicedSchemesHandler_ReturnsSchemes()
        {
            // Arrange
            UKCompetentAuthority competentAuthority = 
                new UKCompetentAuthority(Guid.NewGuid(), "Environment Agency", "EA", new Country(Guid.NewGuid(), "UK - England"), "*****@*****.**");
            var scheme1 = A.Fake<Scheme>();
            A.CallTo(() => scheme1.SchemeName).Returns("Test1");
            A.CallTo(() => scheme1.CompetentAuthority).Returns(competentAuthority);
            var scheme2 = A.Fake<Scheme>();
            A.CallTo(() => scheme2.SchemeName).Returns("Test2");
            A.CallTo(() => scheme2.CompetentAuthority).Returns(competentAuthority);
            var scheme3 = A.Fake<Scheme>();
            A.CallTo(() => scheme3.SchemeName).Returns("Test3");
            A.CallTo(() => scheme3.CompetentAuthority).Returns(competentAuthority);

            InvoiceRun invoice = A.Fake<InvoiceRun>();
           
            var memberUpload1 = A.Fake<MemberUpload>();
            A.CallTo(() => memberUpload1.ComplianceYear).Returns(2015);
            A.CallTo(() => memberUpload1.Scheme).Returns(scheme1);
            A.CallTo(() => memberUpload1.InvoiceRun).Returns(invoice);

            var memberUpload2 = A.Fake<MemberUpload>();
            A.CallTo(() => memberUpload2.ComplianceYear).Returns(2017);
            A.CallTo(() => memberUpload2.Scheme).Returns(scheme2);
            A.CallTo(() => memberUpload2.InvoiceRun).Returns(invoice);

            var memberUpload3 = A.Fake<MemberUpload>();
            A.CallTo(() => memberUpload3.ComplianceYear).Returns(2016);
            A.CallTo(() => memberUpload3.Scheme).Returns(scheme3);
            A.CallTo(() => memberUpload3.InvoiceRun).Returns(invoice);

            ICommonDataAccess dataAccess = A.Fake<ICommonDataAccess>();
            A.CallTo(() => dataAccess.FetchInvoicedMemberUploadsAsync(competentAuthority))
                .Returns(new List<MemberUpload>()
                {
                     memberUpload1,
                    memberUpload2,
                    memberUpload3
                });

            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();
            FetchSchemesWithInvoicesHandler handler = new FetchSchemesWithInvoicesHandler(
               authorization,
               dataAccess);

            FetchSchemesWithInvoices request = new FetchSchemesWithInvoices(CompetentAuthority.England);
            A.CallTo(() => dataAccess.FetchCompetentAuthority(CompetentAuthority.England)).Returns(competentAuthority);
            // Act
            var schemesList = await handler.HandleAsync(request);

            //Assert
            Assert.NotNull(schemesList);
            Assert.Equal(3, schemesList.Count);
            Assert.Collection(schemesList,
                r1 => Assert.Equal("Test1", r1.ToString()),
                r2 => Assert.Equal("Test2", r2.ToString()),
                r3 => Assert.Equal("Test3", r3.ToString()));
        }   
Example #33
0
        public async Task HandleAsync_WithErrorWhenGeneratingIbisFile_DoesNotSaveChanges_AndReturnsError()
        {
            // Arrange
            UKCompetentAuthority authority =
                new UKCompetentAuthority(Guid.NewGuid(), "Environment Agency", "EA", A.Dummy <Country>(), "*****@*****.**", 0);

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

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

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

            MemberUpload memberUpload1 = new MemberUpload(
                A.Dummy <Guid>(),
                A.Dummy <string>(),
                A.Dummy <List <MemberUploadError> >(),
                10,
                2017,
                scheme,
                A.Dummy <string>());

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

            memberUploads.Add(memberUpload1);

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

            A.CallTo(() => dataAccess.FetchCompetentAuthority(CompetentAuthority.England)).Returns(authority);
            A.CallTo(() => dataAccess.FetchSubmittedNonInvoicedMemberUploadsAsync(authority))
            .Returns(memberUploads);

            var errors = new List <string> {
                "error"
            };
            IbisFileDataGeneratorResult ibisFileDataGeneratorResult = new IbisFileDataGeneratorResult(null, errors);

            IIbisFileDataGenerator ibisFileDataGenerator = A.Fake <IIbisFileDataGenerator>();

            A.CallTo(() => ibisFileDataGenerator.CreateFileDataAsync(A <ulong> ._, A <InvoiceRun> ._))
            .Returns(ibisFileDataGeneratorResult);

            IssuePendingChargesHandler handler = new IssuePendingChargesHandler(
                A.Dummy <IWeeeAuthorization>(),
                dataAccess,
                ibisFileDataGenerator,
                A.Dummy <IDomainUserContext>());

            Requests.Charges.IssuePendingCharges request = new Requests.Charges.IssuePendingCharges(CompetentAuthority.England);

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

            // Assert
            A.CallTo(() => dataAccess.SaveAsync(A <InvoiceRun> ._))
            .MustNotHaveHappened();

            Assert.Null(result.InvoiceRunId);
            Assert.NotEmpty(result.Errors);
        }
Example #34
0
        public async Task HandleAsync_SettingEASchemeIbisCustomerReferenceNumberToAValueThatAlreadyExistsForAnotherNonEAScheme_ReturnsSuccessResult()
        {
            // Arrange
            UKCompetentAuthority environmentAgency = A.Dummy <UKCompetentAuthority>();

            typeof(UKCompetentAuthority).GetProperty("Id").SetValue(environmentAgency, new Guid("42D3130C-4CDB-4F74-866A-BFF839A347B5"));

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

            typeof(UKCompetentAuthority).GetProperty("Id").SetValue(devlovedAgency, new Guid("76BE711C-191D-4648-AFE7-4404D287535C"));

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

            typeof(Entity).GetProperty("Id").SetValue(scheme, new Guid("5AE25C37-88C8-4646-8793-DB4C2F4EF0E5"));
            scheme.UpdateScheme(
                "Scheme 1",
                "WEE/AA0000AA/SCH",
                "WEE7453846",
                Domain.Obligation.ObligationType.B2C,
                environmentAgency);
            scheme.SetStatus(Domain.Scheme.SchemeStatus.Approved);

            Scheme otherScheme = new Scheme(A.Dummy <Organisation>());

            typeof(Entity).GetProperty("Id").SetValue(otherScheme, new Guid("C78D98A9-E33A-4E20-88D3-F1C99D5165B1"));
            otherScheme.UpdateScheme(
                "Scheme 2",
                "WEE/BB1111BB/SCH",
                "WEE8643759",
                Domain.Obligation.ObligationType.B2C,
                devlovedAgency);
            otherScheme.SetStatus(Domain.Scheme.SchemeStatus.Approved);

            A.CallTo(() => dataAccess.FetchSchemeAsync(new Guid("5AE25C37-88C8-4646-8793-DB4C2F4EF0E5"))).Returns(scheme);
            A.CallTo(() => dataAccess.FetchEnvironmentAgencyAsync()).Returns(environmentAgency);
            A.CallTo(() => dataAccess.FetchNonRejectedEnvironmentAgencySchemesAsync())
            .Returns(new List <Scheme>()
            {
                scheme
            });

            // Act
            CreateScheme request = new CreateScheme(
                scheme.Id,
                "Scheme 1",
                "WEE/AA0000AA/SCH",
                "WEE8643759",
                ObligationType.B2C,
                new Guid("42D3130C-4CDB-4F74-866A-BFF839A347B5"),
                SchemeStatus.Approved);

            CreateOrUpdateSchemeInformationResult result = await handler.HandleAsync(request);

            A.CallTo(() => dataAccess.SaveAsync()).MustHaveHappened();

            // Assert
            Assert.NotNull(result);
            Assert.Equal(CreateOrUpdateSchemeInformationResult.ResultType.Success, result.Result);
        }
Example #35
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 void InvalidAgencyEmailAddresses(UKCompetentAuthority competentAuthority, string email)
        {
            viewModel.CompetentAuthority = competentAuthority;
            viewModel.Email = email;
            var validationResult = ViewModelValidator.ValidateViewModel(viewModel);

            Assert.Equal(1, validationResult.Count);
        }
 public async Task<NotificationApplication> CreateNew(NotificationType notificationType,
     UKCompetentAuthority competentAuthority)
 {
     var nextNotificationNumber = await numberGenerator.GetNextNotificationNumber(competentAuthority);
     var notification = new NotificationApplication(userContext.UserId, notificationType, competentAuthority,
         nextNotificationNumber);
     return notification;
 }
Example #38
0
        public void InvalidAgencyEmailAddresses(UKCompetentAuthority competentAuthority, string email)
        {
            viewModel.CompetentAuthority = competentAuthority;
            viewModel.Email = email;
            var validationResult = ViewModelValidator.ValidateViewModel(viewModel);

            Assert.Single(validationResult);
        }
        private static string CreateSqlQuery(UKCompetentAuthority competentAuthority)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.Append("SELECT NEXT VALUE FOR ");
            stringBuilder.AppendFormat(NotificationNumberSequenceFormat, EnumHelper.GetShortName(competentAuthority));
            return(stringBuilder.ToString());
        }
Example #40
0
 public CreateInternalUser(string userId, string jobTitle, Guid localAreaId,
                           UKCompetentAuthority competentAuthority)
 {
     UserId             = userId;
     JobTitle           = jobTitle;
     LocalAreaId        = localAreaId;
     CompetentAuthority = competentAuthority;
 }
 /// <summary>
 /// Fetches all invoice runs for the specified authority.
 /// Results are ordered by issued date descending.
 /// </summary>
 /// <param name="authority"></param>
 /// <returns></returns>
 public async Task <IReadOnlyList <InvoiceRun> > FetchInvoiceRunsAsync(UKCompetentAuthority authority)
 {
     return(await context.InvoiceRuns
            .Include(ir => ir.IssuedByUser)
            .Where(ir => ir.CompetentAuthority.Id == authority.Id)
            .OrderByDescending(ir => ir.IssuedDate)
            .ToListAsync());
 }
        public async Task ReturnsCorrectFormat(string expected, UKCompetentAuthority competentAuthority, int notificationNumber, NotificationType notificationType, int movementNumber)
        {
            var notification = new NotificationApplication(Guid.NewGuid(), notificationType, competentAuthority, notificationNumber);
            A.CallTo(() => notificationRepository.GetById(notificationId)).Returns(notification);

            var result = await certificateOfRecoveryName.GetValue(new Movement(movementNumber, notificationId, AnyDate, userId));

            Assert.Equal(expected, result);
        }
        private NotificationApplication CreateNotificationApplication(Guid id, UKCompetentAuthority competentAuthority, WasteType wasteType)
        {
            var notificationApplication = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, competentAuthority, 0);

            EntityHelper.SetEntityId(notificationApplication, id);

            notificationApplication.SetWasteType(wasteType);

            return(notificationApplication);
        }
Example #44
0
        public async Task <NotificationApplication> CreateNew(NotificationType notificationType,
                                                              UKCompetentAuthority competentAuthority)
        {
            var nextNotificationNumber = await numberGenerator.GetNextNotificationNumber(competentAuthority);

            var notification = new NotificationApplication(userContext.UserId, notificationType, competentAuthority,
                                                           nextNotificationNumber);

            return(notification);
        }
        public async Task ReturnsCorrectFormat(UKCompetentAuthority competentAuthority, int notificationNumber, int movementNumber, string expected)
        {
            var notification = new NotificationApplication(notificationId, NotificationType.Recovery, competentAuthority, notificationNumber);
            A.CallTo(() => notificationApplicationRepository.GetById(notificationId)).Returns(notification);

            var movement = new Movement(movementNumber, notificationId, AnyDate, userId);
            var name = await certificateOfReceiptName.GetValue(movement);

            Assert.Equal(expected, name);
        }
        public async Task ReturnsCorrectFormat(string expected, UKCompetentAuthority competentAuthority, int notificationNumber, NotificationType notificationType, int movementNumber)
        {
            var notification = new NotificationApplication(Guid.NewGuid(), notificationType, competentAuthority, notificationNumber);

            A.CallTo(() => notificationRepository.GetById(notificationId)).Returns(notification);

            var result = await certificateOfRecoveryName.GetValue(new Movement(movementNumber, notificationId, AnyDate, userId));

            Assert.Equal(expected, result);
        }
 public async Task<PricingStructure> GetExport(UKCompetentAuthority competentAuthority, NotificationType notificationType, int numberOfShipments, bool isInterim)
 {
     return await context.PricingStructures.SingleAsync(p =>
         p.CompetentAuthority == competentAuthority
         && p.Activity.TradeDirection == TradeDirection.Export
         && p.Activity.NotificationType == notificationType
         && p.Activity.IsInterim == isInterim
         && (p.ShipmentQuantityRange.RangeFrom <= numberOfShipments
             && (p.ShipmentQuantityRange.RangeTo == null
             || p.ShipmentQuantityRange.RangeTo >= numberOfShipments)));
 }
        public DateTime? GetDecisionRequiredDate(IWorkingDayCalculator workingDayCalculator, UKCompetentAuthority competentAuthority)
        {
            DateTime? returnDate = null;

            if (CompletedDate.HasValue)
            {
                returnDate = workingDayCalculator.AddWorkingDays(CompletedDate.Value, WorkingDaysUntilDecisionRequired, false, competentAuthority);
            }

            return returnDate;
        }
        public DateTime Get(bool areFacilitiesPreconsented, DateTime acknowledgedDate, UKCompetentAuthority competentAuthority)
        {
            if (areFacilitiesPreconsented)
            {
                return workingDayCalculator.AddWorkingDays(acknowledgedDate,
                    7,
                    false,
                    competentAuthority);
            }

            return acknowledgedDate.AddDays(30);
        }
        public InternalUser(string userId, string jobTitle, UKCompetentAuthority competentAuthority, Guid localAreaId)
        {
            Guard.ArgumentNotNullOrEmpty(() => userId, userId);
            Guard.ArgumentNotNullOrEmpty(() => jobTitle, jobTitle);
            Guard.ArgumentNotDefaultValue(() => localAreaId, localAreaId);

            UserId = userId;
            JobTitle = jobTitle;
            CompetentAuthority = competentAuthority;
            LocalAreaId = localAreaId;
            Status = InternalUserStatus.Pending;
        }
        public ImportNotification(NotificationType notificationType,
            UKCompetentAuthority competentAuthority,
            string notificationNumber)
        {
            Guard.ArgumentNotNullOrEmpty(() => notificationNumber, notificationNumber);
            Guard.ArgumentNotDefaultValue(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotDefaultValue(() => notificationType, notificationType);

            NotificationType = notificationType;
            CompetentAuthority = competentAuthority;
            NotificationNumber = notificationNumber;
            RaiseEvent(new ImportNotificationCreatedEvent(this));
        }
 public ActionResult CardPaymentInformation(UKCompetentAuthority competentAuthority)
 {
     switch (competentAuthority)
     {
         case UKCompetentAuthority.England:
             return PartialView("_EaCard");
         case UKCompetentAuthority.Scotland:
             return PartialView("_SepaCard");
         case UKCompetentAuthority.Wales:
             return PartialView("_NrwCard");
         default:
             return new EmptyResult();
     }
 }
        public Task<NotificationApplication> CreateLegacy(NotificationType notificationType,
            UKCompetentAuthority competentAuthority, int number)
        {
            Guard.ArgumentNotZeroOrNegative(() => number, number);

            if (!IsNumberValid(competentAuthority, number))
            {
                throw new ArgumentOutOfRangeException("number",
                    string.Format("{0} is out of range for a notification number for {1}", number, competentAuthority));
            }

            var notification = new NotificationApplication(userContext.UserId, notificationType, competentAuthority,
                number);
            return Task.FromResult(notification);
        }
        internal NotificationApplication(Guid userId, NotificationType notificationType,
            UKCompetentAuthority competentAuthority, int notificationNumber)
        {
            UserId = userId;
            NotificationType = notificationType;
            CompetentAuthority = competentAuthority;
            NotificationNumber = NotificationNumberFormatter.GetNumber(notificationNumber, competentAuthority);

            OperationInfosCollection = new List<OperationInfo>();
            PackagingInfosCollection = new List<PackagingInfo>();
            PhysicalCharacteristicsCollection = new List<PhysicalCharacteristicsInfo>();
            WasteCodeInfoCollection = new List<WasteCodeInfo>();

            RaiseEvent(new NotificationCreatedEvent(this));
        }
        public void CanHaveInvalidAgencyEmailAddressesesWhenNotLiveEnvironment(UKCompetentAuthority competentAuthority,
            string email)
        {
            A.CallTo(() => dependencyResolver.GetService(typeof(AppConfiguration))).Returns(
                new AppConfiguration()
                {
                    Environment = "TEST"
                });

            viewModel.CompetentAuthority = competentAuthority;
            viewModel.Email = email;
            var validationResult = ViewModelValidator.ValidateViewModel(viewModel);

            Assert.Empty(validationResult);
        }
 public static UKCompetentAuthorityDetails ForCompetentAuthority(UKCompetentAuthority competentAuthority)
 {
     switch (competentAuthority)
     {
         case UKCompetentAuthority.England:
             return EA;
         case UKCompetentAuthority.Scotland:
             return SEPA;
         case UKCompetentAuthority.NorthernIreland:
             return NIEA;
         case UKCompetentAuthority.Wales:
             return NRW;
         default:
             throw new ArgumentException(
                 string.Format("No Competent Authority details for {0} found", competentAuthority), "competentAuthority");
     }
 }
Example #57
0
        public void UpdateScheme(
            string schemeName,
            string approvalNumber,
            string ibisCustomerReference,
            ObligationType? obligationType,
            UKCompetentAuthority competentAuthority)
        {
            Guard.ArgumentNotNullOrEmpty(() => schemeName, schemeName);
            Guard.ArgumentNotNullOrEmpty(() => approvalNumber, approvalNumber);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);

            SchemeName = schemeName;
            ApprovalNumber = approvalNumber;
            IbisCustomerReference = ibisCustomerReference;
            ObligationType = obligationType;
            CompetentAuthority = competentAuthority;
            CompetentAuthorityId = competentAuthority.Id;
        }
        public async Task<ActionResult> GenerateFinancialGuaranteeDocument(UKCompetentAuthority competentAuthority)
        {
            try
            {
                var response = await mediator.SendAsync(new GenerateFinancialGuaranteeDocument(competentAuthority));

                var downloadName = "IwsFinancialGuarantee" + SystemTime.UtcNow + ".pdf";

                return File(response, "application/pdf", downloadName);
            }
            catch (ApiBadRequestException ex)
            {
                this.HandleBadRequest(ex);
                if (ModelState.IsValid)
                {
                    throw;
                }
                return HttpNotFound();
            }
        }
        private string GetFinancialGuaranteeDocumentName(UKCompetentAuthority competentAuthority)
        {
            string filename;

            switch (competentAuthority)
            {
                case UKCompetentAuthority.NorthernIreland:
                    filename = "NIEAFinancialGuaranteeForm.pdf";
                    break;

                case UKCompetentAuthority.Wales:
                    filename = "NRWFinancialGuaranteeForm.pdf";
                    break;

                default:
                    filename = "EAFinancialGuaranteeForm.pdf";
                    break;
            }

            return filename;
        }
 public async Task<ExportMovementsData> Get(DateTime from, DateTime to, UKCompetentAuthority competentAuthority)
 {
     return await context.Database.SqlQuery<ExportMovementsData>(
         @"SELECT
               COUNT(CASE WHEN MovementInternalUserId IS NULL AND FileId IS NOT NULL THEN 1 ELSE NULL END) AS FilesUploadedExternally,
               COUNT(CASE WHEN MovementInternalUserId IS NOT NULL AND FileId IS NOT NULL THEN 1 ELSE NULL END) AS FilesUploadedInternally,
               COUNT(CASE WHEN MovementInternalUserId IS NULL THEN 1 ELSE NULL END) AS MovementsCreatedExternally,
               COUNT(MovementInternalUserId) AS MovementsCreatedInternally,
               COUNT(CASE WHEN MovementReceiptInternalUserId IS NULL AND ReceiptDate IS NOT NULL THEN 1 ELSE NULL END) AS MovementReceiptsCreatedExternally,
               COUNT(CASE WHEN MovementReceiptInternalUserId IS NOT NULL AND ReceiptDate IS NOT NULL THEN 1 ELSE NULL END) AS MovementReceiptsCreatedInternally,
               COUNT(CASE WHEN MovementOperationReceiptInternalUserId IS NULL AND OperationDate IS NOT NULL THEN 1 ELSE NULL END) AS MovementOperationReceiptsCreatedExternally,
               COUNT(CASE WHEN MovementOperationReceiptInternalUserId IS NOT NULL AND OperationDate IS NOT NULL THEN 1 ELSE NULL END) AS MovementOperationReceiptsCreatedInternally
           FROM
               [Reports].[ExportMovements]
           WHERE 
               [CompetentAuthority] = @ca
               AND ConsentedDate BETWEEN @from AND @to",
         new SqlParameter("@ca", (int)competentAuthority),
         new SqlParameter("@from", from),
         new SqlParameter("@to", to)).SingleAsync();
 }