Exemplo n.º 1
0
        public void GetMaterialAmountOverTime_ShouldBeIntegrated()
        {
            var dealersResult = dealerController.Dealers().GetObject <PagedResult <Dealer> >().Queryable.ToArray();
            var dealersGen    = ControllerHelper.ChooseFrom(dealersResult);

            var materialsResult = materialController.GetMaterials(1, int.MaxValue).GetObject <PagedResult <Material> >().Queryable.ToArray();
            var materialsGen    = ControllerHelper.ChooseFrom(materialsResult);

            Prop.ForAll <int[]>((i) =>
            {
                var material = materialsGen.Sample(0, 1).Head;
                var dealer   = dealersGen.Sample(0, 1).Head;
                //100 to 50 days later
                var dateEnd   = DateTime.Now.AddDays(Gen.Choose(-50, 0).Sample(0, 1).Head);
                var dateStart = dateEnd.AddDays(Gen.Choose(-50, 0).Sample(0, 1).Head);
                //130 to 20 days later
                var dateEndMargin   = dateEnd.AddDays(Gen.Choose(0, 30).Sample(0, 1).Head);
                var dateStartMargin = dateStart.AddDays(Gen.Choose(-30, 0).Sample(0, 1).Head);


                var materialOverTime         = sut.GetMaterialAmountOverTime(material.Id, dealer.Id, dateStart, dateEnd).Result.GetObject <IEnumerable <AmountOverDateModel> >();
                var materialOverTimeMargined = sut.GetMaterialAmountOverTime(material.Id, dealer.Id, dateStartMargin, dateEndMargin).Result.GetObject <IEnumerable <AmountOverDateModel> >();

                foreach (var item in materialOverTime)
                {
                    var marginedItem = materialOverTimeMargined.Where(m => ((DateTime)m.Date).Date == ((DateTime)item.Date).Date).Single();

                    Assert.AreEqual(item.Amount, marginedItem.Amount);
                }
            }).QuickCheckThrowOnFailure();
        }