Beispiel #1
0
        public void GetEnumerator_ProcessesRows()
        {
            IQueryable <GridModel>     items = new[] { new GridModel(), new GridModel() }.AsQueryable();
            IGridProcessor <GridModel> postProcessor = Substitute.For <IGridProcessor <GridModel> >();
            IGridProcessor <GridModel> preProcessor = Substitute.For <IGridProcessor <GridModel> >();
            IGridProcessor <GridModel> manProcessor = Substitute.For <IGridProcessor <GridModel> >();
            IQueryable <GridModel>     postProcessedItems = new[] { new GridModel() }.AsQueryable();
            IQueryable <GridModel>     preProcessedItems = new[] { new GridModel() }.AsQueryable();

            manProcessor.ProcessorType  = GridProcessorType.Manual;
            postProcessor.ProcessorType = GridProcessorType.Post;
            preProcessor.ProcessorType  = GridProcessorType.Pre;
            Grid <GridModel> grid = new Grid <GridModel>(items);

            postProcessor.Process(preProcessedItems).Returns(postProcessedItems);
            manProcessor.Process(items).Returns(new GridModel[0].AsQueryable());
            preProcessor.Process(items).Returns(preProcessedItems);
            grid.Processors.Add(postProcessor);
            grid.Processors.Add(preProcessor);
            grid.Processors.Add(manProcessor);

            IEnumerable <Object> actual = new GridRows <GridModel>(grid).ToList().Select(row => row.Model);
            IEnumerable <Object> expected = postProcessedItems;

            postProcessor.Received().Process(preProcessedItems);
            manProcessor.DidNotReceive().Process(items);
            preProcessor.Received().Process(items);

            Assert.Equal(expected, actual);
        }
Beispiel #2
0
        public void GetEnumerator_CachesRows()
        {
            IQueryable <GridModel>     items = new[] { new GridModel(), new GridModel() }.AsQueryable();
            IGridProcessor <GridModel> preProcessor = Substitute.For <IGridProcessor <GridModel> >();

            preProcessor.Process(items).Returns(Array.Empty <GridModel>().AsQueryable());
            preProcessor.ProcessorType = GridProcessorType.Pre;
            Grid <GridModel> grid = new Grid <GridModel>(items);

            GridRows <GridModel> rows = new GridRows <GridModel>(grid);

            rows.ToList();

            grid.Processors.Add(preProcessor);

            IEnumerable <Object> actual   = rows.ToList().Select(row => row.Model);
            IEnumerable <Object> expected = items;

            preProcessor.DidNotReceive().Process(Arg.Any <IQueryable <GridModel> >());
            Assert.Equal(expected, actual);
        }
Beispiel #3
0
        public void GetEnumerator_ReturnsCurrentRows()
        {
            IQueryable <GridModel>     models = new[] { new GridModel(), new GridModel() }.AsQueryable();
            IGridProcessor <GridModel> preProcessor = Substitute.For <IGridProcessor <GridModel> >();

            preProcessor.Process(models).Returns(new GridModel[0].AsQueryable());
            preProcessor.ProcessorType = GridProcessorType.Pre;
            Grid <GridModel> grid = new Grid <GridModel>(models);

            GridRows <GridModel> rows = new GridRows <GridModel>(grid);

            rows.ToList();

            grid.Processors.Add(preProcessor);

            IEnumerable <Object> actual   = rows.ToList().Select(row => row.Model);
            IEnumerable <Object> expected = models;

            preProcessor.DidNotReceive().Process(Arg.Any <IQueryable <GridModel> >());
            CollectionAssert.AreEqual(expected, actual);
        }