Esempio n. 1
0
        public static async Task GenerateSeedDealAsync(DealController sut, List <Dealer> dealers, List <Material> materials, int count = 50)
        {
            var dealersGenerator  = Gen.Elements <Dealer>(dealers).Where(x => x.Id != 1);
            var materialGenerator = Gen.Elements <Material>(materials).NonEmptyListOf();
            var barcodeGenerator  = Arb.Generate <string>();

            var sells = Gen.Choose(0, count).Select(i =>
            {
                var date = DateTime.Now;
                date     = date.AddDays(Gen.Choose(-90, 0).Sample(0, 1).Head);
                var ds   = dealersGenerator.Sample(0, 1).Single();
                return(new Deal
                {
                    BuyerId = ds.Id,
                    Items = materialGenerator.Sample(0, 1).Head.Select(m => new DealItem
                    {
                        MaterialId = m.Id,
                        PricePerOne = Gen.Choose(1, 10000).Sample(0, 1).Head,
                        Quantity = Gen.Choose(1, 100).Sample(0, 1).Head
                    }).ToList(),
                    DealTime = date,
                    DealPrice = new Payment
                    {
                        Method = Hesabdar.Models.Enums.PaymentMethod.DealPrice,
                        PayDate = date,
                        Paid = true,
                        Amount = Gen.Choose(1, 10000).Sample(0, 1).Head
                    },
                    DealPayment = new Payment
                    {
                        Method = Gen.OneOf(Gen.Constant(Hesabdar.Models.Enums.PaymentMethod.Cash), Gen.Constant(Hesabdar.Models.Enums.PaymentMethod.Cheque)).Sample(0, 1).Head,
                        PayDate = date,
                        Paid = Gen.OneOf(Gen.Constant(true), Gen.Constant(true)).Sample(0, 1).Head,
                        Amount = Gen.Choose(1, 10000).Sample(0, 1).Head
                    }
                });
            });

            foreach (var item in sells.Sample(0, count))
            {
                await sut.PostSale(item);
            }

            var purchases = Gen.Choose(0, count).Select(i =>
            {
                var ds   = dealersGenerator.Sample(0, 1).Single();
                var date = DateTime.Now;
                date     = date.AddDays(Gen.Choose(-90, 0).Sample(0, 1).Head);
                return(new Deal
                {
                    SellerId = ds.Id,
                    Items = materialGenerator.Sample(0, 1).Head.Select(m => new DealItem
                    {
                        MaterialId = m.Id,
                        PricePerOne = Gen.Choose(1, 10000).Sample(0, 1).Head,
                        Quantity = Gen.Choose(1, 100).Sample(0, 1).Head
                    }).ToList(),
                    DealTime = date,
                    DealPrice = new Payment
                    {
                        Method = Hesabdar.Models.Enums.PaymentMethod.DealPrice,
                        PayDate = date,
                        Paid = true,
                        Amount = Gen.Choose(1, 10000).Sample(0, 1).Head
                    },
                    DealPayment = new Payment
                    {
                        Method = Gen.OneOf(Gen.Constant(Hesabdar.Models.Enums.PaymentMethod.Cash), Gen.Constant(Hesabdar.Models.Enums.PaymentMethod.Cheque)).Sample(0, 1).Head,
                        PayDate = date,
                        Paid = Gen.OneOf(Gen.Constant(true), Gen.Constant(true)).Sample(0, 1).Head,
                        Amount = Gen.Choose(1, 10000).Sample(0, 1).Head
                    }
                });
            });

            foreach (var item in purchases.Sample(0, count))
            {
                await sut.PostPurchase(item);
            }
        }