public async Task Build_ExistingLatestSubmittedDataReturnVersion_WithAllExistingWeeeCollectedAmounts_ReturnsDataReturnVersionWithExistingWeeeCollectedReturnVersion()
        {
            var weeeCollectedReturnVersion = new WeeeCollectedReturnVersion();

            weeeCollectedReturnVersion.AddWeeeCollectedAmount(
                new WeeeCollectedAmount(WeeeCollectedAmountSourceType.Dcf, ObligationType.B2C, WeeeCategory.ConsumerEquipment, 100));

            var dataReturn        = new DataReturn(A.Dummy <Scheme>(), A.Dummy <Quarter>());
            var dataReturnVersion = new DataReturnVersion(dataReturn, weeeCollectedReturnVersion,
                                                          A.Dummy <WeeeDeliveredReturnVersion>(), A.Dummy <EeeOutputReturnVersion>());

            dataReturn.SetCurrentVersion(dataReturnVersion);

            var helper = new DataReturnVersionBuilderHelper();

            A.CallTo(() => helper.DataAccess.FetchDataReturnOrDefault())
            .Returns(dataReturn);

            var builder = helper.Create();
            await builder.AddWeeeCollectedAmount(WeeeCollectedAmountSourceType.Dcf, WeeeCategory.ConsumerEquipment, ObligationType.B2C, 100);

            var result = await builder.Build();

            Assert.Same(weeeCollectedReturnVersion, result.DataReturnVersion.WeeeCollectedReturnVersion);
        }
        public void AddWeeeCollectedAmount_AddsToWeeeCollectedAmounts()
        {
            // Arrange
            var collectedReturnVersion = new WeeeCollectedReturnVersion();
            var amount = new WeeeCollectedAmount(
                A.Dummy <WeeeCollectedAmountSourceType>(), ObligationType.B2B, A.Dummy <WeeeCategory>(), A.Dummy <decimal>());

            // Act
            collectedReturnVersion.AddWeeeCollectedAmount(amount);

            // Assert
            Assert.Contains(amount, collectedReturnVersion.WeeeCollectedAmounts);
        }
Exemplo n.º 3
0
        private WeeeCollectedReturnVersion BuildWeeeCollectedReturnVersion(DataReturnVersion submittedDataReturnVersion)
        {
            WeeeCollectedReturnVersion weeeCollectedReturnVersion = null;

            // Unchanged data from the latest submitted data return version can be reused. Check whether all or some of them can be reused.
            if (weeeCollectedAmounts.Any())
            {
                ICollection <WeeeCollectedAmount> mergedWeeeCollectedAmounts;
                bool reuseLatestWeeeCollectedReturnVersion = false;

                if (submittedDataReturnVersion != null &&
                    submittedDataReturnVersion.WeeeCollectedReturnVersion != null)
                {
                    reuseLatestWeeeCollectedReturnVersion =
                        ReuseEqualItems(weeeCollectedAmounts, submittedDataReturnVersion.WeeeCollectedReturnVersion.WeeeCollectedAmounts, out mergedWeeeCollectedAmounts);
                }
                else
                {
                    mergedWeeeCollectedAmounts = weeeCollectedAmounts;
                }

                if (reuseLatestWeeeCollectedReturnVersion)
                {
                    weeeCollectedReturnVersion = submittedDataReturnVersion.WeeeCollectedReturnVersion;
                }
                else
                {
                    weeeCollectedReturnVersion = new WeeeCollectedReturnVersion();
                    foreach (var weeeCollectedAmount in mergedWeeeCollectedAmounts)
                    {
                        weeeCollectedReturnVersion.AddWeeeCollectedAmount(weeeCollectedAmount);
                    }
                }
            }

            return(weeeCollectedReturnVersion);
        }
        public async Task Build_ExistingLatestSubmittedDataReturnVersion_WithSomeExistingWeeeCollectedAmounts_ReturnsDataReturnVersionWithExistingWeeeCollectedAmounts()
        {
            var weeeCollectedAmount1 = new WeeeCollectedAmount(WeeeCollectedAmountSourceType.Dcf, ObligationType.B2C, WeeeCategory.DisplayEquipment, 100);
            var weeeCollectedAmount2 = new WeeeCollectedAmount(WeeeCollectedAmountSourceType.Dcf, ObligationType.B2C, WeeeCategory.ConsumerEquipment, 100);
            var weeeCollectedAmount3 = new WeeeCollectedAmount(WeeeCollectedAmountSourceType.Distributor, ObligationType.B2C, WeeeCategory.ConsumerEquipment, 100);
            var weeeCollectedAmount4 = new WeeeCollectedAmount(WeeeCollectedAmountSourceType.FinalHolder, ObligationType.B2C, WeeeCategory.ConsumerEquipment, 100);

            var weeeCollectedReturnVersion = new WeeeCollectedReturnVersion();
            weeeCollectedReturnVersion.AddWeeeCollectedAmount(weeeCollectedAmount1);
            weeeCollectedReturnVersion.AddWeeeCollectedAmount(weeeCollectedAmount2);
            weeeCollectedReturnVersion.AddWeeeCollectedAmount(weeeCollectedAmount3);
            weeeCollectedReturnVersion.AddWeeeCollectedAmount(weeeCollectedAmount4);

            var dataReturn = new DataReturn(A.Dummy<Scheme>(), A.Dummy<Quarter>());
            var dataReturnVersion = new DataReturnVersion(dataReturn, weeeCollectedReturnVersion,
                A.Dummy<WeeeDeliveredReturnVersion>(), A.Dummy<EeeOutputReturnVersion>());
            dataReturn.SetCurrentVersion(dataReturnVersion);

            var helper = new DataReturnVersionBuilderHelper();

            A.CallTo(() => helper.DataAccess.FetchDataReturnOrDefault())
               .Returns(dataReturn);

            var builder = helper.Create();
            await builder.AddWeeeCollectedAmount(WeeeCollectedAmountSourceType.Dcf, WeeeCategory.ConsumerEquipment, ObligationType.B2C, 100);
            await builder.AddWeeeCollectedAmount(WeeeCollectedAmountSourceType.Distributor, WeeeCategory.ConsumerEquipment, ObligationType.B2C, 100);

            var result = await builder.Build();

            Assert.NotSame(weeeCollectedReturnVersion, result.DataReturnVersion.WeeeCollectedReturnVersion);
            Assert.Collection(result.DataReturnVersion.WeeeCollectedReturnVersion.WeeeCollectedAmounts,
                r1 => Assert.Same(weeeCollectedAmount2, r1),
                r2 => Assert.Same(weeeCollectedAmount3, r2));
        }