Esempio n. 1
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));
            }
        }
Esempio n. 2
0
        public async Task FetchInvoiceRunsAsync_WithSpecifiedAuthority_OnlyReturnsInvoiceRunsForTheSpecifiedAuthority()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser  user   = helper.GetOrCreateUser("TestUser");

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

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

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

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

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

                wrapper.Model.SaveChanges();

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

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

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

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

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

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

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

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

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

                wrapper.Model.SaveChanges();

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

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

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

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.Equal(new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872"), results[0].Id);
            }
        }
        public async Task FetchInvoicedProducerSubmissionsAsync_ReturnsProducerSubmissionsForRemovedProducer_WhenProducerHasBeenInvoiced()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                var helper       = new ModelHelper(database.Model);
                var domainHelper = new DomainHelper(database.WeeeContext);

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

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

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

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

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

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

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

                database.Model.SaveChanges();

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

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

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

                var producerResult = results.Single();
                Assert.Equal(producerSubmission.Id, producerResult.Id);
            }
        }
        public async Task FetchInvoicedProducerSubmissionsAsync_WithSpecifiedAuthorityYearAndSchemeName_OnlyReturnsProducerSubmissions()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                var helper = new ModelHelper(database.Model);
                // At least one user is required in the database.
                var user = helper.GetOrCreateUser("A user");

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

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

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

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

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

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

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

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

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

                Domain.Producer.ProducerSubmission producer = results.FirstOrDefault(p => p.RegisteredProducer.ProducerRegistrationNumber == registrationNumber);
                // Assert
                Assert.NotNull(producer);
                Assert.Equal(producerSubmission.RegisteredProducer.ProducerRegistrationNumber, producer.RegisteredProducer.ProducerRegistrationNumber);
                Assert.Equal(1, producerSubmissionList.Count);
            }
        }
Esempio n. 6
0
        public async Task FetchnvoicedMemberUploadsAsync_WithSpecifiedAuthority_OOnlyReturnsInvoicedMemberUploadsForTheSpecifiedAuthority()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser  user   = helper.GetOrCreateUser("TestUser");

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

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

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

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

                wrapper.Model.SaveChanges();

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

                CommonDataAccess dataAccess = new CommonDataAccess(wrapper.WeeeContext);

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

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.Equal(memberUpload.Id, results[0].Id);
            }
        }
        public async Task FetchnvoicedMemberUploadsAsync_WithSpecifiedAuthority_OOnlyReturnsInvoicedMemberUploadsForTheSpecifiedAuthority()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser user = helper.GetOrCreateUser("TestUser");

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

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

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

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

                wrapper.Model.SaveChanges();

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

                CommonDataAccess dataAccess = new CommonDataAccess(wrapper.WeeeContext);

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

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.Equal(memberUpload.Id, results[0].Id);
            }
        }
Esempio n. 8
0
        public async Task FetchInvoiceRunsAsync_Always_EagerLoadsIssuedByUser()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser  user   = helper.GetOrCreateUser("TestUser");

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

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

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

                wrapper.Model.SaveChanges();

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

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

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

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.NotNull(results[0].IssuedByUser);
            }
        }
        public async Task FetchSubmittedNonInvoicedMemberUploadsAsync_WithSpecifiedAuthority_OnlyReturnsNonInvoicedMemberUploadsForTheSpecifiedAuthority()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
              
                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

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

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

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

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.Equal(memberUpload.Id, results[0].Id);
            }
        }
        public async Task FetchInvoiceRunsAsync_Always_ReturnsResultsOrderedByIssuedDateDescending()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser user = helper.GetOrCreateUser("TestUser");

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

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

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

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

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

                wrapper.Model.SaveChanges();

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

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

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

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

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

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

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

                wrapper.Model.SaveChanges();

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

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

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

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.NotNull(results[0].IssuedByUser);
            }
        }