public async Task FetchCompleteOrganisations_WithRejectedScheme_OrganisationNotReturned()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                // Arrange
                Organisation organisation = new Organisation();
                organisation.Id = new Guid("6BD77BBD-0BD8-4BAB-AA9F-A3E657D1CBB4");
                organisation.TradingName = "Test organisation";
                organisation.OrganisationType = EA.Weee.Domain.Organisation.OrganisationType.SoleTraderOrIndividual.Value;
                organisation.OrganisationStatus = EA.Weee.Domain.Organisation.OrganisationStatus.Complete.Value;

                Scheme scheme = new Scheme();
                scheme.Id = new Guid("CFD9B56F-6C3C-4E49-825C-A125ACFFEC3B");
                scheme.Organisation = organisation;
                scheme.SchemeStatus = (int)Core.Shared.SchemeStatus.Rejected;

                database.Model.Organisations.Add(organisation);
                database.Model.Schemes.Add(scheme);
                database.Model.SaveChanges();

                var dataAccess = new FetchOrganisationSearchResultsForCacheDataAccess(database.WeeeContext);

                // Act
                IList<OrganisationSearchResult> results = await dataAccess.FetchCompleteOrganisations();

                // Assert
                Assert.DoesNotContain(results,
                    r => r.OrganisationId == new Guid("6BD77BBD-0BD8-4BAB-AA9F-A3E657D1CBB4"));
            }
        }
Ejemplo n.º 2
0
        public async Task FetchLatestProducers_WithProducerRegisteredTwiceIn2015_ReturnsOnlyLatestProducer()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                // Arrange
                Model.Scheme scheme = helper.CreateScheme();

                Model.MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme);
                memberUpload1.ComplianceYear = 2015;
                memberUpload1.IsSubmitted    = true;

                Model.ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload1, "AAAAA");
                producer1.UpdatedDate = new DateTime(2015, 1, 1);

                Model.MemberUpload memberUpload2 = helper.CreateMemberUpload(scheme);
                memberUpload2.ComplianceYear = 2015;
                memberUpload2.IsSubmitted    = true;

                Model.ProducerSubmission producer2 = helper.CreateProducerAsCompany(memberUpload2, "AAAAA");
                producer2.UpdatedDate = new DateTime(2015, 1, 2);

                database.Model.SaveChanges();

                // Act
                FetchProducerSearchResultsForCacheDataAccess dataAccess = new FetchProducerSearchResultsForCacheDataAccess(database.WeeeContext);
                var results = await dataAccess.FetchLatestProducers();

                // Assert
                Assert.NotNull(results);
                Assert.Contains(results, p => p.RegistrationNumber == "AAAAA" && p.Name == producer2.Business.Company.Name);
                Assert.DoesNotContain(results, p => p.RegistrationNumber == "AAAAA" && p.Name == producer1.Business.Company.Name);
            }
        }
Ejemplo n.º 3
0
        public async Task FetchLatestProducers_WithThreeProducers_ReturnsProducersOrderedByRegistrationNumber()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                // Arrange
                Model.Scheme scheme = helper.CreateScheme();

                Model.MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme);
                memberUpload1.ComplianceYear = 2015;
                memberUpload1.IsSubmitted    = true;

                Model.ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload1, "AAAAA");

                Model.MemberUpload memberUpload2 = helper.CreateMemberUpload(scheme);
                memberUpload2.ComplianceYear = 2015;
                memberUpload2.IsSubmitted    = true;

                Model.ProducerSubmission producer2 = helper.CreateProducerAsCompany(memberUpload2, "CCCCC");

                Model.MemberUpload memberUpload3 = helper.CreateMemberUpload(scheme);
                memberUpload3.ComplianceYear = 2015;
                memberUpload3.IsSubmitted    = true;

                Model.ProducerSubmission producer3 = helper.CreateProducerAsCompany(memberUpload3, "BBBBB");

                database.Model.SaveChanges();

                // Act
                FetchProducerSearchResultsForCacheDataAccess dataAccess = new FetchProducerSearchResultsForCacheDataAccess(database.WeeeContext);
                var results = await dataAccess.FetchLatestProducers();

                // Assert
                Assert.NotNull(results);

                var result1 = results.SingleOrDefault(r => r.RegistrationNumber == "AAAAA");
                var result2 = results.SingleOrDefault(r => r.RegistrationNumber == "BBBBB");
                var result3 = results.SingleOrDefault(r => r.RegistrationNumber == "CCCCC");

                Assert.NotNull(result1);
                Assert.NotNull(result2);
                Assert.NotNull(result3);

                int result1index = results.IndexOf(result1);
                int result2index = results.IndexOf(result2);
                int result3index = results.IndexOf(result3);

                Assert.True(result1index < result2index);
                Assert.True(result2index < result3index);
            }
        }
        public async Task FetchCompleteOrganisations_WithCompleteCompany_UsesNameColumnToPopulateOrganisationName()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                // Arrange
                Organisation organisation = new Organisation();
                organisation.Id = new Guid("6BD77BBD-0BD8-4BAB-AA9F-A3E657D1CBB4");
                organisation.Name = "Company Name";
                organisation.OrganisationType = EA.Weee.Domain.Organisation.OrganisationType.RegisteredCompany.Value;
                organisation.OrganisationStatus = EA.Weee.Domain.Organisation.OrganisationStatus.Complete.Value;

                Scheme scheme = new Scheme();
                scheme.Id = new Guid("CFD9B56F-6C3C-4E49-825C-A125ACFFEC3B");
                scheme.Organisation = organisation;
                scheme.SchemeStatus = (int)Core.Shared.SchemeStatus.Approved;

                database.Model.Organisations.Add(organisation);
                database.Model.Schemes.Add(scheme);
                database.Model.SaveChanges();

                var dataAccess = new FetchOrganisationSearchResultsForCacheDataAccess(database.WeeeContext);

                // Act
                IList<OrganisationSearchResult> results = await dataAccess.FetchCompleteOrganisations();

                // Assert
                Assert.Contains(results,
                    r => r.OrganisationId == new Guid("6BD77BBD-0BD8-4BAB-AA9F-A3E657D1CBB4") && r.Name == "Company Name");
            }
        }
        public async Task FetchCompleteOrganisations_WithSeveralResults_ReturnsResultsOrderedByName()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                // Arrange
                Organisation organisation1 = new Organisation();
                organisation1.Id = new Guid("6BD77BBD-0BD8-4BAB-AA9F-A3E657D1CBB4");
                organisation1.Name = "Company B";
                organisation1.OrganisationType = EA.Weee.Domain.Organisation.OrganisationType.RegisteredCompany.Value;
                organisation1.OrganisationStatus = EA.Weee.Domain.Organisation.OrganisationStatus.Complete.Value;

                Scheme scheme1 = new Scheme();
                scheme1.Id = new Guid("CFD9B56F-6C3C-4E49-825C-A125ACFFEC3B");
                scheme1.Organisation = organisation1;
                scheme1.SchemeStatus = (int)Core.Shared.SchemeStatus.Approved;

                Organisation organisation2 = new Organisation();
                organisation2.Id = new Guid("659A5E1B-90F8-4E5C-8939-436189424AB6");
                organisation2.Name = "Company A";
                organisation2.OrganisationType = EA.Weee.Domain.Organisation.OrganisationType.RegisteredCompany.Value;
                organisation2.OrganisationStatus = EA.Weee.Domain.Organisation.OrganisationStatus.Complete.Value;

                Scheme scheme2 = new Scheme();
                scheme2.Id = new Guid("0F0CCEEF-849B-474A-A548-C52F99FD0C99");
                scheme2.Organisation = organisation2;
                scheme2.SchemeStatus = (int)Core.Shared.SchemeStatus.Approved;

                Organisation organisation3 = new Organisation();
                organisation3.Id = new Guid("D7C37279-C3F5-44C0-B6CF-D43A968F3F29");
                organisation3.Name = "Company C";
                organisation3.OrganisationType = EA.Weee.Domain.Organisation.OrganisationType.RegisteredCompany.Value;
                organisation3.OrganisationStatus = EA.Weee.Domain.Organisation.OrganisationStatus.Complete.Value;

                Scheme scheme3 = new Scheme();
                scheme3.Id = new Guid("52DA530C-B09C-4C52-B354-F07E72EE6111");
                scheme3.Organisation = organisation3;
                scheme3.SchemeStatus = (int)Core.Shared.SchemeStatus.Approved;

                database.Model.Organisations.Add(organisation1);
                database.Model.Organisations.Add(organisation2);
                database.Model.Organisations.Add(organisation3);
                database.Model.Schemes.Add(scheme1);
                database.Model.Schemes.Add(scheme2);
                database.Model.Schemes.Add(scheme3);
                database.Model.SaveChanges();

                var dataAccess = new FetchOrganisationSearchResultsForCacheDataAccess(database.WeeeContext);

                // Act
                IList<OrganisationSearchResult> results = await dataAccess.FetchCompleteOrganisations();

                // Assert
                int indexOfCompanyA = results.IndexOf(results.First(r => r.OrganisationId == new Guid("659A5E1B-90F8-4E5C-8939-436189424AB6")));
                int indexOfCompanyB = results.IndexOf(results.First(r => r.OrganisationId == new Guid("6BD77BBD-0BD8-4BAB-AA9F-A3E657D1CBB4")));
                int indexOfCompanyC = results.IndexOf(results.First(r => r.OrganisationId == new Guid("D7C37279-C3F5-44C0-B6CF-D43A968F3F29")));

                Assert.True(indexOfCompanyA < indexOfCompanyB, "Organisation search results must be returned ordered by organisation name.");
                Assert.True(indexOfCompanyB < indexOfCompanyC, "Organisation search results must be returned ordered by organisation name.");
            }
        }
Ejemplo n.º 6
0
        public DataReturnVersion CreateDataReturnVersion(Scheme scheme, int complianceYear, int quarter, bool isSubmitted = true, DataReturn dataReturn = null, WeeeCollectedReturnVersion weeeCollectedReturnVersion = null)
        {
            if (dataReturn == null)
            {
                dataReturn = GetOrCreateDataReturn(scheme, complianceYear, quarter);
            }

            Guid dataReturnVersionId = IntegerToGuid(GetNextId());

            var dataReturnVersion = new DataReturnVersion
            {
                Id = dataReturnVersionId,
                DataReturn = dataReturn,
                DataReturnId = dataReturn.Id,
                CreatedDate = DateTime.UtcNow
            };

            if (isSubmitted)
            {
                dataReturnVersion.SubmittedDate = DateTime.UtcNow;
                dataReturnVersion.SubmittingUserId = GetOrCreateUser("Testuser").Id;
                dataReturn.CurrentDataReturnVersionId = dataReturnVersionId;
                dataReturn.CurrentDataReturnVersion = dataReturnVersion;
            }

            if (weeeCollectedReturnVersion != null)
            {
                dataReturnVersion.WeeeCollectedReturnVersion = weeeCollectedReturnVersion;
            }

            model.DataReturnVersions.Add(dataReturnVersion);

            return dataReturnVersion;
        }
Ejemplo n.º 7
0
        public DataReturn CreateDataReturn(Scheme scheme, int complianceYear, int quarter)
        {
            int dataReturnId = GetNextId();

            var dataReturn = new DataReturn
            {
                Id = IntegerToGuid(dataReturnId),
                Scheme = scheme,
                SchemeId = scheme.Id,
                Quarter = quarter,
                ComplianceYear = complianceYear
            };
            model.DataReturns.Add(dataReturn);

            return dataReturn;
        }
Ejemplo n.º 8
0
        public DataReturn GetOrCreateDataReturn(Scheme scheme, int complianceYear, int quarter)
        {
            // Try to find a DataReturn that has already been created, otherwise create a new one.
            var dataReturn =
                model.DataReturns.Local
                .SingleOrDefault(du => du.Scheme.Id == scheme.Id &&
                                       du.ComplianceYear == complianceYear &&
                                       du.Quarter == quarter);

            if (dataReturn == null)
            {
                dataReturn = CreateDataReturn(scheme, complianceYear, quarter);
            }

            return dataReturn;
        }
Ejemplo n.º 9
0
        public DataReturnUpload CreateDataReturnUpload(Scheme scheme, DataReturnVersion dataReturnVersion = null)
        {
            int dataReturnUploadId = GetNextId();
            DataReturnUpload dataReturnUpload = new DataReturnUpload
            {
                Id = IntegerToGuid(dataReturnUploadId),
                SchemeId = scheme.Id,
                Scheme = scheme,
                Data = string.Format("<SchemeReturn{0} />", dataReturnUploadId),
                Date = DateTime.UtcNow,
                ProcessTime = TimeSpan.Zero
            };

            if (dataReturnVersion != null)
            {
                dataReturnUpload.DataReturnVersionId = dataReturnVersion.Id;
                dataReturnUpload.DataReturnVersion = dataReturnVersion;

                if (dataReturnVersion.DataReturn != null)
                {
                    dataReturnUpload.ComplianceYear = dataReturnVersion.DataReturn.ComplianceYear;
                    dataReturnUpload.Quarter = dataReturnVersion.DataReturn.Quarter;
                }
            }

            model.DataReturnUploads.Add(dataReturnUpload);

            return dataReturnUpload;
        }
Ejemplo n.º 10
0
        public RegisteredProducer GetOrCreateRegisteredProducer(Scheme scheme, int complianceYear, string registrationNumber)
        {
            // Try to find a RegisteredProducer that has already been created, otherwise create a new one.
            // A removed producer is not reused.
            RegisteredProducer registeredProducer =
                model.RegisteredProducers.Local
                .SingleOrDefault(rp => rp.ProducerRegistrationNumber == registrationNumber &&
                                       rp.ComplianceYear == complianceYear &&
                                       rp.SchemeId == scheme.Id &&
                                       !rp.Removed);

            if (registeredProducer == null)
            {
                int registeredProducerId = GetNextId();

                registeredProducer = new RegisteredProducer
                {
                    Id = IntegerToGuid(registeredProducerId),
                    Scheme = scheme,
                    SchemeId = scheme.Id,
                    ComplianceYear = complianceYear,
                    ProducerRegistrationNumber = registrationNumber,
                    CurrentSubmissionId = null,
                    Removed = false
                };
                model.RegisteredProducers.Add(registeredProducer);
            }

            return registeredProducer;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a member upload associated with the specified scheme and sets the member
        /// upload as being submitted. An invoice run can optionally be assigned to the submitted
        /// member upload.
        /// </summary>
        /// <param name="scheme"></param>
        /// <param name="invoiceRun"></param>
        /// <returns></returns>
        public MemberUpload CreateSubmittedMemberUpload(Scheme scheme, InvoiceRun invoiceRun = null)
        {
            var memberUpload = CreateMemberUpload(scheme);

            memberUpload.IsSubmitted = true;
            memberUpload.SubmittedDate = DateTime.UtcNow;
            memberUpload.TotalCharges = 30;

            if (invoiceRun != null)
            {
                memberUpload.InvoiceRun = invoiceRun;
                memberUpload.InvoiceRunId = invoiceRun.Id;
            }

            return memberUpload;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a member upload associated with the specified scheme.
        /// After creation, the ComplianceYear and IsSubmitted properties
        /// should be explicitly set by the test.
        /// </summary>
        /// <param name="scheme"></param>
        /// <returns></returns>
        public MemberUpload CreateMemberUpload(Scheme scheme)
        {
            int memberUploadId = GetNextId();
            MemberUpload memberUpload = new MemberUpload
            {
                Id = IntegerToGuid(memberUploadId),
                OrganisationId = scheme.OrganisationId,
                Organisation = scheme.Organisation,
                Scheme = scheme,
                SchemeId = scheme.Id,
                Data = string.Format("<memberUpload{0} />", memberUploadId),
                CreatedById = GetOrCreateUser("Testuser").Id,
                CreatedDate = DateTime.UtcNow,
                ProcessTime = new TimeSpan(0),
                ComplianceYear = 2016
            };

            model.MemberUploads.Add(memberUpload);

            return memberUpload;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a scheme and associates it to the specified organisation.
        /// </summary>
        /// <returns></returns>
        public Scheme CreateScheme(Organisation organisation)
        {
            int schemeId = GetNextId();
            Scheme scheme = new Scheme
            {
                Id = IntegerToGuid(schemeId),
                Organisation = organisation,
                OrganisationId = organisation.Id,
                SchemeName = "test scheme name",
                ApprovalNumber = schemeId.ToString()
            };
            model.Schemes.Add(scheme);

            return scheme;
        }