public async Task GetDataReturnComplianceYearsForSchemeHandler_ReturnsYearsInDescendingOrder()
        {
            using (var database = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(database.Model);                

                var scheme = helper.CreateScheme();
                var firstDataReturn = helper.CreateDataReturn(scheme, 2006, (int)QuarterType.Q1);
                var firstDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2006, 1, true, firstDataReturn);
                helper.CreateDataReturnUpload(scheme, firstDataReturnVersion);

                var secondDataReturn = helper.CreateDataReturn(scheme, 2007, (int)QuarterType.Q1);
                var secondDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2007, 1, true, secondDataReturn);
                helper.CreateDataReturnUpload(scheme, secondDataReturnVersion);
                database.Model.SaveChanges();               

                // Act
                var dataAccess = new FetchDataReturnComplianceYearsForSchemeDataAccess(database.WeeeContext);
                var yearsList = await dataAccess.GetDataReturnComplianceYearsForScheme(scheme.Id);

                //Assert                
                Assert.NotNull(yearsList);
                Assert.Equal(2, yearsList.Count);
                Assert.Collection(yearsList,
                    r1 => Assert.Equal("2007", r1.ToString()),
                    r2 => Assert.Equal("2006", r2.ToString()));
            }
        }
        public void GetLatestProducerForComplianceYearAndScheme_PrnDoesNotMatch_ReturnsNull()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

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

                MemberUpload memberUpload = helper.CreateMemberUpload(scheme);
                memberUpload.ComplianceYear = 2016;
                memberUpload.IsSubmitted = true;

                Weee.Tests.Core.Model.ProducerSubmission producer = helper.CreateProducerAsCompany(memberUpload, "AAAAAAAA");

                database.Model.SaveChanges();

                ProducerQuerySet querySet = ProducerQuerySet(database.WeeeContext);

                // Act
                var result = querySet.GetLatestProducerForComplianceYearAndScheme("XXXXXXXX", "2016", scheme.OrganisationId);

                // Assert
                Assert.Null(result);
            }
        }
        public async void HasMemberSubmissions_ForOganisationWithAssociatedScheme_AndNoSubmission_ReturnsFalse()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                // Arrange
                var scheme = helper.CreateScheme();

                var upload1 = helper.CreateMemberUpload(scheme);
                upload1.IsSubmitted = false;
                upload1.ComplianceYear = 2016;

                var upload2 = helper.CreateMemberUpload(scheme);
                upload2.IsSubmitted = false;
                upload2.ComplianceYear = 2016;

                database.Model.SaveChanges();

                var dataAccess = new GetOrganisationOverviewDataAccess(database.WeeeContext);

                // Act
                var result = await dataAccess.HasMemberSubmissions(scheme.OrganisationId);

                // Assert
                Assert.False(result);
            }
        }
        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);
            }
        }
        public void FetchSumOfExistingCharges_WithProducerWithNoChargesInSpecifiedYear_ReturnsZero()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(database.Model);

                Scheme scheme = helper.CreateScheme();

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

                ProducerSubmission producer = helper.CreateProducerAsCompany(memberUpload, "AAAAA");
                producer.ChargeThisUpdate = 1;

                database.Model.SaveChanges();

                ProducerChargeCalculatorDataAccess dataAccess = new ProducerChargeCalculatorDataAccess(database.WeeeContext);

                // Act
                decimal result = dataAccess.FetchSumOfExistingCharges(scheme.ApprovalNumber, "AAAAA", 2016);

                // Assert
                Assert.Equal(0, result);
            }
        }
        public async void FetchSchemeByOrganisationId_WhenTwoSchemesHaveTheSameOrganisationId_ThrowsException()
        {
            using (var database = new DatabaseWrapper())
            {
                Guid organisationId = new Guid("72BB14DF-DCD5-4DBB-BBA9-4CFC26AD80F9");
                GetSchemePublicInfoDataAccess dataAccess = new GetSchemePublicInfoDataAccess(database.WeeeContext);

                // Arrange
                ModelHelper modelHelper = new ModelHelper(database.Model);

                var scheme1 = modelHelper.CreateScheme();
                scheme1.Organisation.Id = organisationId;

                var scheme2 = modelHelper.CreateScheme();
                scheme2.Organisation = scheme1.Organisation;

                database.Model.SaveChanges();

                // Act
                Func<Task<Domain.Scheme.Scheme>> action = async () => await dataAccess.FetchSchemeByOrganisationId(organisationId);

                // Assert
                await Assert.ThrowsAsync<Exception>(action);
            }
        }
        public void FetchSumOfExistingCharges_WithUnknownProducer_ReturnsZero()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                Scheme scheme = helper.CreateScheme();

                database.Model.SaveChanges();

                // Arrange
                ProducerChargeCalculatorDataAccess dataAccess = new ProducerChargeCalculatorDataAccess(database.WeeeContext);

                // Act
                decimal result = dataAccess.FetchSumOfExistingCharges(scheme.ApprovalNumber, "XXXXXXX", 2016);

                // Assert
                Assert.Equal(0, result);
            }
        }
        public void GetSchemeApprovalNumberByOrganisationId_OrganisationIdDoesExist_ReturnsApprovalNumber()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                // Arrange
                Scheme scheme = helper.CreateScheme();
                scheme.ApprovalNumber = "ABC";
                
                database.Model.SaveChanges();

                SchemeQuerySet schemeQuerySet = new SchemeQuerySet(database.WeeeContext);

                // Act
                string result = schemeQuerySet.GetSchemeApprovalNumberByOrganisationId(scheme.OrganisationId);

                // Assert
                Assert.Equal("ABC", result);
            }
        }
        public async Task InsertNonRemovedRegisteredProducer_WithExistingRemovedProducer_DoesntThrowAnException()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                Scheme scheme = helper.CreateScheme();

                RegisteredProducer registeredProducer1 = new RegisteredProducer()
                {
                    Id = new Guid("834635D7-876D-47BD-B3E3-570E481B2C15"),
                    Scheme = scheme,
                    ComplianceYear = 2099,
                    ProducerRegistrationNumber = "WEE/HD6483TF",
                    Removed = true,
                };

                wrapper.Model.RegisteredProducers.Add(registeredProducer1);

                await wrapper.Model.SaveChangesAsync();

                // Act
                RegisteredProducer registeredProducer2 = new RegisteredProducer()
                {
                    Id = new Guid("65C1B132-2573-409C-B18E-E7C3AEC777AF"),
                    Scheme = scheme,
                    ComplianceYear = 2099,
                    ProducerRegistrationNumber = "WEE/HD6483TF",
                    Removed = false,
                };

                wrapper.Model.RegisteredProducers.Add(registeredProducer2);

                await wrapper.Model.SaveChangesAsync();

                // Assert
                // No exception
            }
        }
        public async void FetchSchemeByOrganisationId_WitValidOrganisationId_ReturnsScheme()
        {
            using (var database = new DatabaseWrapper())
            {
                Guid organisationId = new Guid("72BB14DF-DCD5-4DBB-BBA9-4CFC26AD80F9");
                GetSchemePublicInfoDataAccess dataAccess = new GetSchemePublicInfoDataAccess(database.WeeeContext);

                // Arrange
                ModelHelper modelHelper = new ModelHelper(database.Model);

                var scheme1 = modelHelper.CreateScheme();
                scheme1.Organisation.Id = organisationId;

                database.Model.SaveChanges();

                // Act
                var result = await dataAccess.FetchSchemeByOrganisationId(organisationId);

                // Assert
                Assert.NotNull(result);
                Assert.Equal(organisationId, result.OrganisationId);
            }
        }
        public async void Fetch_TwoUploadsForTheSameComplianceYear_OnlyReturnsTheYearOnce()
        {
            using (var database = new DatabaseWrapper())
            {
                const int complianceYear = 2005;

                // Arrange
                var modelHelper = new ModelHelper(database.Model);

                var organisation = modelHelper.CreateOrganisation();
                await database.Model.SaveChangesAsync();

                var scheme = modelHelper.CreateScheme(organisation);
                await database.Model.SaveChangesAsync();

                var firstDataReturn = modelHelper.CreateDataReturn(scheme, complianceYear, (int)QuarterType.Q1);
                await database.Model.SaveChangesAsync();

                var firstDataReturnVersion = modelHelper.CreateDataReturnVersion(scheme, complianceYear, (int)QuarterType.Q1, true, firstDataReturn);
                modelHelper.CreateDataReturnUpload(scheme, firstDataReturnVersion);
                await database.Model.SaveChangesAsync();

                var secondDataReturn = modelHelper.CreateDataReturn(scheme, complianceYear, (int)QuarterType.Q2);
                await database.Model.SaveChangesAsync();

                var secondDataReturnVersion = modelHelper.CreateDataReturnVersion(scheme, complianceYear, (int)QuarterType.Q2, true, secondDataReturn);
                modelHelper.CreateDataReturnUpload(scheme, secondDataReturnVersion);
                await database.Model.SaveChangesAsync();

                // Act
                var dataAccess = new FetchDataReturnComplianceYearsForSchemeDataAccess(database.WeeeContext);
                var result = await dataAccess.GetDataReturnComplianceYearsForScheme(scheme.Id);

                // Assert
                Assert.Single(result.Where(y => y == complianceYear));
            }
        }
        public async Task FetchSchemeByOrganisationIdAsync_GetsSchemeForMatchingOrganisationId()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(database.Model);

                var organisation1 = helper.CreateOrganisation();
                helper.CreateScheme(organisation1);

                var organisation2 = helper.CreateOrganisation();
                var scheme2 = helper.CreateScheme(organisation2);

                database.Model.SaveChanges();

                var dataAccess = new FetchDataReturnComplianceYearsForSchemeDataAccess(database.WeeeContext);

                // Act
                var result = await dataAccess.FetchSchemeByOrganisationIdAsync(organisation2.Id);

                // Assert
                Assert.Equal(scheme2.Id, result.Id);
            }
        }
        public void GetLatestCompanyProducers_ReturnsCurrentForComplianceYearCompaniesOnly()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                // Arrange
                Scheme scheme1 = helper.CreateScheme();

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

                ProducerSubmission companyProducer1 = helper.CreateProducerAsCompany(memberUpload1, "AA");

                ProducerSubmission companyProducer2 = helper.CreateProducerAsCompany(memberUpload1, "BB");

                ProducerSubmission companyProducer3 = helper.CreateProducerAsCompany(memberUpload1, "AA");

                database.Model.SaveChanges();

                // Act
                var result = ProducerQuerySet(database.WeeeContext).GetLatestCompanyProducers();

                // Assert
                Assert.DoesNotContain(result, p => p.Id == companyProducer1.Id);
                Assert.Contains(result, p => p.Id == companyProducer2.Id);
                Assert.Contains(result, p => p.Id == companyProducer3.Id);
            }
        }
        public async void HasMultipleManageableOrganisationUsers_ForOrganisationWithMoreThanOneUser_AllRejectedStatuses_ReturnsFalse()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                // Arrange
                var organisation = helper.CreateOrganisation();

                // Rejected users
                helper.CreateOrganisationUser(organisation, "Test user1", 3);
                helper.CreateOrganisationUser(organisation, "Test user2", 3);

                database.Model.SaveChanges();

                var dataAccess = new GetOrganisationOverviewDataAccess(database.WeeeContext);

                // Act
                var result = await dataAccess.HasMultipleManageableOrganisationUsers(organisation.Id);

                // Assert
                Assert.False(result);
            }
        }
        public async Task FetchSchemeAsync_ReturnsNull_WhenNoSchemeWithSpecifiedOrganisationId()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                // Arrange
                var modelHelper = new ModelHelper(database.Model);

                var organisationId = new Guid("C826DCE8-78EB-4BE4-B419-4DE73D1AD181");

                database.Model.SaveChanges();

                OrganisationDetailsDataAccess dataAccess = new OrganisationDetailsDataAccess(database.WeeeContext);

                // Act
                Domain.Scheme.Scheme result = await dataAccess.FetchSchemeAsync(organisationId);

                // Assert
                Assert.Null(result);
            }
        }
        public async Task HasDataReturnSubmissions_ForOganisationWithNoAssociatedScheme_ReturnsFalse()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                // Arrange
                var organisation = helper.CreateOrganisation();

                database.Model.SaveChanges();

                var dataAccess = new GetOrganisationOverviewDataAccess(database.WeeeContext);

                // Act
                var result = await dataAccess.HasDataReturnSubmissions(organisation.Id);

                // Assert
                Assert.False(result);
            }
        }
        public async Task HasMemberSubmissions_ForOganisationWithAssociatedScheme_AndNoSubmittedDataReturnVersion_ReturnsFalse()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                // Arrange
                var scheme = helper.CreateScheme();
                helper.CreateDataReturnVersion(scheme, 2016, 1, false);

                database.Model.SaveChanges();

                var dataAccess = new GetOrganisationOverviewDataAccess(database.WeeeContext);

                // Act
                var result = await dataAccess.HasDataReturnSubmissions(scheme.OrganisationId);

                // Assert
                Assert.False(result);
            }
        }
        public void FetchSumOfExistingCharges_WithSameProducerWithDifferentSchemesInSameYear_ReturnsChargesPerScheme()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(database.Model);

                Scheme scheme1 = helper.CreateScheme();
                scheme1.ApprovalNumber = "FirstScheme";

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted = true;

                ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload1, "AAAAA");
                producer1.ChargeThisUpdate = 1;
                
                Scheme scheme2 = helper.CreateScheme();
                scheme2.ApprovalNumber = "SecondScheme";

                MemberUpload memberUpload2 = helper.CreateMemberUpload(scheme2);
                memberUpload2.ComplianceYear = 2016;
                memberUpload2.IsSubmitted = true;

                ProducerSubmission producer2 = helper.CreateProducerAsCompany(memberUpload2, "AAAAA");
                producer2.ChargeThisUpdate = 2;

                database.Model.SaveChanges();

                ProducerChargeCalculatorDataAccess dataAccess = new ProducerChargeCalculatorDataAccess(database.WeeeContext);

                // Act
                decimal producer1Charge = dataAccess.FetchSumOfExistingCharges("FirstScheme", "AAAAA", 2016);
                decimal producer2Charge = dataAccess.FetchSumOfExistingCharges("SecondScheme", "AAAAA", 2016);

                // Assert
                Assert.Equal(1, producer1Charge);
                Assert.Equal(2, producer2Charge);
            }
        }
        public void FetchSumOfExistingCharges_WithProducerWithSeveralCharges_ReturnsSumOfChargeAmounts()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(database.Model);

                Scheme scheme = helper.CreateScheme();

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

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

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

                ProducerSubmission producer2 = helper.CreateProducerAsCompany(memberUpload2, "AAAAA");
                producer2.ChargeThisUpdate = 2;

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

                ProducerSubmission producer3 = helper.CreateProducerAsCompany(memberUpload3, "AAAAA");
                producer3.ChargeThisUpdate = 3;

                database.Model.SaveChanges();

                ProducerChargeCalculatorDataAccess dataAccess = new ProducerChargeCalculatorDataAccess(database.WeeeContext);

                // Act
                decimal result = dataAccess.FetchSumOfExistingCharges(scheme.ApprovalNumber, "AAAAA", 2016);

                // Assert
                Assert.Equal(6, result);
            }
        }
        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 void GetLatestProducerFromPreviousComplianceYears_TwoProducerEntriesIn2015_AndOneIn2014_ReturnsLatestProducerByUpdatedDateIn2015()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

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

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

                Weee.Tests.Core.Model.ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload1, "AAAAAAA");
                producer1.UpdatedDate = new DateTime(2015, 1, 1);

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

                Weee.Tests.Core.Model.ProducerSubmission producer2 = helper.CreateProducerAsCompany(memberUpload2, "AAAAAAA");
                producer2.UpdatedDate = new DateTime(2015, 1, 2);

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

                Weee.Tests.Core.Model.ProducerSubmission producer3 = helper.CreateProducerAsCompany(memberUpload3, "AAAAAAA");
                producer3.UpdatedDate = new DateTime(2014, 1, 1);

                database.Model.SaveChanges();

                ProducerQuerySet querySet = ProducerQuerySet(database.WeeeContext);

                // Act
                var result = querySet.GetLatestProducerFromPreviousComplianceYears("AAAAAAA");

                // Assert
                Assert.NotNull(result);
                Assert.Equal(producer2.Id, result.Id);
            }
        }
        public void GetAllRegistrationNumbers_ReturnsDistinctRegistrationNumbers()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

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

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

                Weee.Tests.Core.Model.ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload1, "AAAAAAA");

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

                Weee.Tests.Core.Model.ProducerSubmission producer2 = helper.CreateProducerAsCompany(memberUpload2, "AAAAAAA");

                database.Model.SaveChanges();

                ProducerQuerySet querySet = ProducerQuerySet(database.WeeeContext);

                // Act
                List<string> results = querySet.GetAllRegistrationNumbers();

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count(r => r == "AAAAAAA"));
            }
        }
        public void GetLatestCompanyProducers_ReturnsCompaniesOnly()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                // Arrange
                Scheme scheme1 = helper.CreateScheme();

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

                Weee.Tests.Core.Model.ProducerSubmission companyProducer1 = helper.CreateProducerAsCompany(memberUpload1, "AAAAAAA");

                Weee.Tests.Core.Model.ProducerSubmission partnershipProducer = helper.CreateProducerAsPartnership(memberUpload1, "PPP1");

                Weee.Tests.Core.Model.ProducerSubmission soleTraderProducer = helper.CreateProducerAsSoleTrader(memberUpload1, "SSS1");

                Weee.Tests.Core.Model.ProducerSubmission companyProducer2 = helper.CreateProducerAsCompany(memberUpload1, "AAAAAAB");

                database.Model.SaveChanges();

                // Act
                var result = ProducerQuerySet(database.WeeeContext).GetLatestCompanyProducers();

                // Assert
                Assert.Contains(result, p => p.Id == companyProducer1.Id);
                Assert.Contains(result, p => p.Id == companyProducer2.Id);
                Assert.DoesNotContain(result, p => p.Id == soleTraderProducer.Id);
                Assert.DoesNotContain(result, p => p.Id == partnershipProducer.Id);
            }
        }
        public void GetProducerForOtherSchemeAndObligationType_ForAnotherSchemeSameObligationType_ReturnsAnotherSchemeProducer()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                // Arrange
                Scheme scheme1 = helper.CreateScheme();
                
                Scheme scheme2 = helper.CreateScheme();

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

                Weee.Tests.Core.Model.ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload1, "AAAAAAA");
                producer1.ObligationType = "B2C";

                database.Model.SaveChanges();

                ProducerQuerySet querySet = ProducerQuerySet(database.WeeeContext);

                // Act
                var result = querySet.GetProducerForOtherSchemeAndObligationType("AAAAAAA", "2015", scheme1.OrganisationId, ObligationType.B2C);

                // Assert
                Assert.NotNull(result);
                Assert.Equal(producer1.Id, result.Id);
            }
        }