Ejemplo n.º 1
0
        public async Task SpgProducerEeeDataHistoryCsvTests_EEEDataHistory_OmitsDataReturnsNotChanged()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                //Arrange
                ModelHelper helper  = new ModelHelper(db.Model);
                var         scheme1 = helper.CreateScheme();
                scheme1.ApprovalNumber = "WEE/TE3334ST/SCH";
                var memberUpload1 = helper.CreateSubmittedMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2000;

                var producer1 = helper.CreateProducerAsCompany(memberUpload1, "PRN897");
                producer1.ObligationType = "B2B";

                // Create a submission
                EeeOutputAmount eeeOutputAmount1 =
                    helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2B", 1, 100);
                EeeOutputReturnVersion eeeOutputReturnVersion1 = helper.CreateEeeOutputReturnVersion();
                helper.AddEeeOutputAmount(eeeOutputReturnVersion1, eeeOutputAmount1);

                var dataReturnVersion1 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion1.SubmittedDate = new DateTime(2015, 1, 1);

                dataReturnVersion1.EeeOutputReturnVersion = eeeOutputReturnVersion1;

                // Create two additional submissions, both having the same data
                // but are different from the first
                EeeOutputAmount eeeOutputAmount2 =
                    helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2B", 1, 200);
                EeeOutputReturnVersion eeeOutputReturnVersion2 = helper.CreateEeeOutputReturnVersion();
                helper.AddEeeOutputAmount(eeeOutputReturnVersion2, eeeOutputAmount2);

                var dataReturnVersion2 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion2.SubmittedDate = new DateTime(2015, 1, 2);

                var dataReturnVersion3 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion3.SubmittedDate = new DateTime(2015, 1, 3);

                dataReturnVersion2.EeeOutputReturnVersion = eeeOutputReturnVersion2;
                dataReturnVersion3.EeeOutputReturnVersion = eeeOutputReturnVersion2;

                db.Model.SaveChanges();

                // Act
                var results = await db.StoredProcedures.SpgProducerEeeHistoryCsvData("PRN897");

                //Assert
                Assert.NotNull(results);
                //Only shows entries for tonnage value changes and ignores the ones with no change.
                Assert.Equal(2, results.ProducerReturnsHistoryData.Count);

                Assert.Collection(results.ProducerReturnsHistoryData,
                                  (r1) => Assert.Equal(new DateTime(2015, 1, 1), r1.SubmittedDate),
                                  (r2) => Assert.Equal(new DateTime(2015, 1, 2), r2.SubmittedDate));

                Assert.Collection(results.ProducerReturnsHistoryData,
                                  (r1) => Assert.Equal("No", r1.LatestData),
                                  (r2) => Assert.Equal("Yes", r2.LatestData));
            }
        }
Ejemplo n.º 2
0
        public async Task GetChanges_WithNoEeeChanges_ReturnsEmptyResult()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme = helper.CreateScheme();

                MemberUpload memberUpload = helper.CreateSubmittedMemberUpload(scheme);
                memberUpload.ComplianceYear = 2016;

                ProducerSubmission producer = helper.CreateProducerAsCompany(memberUpload, "WEE/11BBBB11");

                var eeeOutputAmount = helper.CreateEeeOutputAmount(producer.RegisteredProducer, "B2B", 1, 10);

                var previousDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2016, 1, true);
                previousDataReturnVersion.SubmittedDate = new DateTime(2016, 1, 1);
                helper.AddEeeOutputAmount(previousDataReturnVersion, eeeOutputAmount);

                var currentDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2016, 1, true);
                currentDataReturnVersion.SubmittedDate = new DateTime(2016, 2, 1);
                helper.AddEeeOutputAmount(currentDataReturnVersion, eeeOutputAmount);

                db.Model.SaveChanges();

                var dataAccess = new GetDataReturnSubmissionEeeChangesCsvDataAccess(db.WeeeContext);

                // Act
                var results = await dataAccess.GetChanges(currentDataReturnVersion.Id, previousDataReturnVersion.Id);

                // Assert
                Assert.Empty(results.CsvData);
            }
        }
Ejemplo n.º 3
0
        public async void SpgProducerEeeDataHistoryCsvTests_EEEDataHistory_SecondSubmissionAffectsOtherProducerWhileCurrentProducerRemainsUnchanged_ReturnsOnlyOneRowForProducer()
        {
            var complianceYear = 2995;
            var producerRegistrationNumber1 = "WEE/AW0101AW";
            var producerRegistrationNumber2 = "WEE/AW0102AW";

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

                var organisation = helper.CreateOrganisation();
                var scheme       = helper.CreateScheme(organisation);
                var memberUpload = helper.CreateSubmittedMemberUpload(scheme);
                memberUpload.ComplianceYear = complianceYear;

                var producer1 = helper.CreateProducerAsCompany(memberUpload, producerRegistrationNumber1);
                var producer2 = helper.CreateProducerAsCompany(memberUpload, producerRegistrationNumber2);

                var eeeOutputAmount1 = helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2C", 1, 101);
                var eeeOutputAmount2 = helper.CreateEeeOutputAmount(producer2.RegisteredProducer, "B2C", 2, 102);
                var eeeOutputAmount3 = helper.CreateEeeOutputAmount(producer2.RegisteredProducer, "B2C", 2, 112);

                // Create first upload
                var dataReturnVersion1 = helper.CreateDataReturnVersion(scheme, complianceYear, 1);
                dataReturnVersion1.SubmittedDate = new DateTime(2015, 1, 1);

                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount1);
                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount2);

                // Create second upload with tonnage value changing for producer 2 only
                var dataReturnVersion2 = helper.CreateDataReturnVersion(scheme, complianceYear, 1);
                dataReturnVersion2.SubmittedDate = new DateTime(2015, 2, 1);

                helper.AddEeeOutputAmount(dataReturnVersion2, eeeOutputAmount1);
                helper.AddEeeOutputAmount(dataReturnVersion2, eeeOutputAmount3);

                database.Model.SaveChanges();

                // Act
                var results = await database.StoredProcedures.SpgProducerEeeHistoryCsvData(producerRegistrationNumber1);

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

                // Check first row
                var result = results.ProducerReturnsHistoryData.First();

                Assert.Equal(producerRegistrationNumber1, result.PRN);
                Assert.Equal(1, result.Quarter);
                Assert.Equal(complianceYear, result.ComplianceYear);
                Assert.Equal(101, result.Cat1B2C);
                Assert.Equal("Yes", result.LatestData);
                Assert.Equal(new DateTime(2015, 1, 1), result.SubmittedDate);
            }
        }
Ejemplo n.º 4
0
        public async Task SpgProducerEeeDataHistoryCsvTests_EEEDataHistory_ReturnsOneRowForChangedDataEvenIfOneCategoryChanged()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper  = new ModelHelper(db.Model);
                var         scheme1 = helper.CreateScheme();
                scheme1.ApprovalNumber = "WEE/TE3334ST/SCH";
                var memberUpload1 = helper.CreateSubmittedMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2000;

                var producer1 = helper.CreateProducerAsCompany(memberUpload1, "PRN897");
                producer1.ObligationType = "B2B";

                var dataReturnVersion1 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion1.SubmittedDate = new DateTime(2015, 1, 1);

                EeeOutputAmount eeeOutputAmount = helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2B", 2, 200);

                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount);
                helper.CreateEeeOutputAmount(dataReturnVersion1, producer1.RegisteredProducer, "B2B", 1, 100);

                // Second upload with only category 1 changed, category 2 remains unchanged
                var dataReturnVersion2 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion2.SubmittedDate = new DateTime(2015, 1, 2);

                helper.AddEeeOutputAmount(dataReturnVersion2, eeeOutputAmount);
                helper.CreateEeeOutputAmount(dataReturnVersion2, producer1.RegisteredProducer, "B2B", 1, 300);

                db.Model.SaveChanges();

                // Act
                var results = await db.StoredProcedures.SpgProducerEeeHistoryCsvData("PRN897");

                // Assert
                Assert.NotNull(results);
                // Only shows entries for tonnage value changes and ignores the ones with no change.
                Assert.Equal(2, results.ProducerReturnsHistoryData.Count);

                Assert.Collection(results.ProducerReturnsHistoryData,
                                  (r1) => Assert.Equal(new DateTime(2015, 1, 1), r1.SubmittedDate),
                                  (r2) => Assert.Equal(new DateTime(2015, 1, 2), r2.SubmittedDate));

                Assert.Collection(results.ProducerReturnsHistoryData,
                                  (r1) => Assert.Equal("No", r1.LatestData),
                                  (r2) => Assert.Equal("Yes", r2.LatestData));

                Assert.Collection(results.ProducerReturnsHistoryData,
                                  (r1) => Assert.Equal(100, r1.Cat1B2B),
                                  (r2) => Assert.Equal(300, r2.Cat1B2B));

                Assert.Collection(results.ProducerReturnsHistoryData,
                                  (r1) => Assert.Equal(200, r1.Cat2B2B),
                                  (r2) => Assert.Equal(200, r2.Cat2B2B));
            }
        }
Ejemplo n.º 5
0
        public async Task GetChanges_WithRemovedProducerEeeAmount_ReturnsRowWithRemovedProducer()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme = helper.CreateScheme();

                MemberUpload memberUpload = helper.CreateSubmittedMemberUpload(scheme);
                memberUpload.ComplianceYear = 2016;

                var producer  = helper.CreateProducerAsCompany(memberUpload, "WEE/11BBBB11");
                var producer2 = helper.CreateProducerAsCompany(memberUpload, "WEE/11BBBB22");

                var eeeOutputAmount1 = helper.CreateEeeOutputAmount(producer.RegisteredProducer, "B2B", 1, 10);
                var eeeOutputAmount2 = helper.CreateEeeOutputAmount(producer2.RegisteredProducer, "B2B", 2, 20);

                var previousDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2016, 1, true);
                previousDataReturnVersion.SubmittedDate = new DateTime(2016, 1, 1);
                helper.AddEeeOutputAmount(previousDataReturnVersion, eeeOutputAmount1);
                helper.AddEeeOutputAmount(previousDataReturnVersion, eeeOutputAmount2);

                var currentDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2016, 1, true);
                currentDataReturnVersion.SubmittedDate = new DateTime(2016, 2, 1);
                helper.AddEeeOutputAmount(currentDataReturnVersion, eeeOutputAmount1);

                db.Model.SaveChanges();

                var dataAccess = new GetDataReturnSubmissionEeeChangesCsvDataAccess(db.WeeeContext);

                // Act
                var results = await dataAccess.GetChanges(currentDataReturnVersion.Id, previousDataReturnVersion.Id);

                // Assert
                Assert.Single(results.CsvData);
                Assert.Equal(DataReturnSubmissionChangeType.Removed, results.CsvData[0].ChangeType);
                Assert.Null(results.CsvData[0].Cat2B2B);
                Assert.Equal(new DateTime(2016, 2, 1), results.CsvData[0].SubmissionDate);
            }
        }
Ejemplo n.º 6
0
        public async void SpgProducerEeeDataHistoryCsvTests_EEEDataHistory_ProducerHasExistingEeeAndThenOneCategoryRemoved_ReturnsRowsWithAndWithoutRemovedCategory()
        {
            var complianceYear             = 2995;
            var producerRegistrationNumber = "WEE/AW0101AW";

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

                var organisation = helper.CreateOrganisation();
                var scheme       = helper.CreateScheme(organisation);
                var memberUpload = helper.CreateSubmittedMemberUpload(scheme);
                memberUpload.ComplianceYear = complianceYear;

                var producer1 = helper.CreateProducerAsCompany(memberUpload, producerRegistrationNumber);

                var eeeOutputAmount1 = helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2C", 1, 101);
                var eeeOutputAmount2 = helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2C", 2, 102);
                var eeeOutputAmount3 = helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2B", 3, 203);

                // Create first upload with two categories
                var dataReturnVersion1 = helper.CreateDataReturnVersion(scheme, complianceYear, 1);
                dataReturnVersion1.SubmittedDate = new DateTime(2015, 1, 1);

                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount1);
                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount2);
                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount3);

                // Create second upload with one of the original categories removed
                var dataReturnVersion2 = helper.CreateDataReturnVersion(scheme, complianceYear, 1);
                dataReturnVersion2.SubmittedDate = new DateTime(2015, 2, 1);

                helper.AddEeeOutputAmount(dataReturnVersion2, eeeOutputAmount1);
                helper.AddEeeOutputAmount(dataReturnVersion2, eeeOutputAmount3);

                database.Model.SaveChanges();

                // Act
                var results = await database.StoredProcedures.SpgProducerEeeHistoryCsvData(producerRegistrationNumber);

                // Assert
                Assert.Equal(2, results.ProducerReturnsHistoryData.Count);

                // Check first row
                var result1 = results.ProducerReturnsHistoryData.First();

                Assert.Equal(producerRegistrationNumber, result1.PRN);
                Assert.Equal(1, result1.Quarter);
                Assert.Equal(complianceYear, result1.ComplianceYear);

                Assert.Equal(101, result1.Cat1B2C);
                Assert.Equal(102, result1.Cat2B2C);

                // Check second row
                var result2 = results.ProducerReturnsHistoryData.Last();

                Assert.Equal(producerRegistrationNumber, result2.PRN);
                Assert.Equal(1, result2.Quarter);
                Assert.Equal(complianceYear, result2.ComplianceYear);

                Assert.Equal(101, result2.Cat1B2C);
                Assert.Null(result2.Cat2B2C);
            }
        }
Ejemplo n.º 7
0
        public async Task SpgProducerEeeDataHistoryCsvTests_EEEDataHistory_SchemeRemovesProducerAfterFirstUploadAndAddLaterAgainInThirdUpload_Returns3RowEvenIfDataIsSame()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper  = new ModelHelper(db.Model);
                var         scheme1 = helper.CreateScheme();
                scheme1.ApprovalNumber = "WEE/TE3334ST/SCH";
                var memberUpload1 = helper.CreateSubmittedMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2000;

                var producer1 = helper.CreateProducerAsCompany(memberUpload1, "PRN897");
                producer1.ObligationType = "B2B";

                var producer2 = helper.CreateProducerAsCompany(memberUpload1, "PRN123");
                producer2.ObligationType = "B2B";

                EeeOutputAmount eeeOutputAmount1 =
                    helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2B", 1, 100);

                EeeOutputAmount eeeOutputAmount2 =
                    helper.CreateEeeOutputAmount(producer2.RegisteredProducer, "B2B", 1, 200);

                // Create a data return version with submission for 2 producers
                var dataReturnVersion1 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion1.SubmittedDate = new DateTime(2015, 1, 1);

                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount1);
                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount2);

                // Second data return version with producer 1 removed
                var dataReturnVersion2 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion2.SubmittedDate = new DateTime(2015, 1, 2);

                helper.AddEeeOutputAmount(dataReturnVersion2, eeeOutputAmount2);

                // Third data return version with producer 1 added back again
                var dataReturnVersion3 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion3.SubmittedDate = new DateTime(2015, 1, 3);

                helper.CreateEeeOutputAmount(dataReturnVersion3, producer1.RegisteredProducer, "B2B", 1, 100);

                db.Model.SaveChanges();

                // Act
                var results = await db.StoredProcedures.SpgProducerEeeHistoryCsvData("PRN897");

                //Assert
                Assert.NotNull(results);

                Assert.Equal(2, results.ProducerReturnsHistoryData.Count);

                Assert.Collection(results.ProducerReturnsHistoryData,
                                  (r1) => Assert.Equal(new DateTime(2015, 1, 1), r1.SubmittedDate),
                                  (r2) => Assert.Equal(new DateTime(2015, 1, 3), r2.SubmittedDate));

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

                Assert.Collection(results.ProducerRemovedFromReturnsData,
                                  (r1) => Assert.Equal(new DateTime(2015, 1, 2), r1.SubmittedDate));

                Assert.Collection(results.ProducerRemovedFromReturnsData,
                                  (r1) => Assert.Equal("WEE/TE3334ST/SCH", r1.ApprovalNumber));

                Assert.Collection(results.ProducerRemovedFromReturnsData,
                                  (r1) => Assert.Equal(1, r1.Quarter));
            }
        }
        public async void SpgProducerEeeDataHistoryCsvTests_EEEDataHistory_SecondSubmissionAffectsOtherProducerWhileCurrentProducerRemainsUnchanged_ReturnsOnlyOneRowForProducer()
        {
            var complianceYear = 2995;
            var producerRegistrationNumber1 = "WEE/AW0101AW";
            var producerRegistrationNumber2 = "WEE/AW0102AW";

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

                var organisation = helper.CreateOrganisation();
                var scheme = helper.CreateScheme(organisation);
                var memberUpload = helper.CreateSubmittedMemberUpload(scheme);
                memberUpload.ComplianceYear = complianceYear;

                var producer1 = helper.CreateProducerAsCompany(memberUpload, producerRegistrationNumber1);
                var producer2 = helper.CreateProducerAsCompany(memberUpload, producerRegistrationNumber2);

                var eeeOutputAmount1 = helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2C", 1, 101);
                var eeeOutputAmount2 = helper.CreateEeeOutputAmount(producer2.RegisteredProducer, "B2C", 2, 102);
                var eeeOutputAmount3 = helper.CreateEeeOutputAmount(producer2.RegisteredProducer, "B2C", 2, 112);

                // Create first upload
                var dataReturnVersion1 = helper.CreateDataReturnVersion(scheme, complianceYear, 1);
                dataReturnVersion1.SubmittedDate = new DateTime(2015, 1, 1);

                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount1);
                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount2);

                // Create second upload with tonnage value changing for producer 2 only
                var dataReturnVersion2 = helper.CreateDataReturnVersion(scheme, complianceYear, 1);
                dataReturnVersion2.SubmittedDate = new DateTime(2015, 2, 1);

                helper.AddEeeOutputAmount(dataReturnVersion2, eeeOutputAmount1);
                helper.AddEeeOutputAmount(dataReturnVersion2, eeeOutputAmount3);

                database.Model.SaveChanges();

                // Act
                var results = await database.StoredProcedures.SpgProducerEeeHistoryCsvData(producerRegistrationNumber1);

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

                // Check first row
                var result = results.ProducerReturnsHistoryData.First();

                Assert.Equal(producerRegistrationNumber1, result.PRN);
                Assert.Equal(1, result.Quarter);
                Assert.Equal(complianceYear, result.ComplianceYear);
                Assert.Equal(101, result.Cat1B2C);
                Assert.Equal("Yes", result.LatestData);
                Assert.Equal(new DateTime(2015, 1, 1), result.SubmittedDate);
            }
        }
        public async void SpgProducerEeeDataHistoryCsvTests_EEEDataHistory_ProducerHasExistingEeeAndThenOneCategoryRemoved_ReturnsRowsWithAndWithoutRemovedCategory()
        {
            var complianceYear = 2995;
            var producerRegistrationNumber = "WEE/AW0101AW";

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

                var organisation = helper.CreateOrganisation();
                var scheme = helper.CreateScheme(organisation);
                var memberUpload = helper.CreateSubmittedMemberUpload(scheme);
                memberUpload.ComplianceYear = complianceYear;

                var producer1 = helper.CreateProducerAsCompany(memberUpload, producerRegistrationNumber);

                var eeeOutputAmount1 = helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2C", 1, 101);
                var eeeOutputAmount2 = helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2C", 2, 102);
                var eeeOutputAmount3 = helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2B", 3, 203);

                // Create first upload with two categories
                var dataReturnVersion1 = helper.CreateDataReturnVersion(scheme, complianceYear, 1);
                dataReturnVersion1.SubmittedDate = new DateTime(2015, 1, 1);

                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount1);
                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount2);
                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount3);

                // Create second upload with one of the original categories removed
                var dataReturnVersion2 = helper.CreateDataReturnVersion(scheme, complianceYear, 1);
                dataReturnVersion2.SubmittedDate = new DateTime(2015, 2, 1);

                helper.AddEeeOutputAmount(dataReturnVersion2, eeeOutputAmount1);
                helper.AddEeeOutputAmount(dataReturnVersion2, eeeOutputAmount3);

                database.Model.SaveChanges();

                // Act
                var results = await database.StoredProcedures.SpgProducerEeeHistoryCsvData(producerRegistrationNumber);

                // Assert
                Assert.Equal(2, results.ProducerReturnsHistoryData.Count);

                // Check first row
                var result1 = results.ProducerReturnsHistoryData.First();

                Assert.Equal(producerRegistrationNumber, result1.PRN);
                Assert.Equal(1, result1.Quarter);
                Assert.Equal(complianceYear, result1.ComplianceYear);

                Assert.Equal(101, result1.Cat1B2C);
                Assert.Equal(102, result1.Cat2B2C);

                // Check second row
                var result2 = results.ProducerReturnsHistoryData.Last();

                Assert.Equal(producerRegistrationNumber, result2.PRN);
                Assert.Equal(1, result2.Quarter);
                Assert.Equal(complianceYear, result2.ComplianceYear);

                Assert.Equal(101, result2.Cat1B2C);
                Assert.Null(result2.Cat2B2C);
            }
        }
        public async Task SpgProducerEeeDataHistoryCsvTests_EEEDataHistory_ReturnsOneRowForChangedDataEvenIfOneCategoryChanged()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);
                var scheme1 = helper.CreateScheme();
                scheme1.ApprovalNumber = "WEE/TE3334ST/SCH";
                var memberUpload1 = helper.CreateSubmittedMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2000;

                var producer1 = helper.CreateProducerAsCompany(memberUpload1, "PRN897");
                producer1.ObligationType = "B2B";

                var dataReturnVersion1 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion1.SubmittedDate = new DateTime(2015, 1, 1);

                EeeOutputAmount eeeOutputAmount = helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2B", 2, 200);

                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount);
                helper.CreateEeeOutputAmount(dataReturnVersion1, producer1.RegisteredProducer, "B2B", 1, 100);

                // Second upload with only category 1 changed, category 2 remains unchanged
                var dataReturnVersion2 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion2.SubmittedDate = new DateTime(2015, 1, 2);

                helper.AddEeeOutputAmount(dataReturnVersion2, eeeOutputAmount);
                helper.CreateEeeOutputAmount(dataReturnVersion2, producer1.RegisteredProducer, "B2B", 1, 300);

                db.Model.SaveChanges();

                // Act
                var results = await db.StoredProcedures.SpgProducerEeeHistoryCsvData("PRN897");

                // Assert
                Assert.NotNull(results);
                // Only shows entries for tonnage value changes and ignores the ones with no change.
                Assert.Equal(2, results.ProducerReturnsHistoryData.Count);

                Assert.Collection(results.ProducerReturnsHistoryData,
                   (r1) => Assert.Equal(new DateTime(2015, 1, 1), r1.SubmittedDate),
                   (r2) => Assert.Equal(new DateTime(2015, 1, 2), r2.SubmittedDate));

                Assert.Collection(results.ProducerReturnsHistoryData,
                  (r1) => Assert.Equal("No", r1.LatestData),
                  (r2) => Assert.Equal("Yes", r2.LatestData));

                Assert.Collection(results.ProducerReturnsHistoryData,
                  (r1) => Assert.Equal(100, r1.Cat1B2B),
                  (r2) => Assert.Equal(300, r2.Cat1B2B));

                Assert.Collection(results.ProducerReturnsHistoryData,
                  (r1) => Assert.Equal(200, r1.Cat2B2B),
                  (r2) => Assert.Equal(200, r2.Cat2B2B));
            }
        }
        public async Task SpgProducerEeeDataHistoryCsvTests_EEEDataHistory_SchemeRemovesProducerAfterFirstUploadAndAddLaterAgainInThirdUpload_Returns3RowEvenIfDataIsSame()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);
                var scheme1 = helper.CreateScheme();
                scheme1.ApprovalNumber = "WEE/TE3334ST/SCH";
                var memberUpload1 = helper.CreateSubmittedMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2000;

                var producer1 = helper.CreateProducerAsCompany(memberUpload1, "PRN897");
                producer1.ObligationType = "B2B";

                var producer2 = helper.CreateProducerAsCompany(memberUpload1, "PRN123");
                producer2.ObligationType = "B2B";

                EeeOutputAmount eeeOutputAmount1 =
                    helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2B", 1, 100);

                EeeOutputAmount eeeOutputAmount2 =
                    helper.CreateEeeOutputAmount(producer2.RegisteredProducer, "B2B", 1, 200);

                // Create a data return version with submission for 2 producers
                var dataReturnVersion1 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion1.SubmittedDate = new DateTime(2015, 1, 1);

                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount1);
                helper.AddEeeOutputAmount(dataReturnVersion1, eeeOutputAmount2);

                // Second data return version with producer 1 removed 
                var dataReturnVersion2 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion2.SubmittedDate = new DateTime(2015, 1, 2);

                helper.AddEeeOutputAmount(dataReturnVersion2, eeeOutputAmount2);

                // Third data return version with producer 1 added back again
                var dataReturnVersion3 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion3.SubmittedDate = new DateTime(2015, 1, 3);

                helper.CreateEeeOutputAmount(dataReturnVersion3, producer1.RegisteredProducer, "B2B", 1, 100);

                db.Model.SaveChanges();

                // Act
                var results = await db.StoredProcedures.SpgProducerEeeHistoryCsvData("PRN897");

                //Assert
                Assert.NotNull(results);

                Assert.Equal(2, results.ProducerReturnsHistoryData.Count);

                Assert.Collection(results.ProducerReturnsHistoryData,
                   (r1) => Assert.Equal(new DateTime(2015, 1, 1), r1.SubmittedDate),
                   (r2) => Assert.Equal(new DateTime(2015, 1, 3), r2.SubmittedDate));

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

                Assert.Collection(results.ProducerRemovedFromReturnsData,
                   (r1) => Assert.Equal(new DateTime(2015, 1, 2), r1.SubmittedDate));

                Assert.Collection(results.ProducerRemovedFromReturnsData,
                  (r1) => Assert.Equal("WEE/TE3334ST/SCH", r1.ApprovalNumber));

                Assert.Collection(results.ProducerRemovedFromReturnsData,
                   (r1) => Assert.Equal(1, r1.Quarter));
            }
        }
        public async Task SpgProducerEeeDataHistoryCsvTests_EEEDataHistory_OmitsDataReturnsNotChanged()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                //Arrange
                ModelHelper helper = new ModelHelper(db.Model);
                var scheme1 = helper.CreateScheme();
                scheme1.ApprovalNumber = "WEE/TE3334ST/SCH";
                var memberUpload1 = helper.CreateSubmittedMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2000;

                var producer1 = helper.CreateProducerAsCompany(memberUpload1, "PRN897");
                producer1.ObligationType = "B2B";

                // Create a submission
                EeeOutputAmount eeeOutputAmount1 =
                    helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2B", 1, 100);
                EeeOutputReturnVersion eeeOutputReturnVersion1 = helper.CreateEeeOutputReturnVersion();
                helper.AddEeeOutputAmount(eeeOutputReturnVersion1, eeeOutputAmount1);

                var dataReturnVersion1 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion1.SubmittedDate = new DateTime(2015, 1, 1);

                dataReturnVersion1.EeeOutputReturnVersion = eeeOutputReturnVersion1;

                // Create two additional submissions, both having the same data
                // but are different from the first
                EeeOutputAmount eeeOutputAmount2 =
                    helper.CreateEeeOutputAmount(producer1.RegisteredProducer, "B2B", 1, 200);
                EeeOutputReturnVersion eeeOutputReturnVersion2 = helper.CreateEeeOutputReturnVersion();
                helper.AddEeeOutputAmount(eeeOutputReturnVersion2, eeeOutputAmount2);

                var dataReturnVersion2 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion2.SubmittedDate = new DateTime(2015, 1, 2);

                var dataReturnVersion3 = helper.CreateDataReturnVersion(scheme1, 2000, 1);
                dataReturnVersion3.SubmittedDate = new DateTime(2015, 1, 3);

                dataReturnVersion2.EeeOutputReturnVersion = eeeOutputReturnVersion2;
                dataReturnVersion3.EeeOutputReturnVersion = eeeOutputReturnVersion2;

                db.Model.SaveChanges();

                // Act
                var results = await db.StoredProcedures.SpgProducerEeeHistoryCsvData("PRN897");

                //Assert
                Assert.NotNull(results);
                //Only shows entries for tonnage value changes and ignores the ones with no change.
                Assert.Equal(2, results.ProducerReturnsHistoryData.Count);

                Assert.Collection(results.ProducerReturnsHistoryData,
                   (r1) => Assert.Equal(new DateTime(2015, 1, 1), r1.SubmittedDate),
                   (r2) => Assert.Equal(new DateTime(2015, 1, 2), r2.SubmittedDate));

                Assert.Collection(results.ProducerReturnsHistoryData,
                  (r1) => Assert.Equal("No", r1.LatestData),
                  (r2) => Assert.Equal("Yes", r2.LatestData));
            }
        }