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();
        }
Exemplo n.º 2
0
        public async Task InitializeAsync()
        {
            var db = new DbContextOptionsBuilder <HesabdarContext>()
                     .UseInMemoryDatabase(databaseName: "test", new InMemoryDatabaseRoot());

            context = new HesabdarContext(db.Options);
            context.Database.EnsureCreated();

            materialController = new MaterialController(context);
            dealerController   = new DealerController(context);
            sut = new DealController(context);
            await TestDataGenerator.GenerateSeedMaterialAsync(materialController);

            await TestDataGenerator.GenerateSeedDealersAsync(dealerController);

            var materials = materialController.GetMaterials(1, Int32.MaxValue).GetObject <PagedResult <Material> >().Queryable.ToList();
            var dealers   = dealerController.Dealers(1, Int32.MaxValue).GetObject <PagedResult <Dealer> >().Queryable.ToList();
            await TestDataGenerator.GenerateSeedDealAsync(sut, dealers, materials);
        }
Exemplo n.º 3
0
        public async Task GetMaterialsTest()
        {
            var mockRepo   = new Mock <IFloraRepository>();
            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(m => m.Map <IEnumerable <MaterialDTO> >(It.IsAny <IEnumerable <Material> >()))
            .Returns((IEnumerable <Material> source) => GetTestMapping(source));
            mockRepo.Setup(repo => repo.GetMaterials()).Returns(Task.FromResult((IEnumerable <Material>)GetTestMaterials()));

            var controller = new MaterialController(mockRepo.Object, mockMapper.Object);


            var result = await controller.GetMaterials();

            var okObjectResult = result as OkObjectResult;

            Assert.NotNull(okObjectResult);

            var model = okObjectResult.Value as IEnumerable <MaterialDTO>;

            Assert.NotNull(model);
            Assert.Single(model);
        }
Exemplo n.º 4
0
        public void GetDealItemsOfMaterial_SelectedRandomMaterial_ShouldBelongToDealItem()
        {
            //init
            var materialsResult = materialController.GetMaterials(1, int.MaxValue).GetObject <PagedResult <Material> >().Queryable.ToArray();
            var materialsArb    = ControllerHelper.ChooseFrom(materialsResult).ToArbitrary();

            Prop.ForAll(materialsArb, (material) =>
            {
                //execution
                var result = sut.DealItemsOfMaterial(material.Id).GetObject <PagedResult <DealItemOfMaterialModel> >().Queryable.ToList();

                //assertion
                foreach (var r in result)
                {
                    Assert.AreEqual(r.MaterialId, material.Id);
                }
            }).QuickCheckThrowOnFailure();
        }