public void ApportionCostsSafeOnEmptyList()
        {
            var data = new TestApportionable[0];

            var apportioner = new CostApportioner <TestApportionable>(x => x.Cost, (x, y) => x.Cost = y, x => x.IsApportionable);

            apportioner.ApportionCost(data, 40.0m);
        }
예제 #2
0
        private void allocateKoreanPayment_Click(object sender, RoutedEventArgs e)
        {
            var contestantIds = new List <int>()
            {
                10975
                , 10979
                , 11386
                , 11387
                , 11388
                , 11389
                , 11390
                , 11391
                , 11392
                , 11393
                , 11394
                , 11395
                , 11397
            };

            var context         = DataEntitiesProvider.Provide();
            var currentOlympiad = context.Olympiad_Infoes.First(x => x.Current);
            var entries         = context.Entrants.Where(x => contestantIds.Contains(x.Name.Mind_Sport_ID) &&
                                                         x.OlympiadId == currentOlympiad.Id).ToList();

            var costapportioner = new CostApportioner <Entrant>(x => x.Fee, (x, f) => x.Fee = f, x => true);

            costapportioner.ApportionCost(entries, 869.89m);
            context.SaveChanges();

            foreach (var contestantId in contestantIds)
            {
                var contestant = context.Contestants.First(x => x.Mind_Sport_ID == contestantId);
                var owed       = entries.Where(x => x.Name.Mind_Sport_ID == contestantId).Sum(x => x.Fee);
                var payment    = new Payment()
                {
                    Banked         = 2017,
                    MindSportsID   = contestantId,
                    Name           = contestant,
                    OlympiadId     = currentOlympiad.Id,
                    Payment_Method = "Group cheque (Korea)",
                    Year           = 2017,
                    Payment1       = owed,
                    Received       = DateTime.Now
                };
                context.Payments.Add(payment);
            }

            context.SaveChanges();
        }
        public void ApportionCostsWithOneToIgnore()
        {
            var data = new[] {
                new TestApportionable {
                    Cost = 15, IsApportionable = true
                },
                new TestApportionable {
                    Cost = 15, IsApportionable = false
                },
                new TestApportionable {
                    Cost = 15, IsApportionable = true
                }
            };
            var apportioner = new CostApportioner <TestApportionable>(x => x.Cost, (x, y) => x.Cost = y, x => x.IsApportionable);

            apportioner.ApportionCost(data, 20.0m);
            Assert.AreEqual(10.0m, data[0].Cost);
            Assert.AreEqual(15.0m, data[1].Cost);
            Assert.AreEqual(10.0m, data[2].Cost);
        }
        public void ApportionCostsComplexCase()
        {
            var data = new[] {
                new TestApportionable {
                    Cost = 10, IsApportionable = true
                },
                new TestApportionable {
                    Cost = 15, IsApportionable = true
                },
                new TestApportionable {
                    Cost = 10, IsApportionable = true
                }
            };
            var apportioner = new CostApportioner <TestApportionable>(x => x.Cost, (x, y) => x.Cost = y, x => x.IsApportionable);

            apportioner.ApportionCost(data, 28.0m);
            Assert.AreEqual(8.0m, data[0].Cost);
            Assert.AreEqual(12.0m, data[1].Cost);
            Assert.AreEqual(8.0m, data[2].Cost);
        }
        public void ApportionCostsSimpleCase_RoundsToPennies()
        {
            var data = new[] {
                new TestApportionable {
                    Cost = 15, IsApportionable = true
                },
                new TestApportionable {
                    Cost = 15, IsApportionable = true
                },
                new TestApportionable {
                    Cost = 15, IsApportionable = true
                }
            };
            var apportioner = new CostApportioner <TestApportionable>(x => x.Cost, (x, y) => x.Cost = y, x => x.IsApportionable);

            apportioner.ApportionCost(data, 40.0m);
            Assert.AreEqual(13.33m, data[0].Cost);
            Assert.AreEqual(13.34m, data[1].Cost);
            Assert.AreEqual(13.33m, data[2].Cost);
        }
        public void ApportionCostsDoesNothingWhenTotalTooLarge()
        {
            var data = new[] {
                new TestApportionable {
                    Cost = 10, IsApportionable = true
                },
                new TestApportionable {
                    Cost = 20, IsApportionable = true
                },
                new TestApportionable {
                    Cost = 30, IsApportionable = true
                }
            };
            var apportioner = new CostApportioner <TestApportionable>(x => x.Cost, (x, y) => x.Cost = y, x => x.IsApportionable);

            apportioner.ApportionCost(data, 80.0m);
            Assert.AreEqual(10m, data[0].Cost);
            Assert.AreEqual(20m, data[1].Cost);
            Assert.AreEqual(30m, data[2].Cost);
        }
        public void ApportionCostsWithAllToIgnore()
        {
            var data = new[] {
                new TestApportionable {
                    Cost = 10, IsApportionable = false
                },
                new TestApportionable {
                    Cost = 20, IsApportionable = false
                },
                new TestApportionable {
                    Cost = 30, IsApportionable = false
                }
            };
            var apportioner = new CostApportioner <TestApportionable>(x => x.Cost, (x, y) => x.Cost = y, x => x.IsApportionable);

            apportioner.ApportionCost(data, 40.0m);
            Assert.AreEqual(10m, data[0].Cost);
            Assert.AreEqual(20m, data[1].Cost);
            Assert.AreEqual(30m, data[2].Cost);
        }
        public void ApportionCostsSimpleCase_DoingItTwiceGivesSameResult()
        {
            var data = new[] {
                new TestApportionable {
                    Cost = 15, IsApportionable = true
                },
                new TestApportionable {
                    Cost = 15, IsApportionable = true
                },
                new TestApportionable {
                    Cost = 15, IsApportionable = true
                }
            };
            var apportioner = new CostApportioner <TestApportionable>(x => x.Cost, (x, y) => x.Cost = y, x => x.IsApportionable);

            apportioner.ApportionCost(data, 40.0m);
            apportioner.ApportionCost(data, 40.0m);
            Assert.AreEqual(13.33m, data[0].Cost);
            Assert.AreEqual(13.34m, data[1].Cost);
            Assert.AreEqual(13.33m, data[2].Cost);
        }
        public void ApportionCosts()
        {
            var context  = DataEntitiesProvider.Provide();
            var olympiad = context.Olympiad_Infoes.First(x => x.Id == CurrentOlympiadId);

            var canApportion = (!IsJuniorForOlympiad) ? olympiad.MaxFee.HasValue : olympiad.MaxCon.HasValue;

            if (!canApportion)
            {
                return;
            }

            var maxFee = (!IsJuniorForOlympiad) ?
                         olympiad.MaxFee.Value : olympiad.MaxCon.Value;

            var apportioner = new CostApportioner <EventVm>(
                x => x.StandardFee, (e, f) => e.Fee = f, x => x.IncludedInMaxFee);

            apportioner.ApportionCost(Events, maxFee);

            OnPropertyChanged("Totals");
        }