Esempio n. 1
0
        public void GetEnumerator_OnNullCurrentRowsProcessesRows()
        {
            IQueryable <GridModel>     models = new[] { new GridModel(), new GridModel() }.AsQueryable();
            IGridProcessor <GridModel> postProcessor = Substitute.For <IGridProcessor <GridModel> >();
            IGridProcessor <GridModel> preProcessor = Substitute.For <IGridProcessor <GridModel> >();
            IQueryable <GridModel>     postProcessedModels = new[] { new GridModel() }.AsQueryable();
            IQueryable <GridModel>     preProcessedModels = new[] { new GridModel() }.AsQueryable();

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

            postProcessor.Process(preProcessedModels).Returns(postProcessedModels);
            preProcessor.Process(models).Returns(preProcessedModels);
            grid.Processors.Add(postProcessor);
            grid.Processors.Add(preProcessor);

            GridRows <GridModel>   rows = new GridRows <GridModel>(grid);
            IEnumerable <IGridRow> currentRows = rows.CurrentRows;

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

            postProcessor.Received().Process(preProcessedModels);
            CollectionAssert.AreEqual(expected, actual);
            preProcessor.Received().Process(models);
            Assert.IsNull(currentRows);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public void GetEnumerator_AutomaticallyProcessesRows()
        {
            IQueryable <GridModel>     items = new[] { new GridModel(), new GridModel() }.AsQueryable();
            IGridProcessor <GridModel> postProcessor = Substitute.For <IGridProcessor <GridModel> >();
            IGridProcessor <GridModel> preProcessor = Substitute.For <IGridProcessor <GridModel> >();
            IQueryable <GridModel>     postProcessedItems = new[] { new GridModel() }.AsQueryable();
            IQueryable <GridModel>     preProcessedItems = new[] { new GridModel() }.AsQueryable();

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

            grid.Mode = GridProcessingMode.Automatic;

            postProcessor.Process(preProcessedItems).Returns(postProcessedItems);
            preProcessor.Process(items).Returns(preProcessedItems);
            grid.Processors.Add(postProcessor);
            grid.Processors.Add(preProcessor);

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

            Assert.Equal(expected, actual);
        }