Exemplo n.º 1
0
        public void ReadCommand()
        {
            var entityRepos  = new ImplicitReadCommandRepository();
            var genericRepos = NewRepos(entityRepos);

            var command = new ReadCommandInfo
            {
                Filters = new[] { new FilterCriteria {
                                      Property = "Name", Operation = "StartsWith", Value = "b"
                                  } },
                OrderByProperties = new[] { new OrderByProperty {
                                                Property = "Name"
                                            } },
                Top            = 3,
                Skip           = 3,
                ReadRecords    = true,
                ReadTotalCount = true,
            };

            Assert.AreEqual("a1, b1, b2 / 10", Dump(NewRepos(new ExplicitReadCommandRepository()).ExecuteReadCommand(command)));
            Assert.AreEqual(0, entityRepos.DropQueryCount());
            Assert.AreEqual("b4, b5 / 5", Dump(genericRepos.ExecuteReadCommand(command)));
            Assert.AreEqual(2, entityRepos.DropQueryCount()); // Paging should result with two queries: selecting items and count.

            command = new ReadCommandInfo {
                ReadRecords = true, ReadTotalCount = true
            };
            Assert.AreEqual("a1, b1, b2, b3, b4, b5 / 6", Dump(genericRepos.ExecuteReadCommand(command)));
            Assert.AreEqual(1, entityRepos.DropQueryCount()); // Without paging, there is no need for two queries.

            command = new ReadCommandInfo {
                Filters = new[] { new FilterCriteria("1") }, ReadRecords = true, ReadTotalCount = true
            };
            Assert.AreEqual("a1, b1 / 2", Dump(genericRepos.ExecuteReadCommand(command)));
            Assert.AreEqual(1, entityRepos.DropQueryCount()); // Without paging, there is no need for two queries.

            command = new ReadCommandInfo {
                Filters = new[] { new FilterCriteria("1"), new FilterCriteria {
                                      Property = "Name", Operation = "StartsWith", Value = "b"
                                  } }, ReadRecords = true, ReadTotalCount = true
            };
            Assert.AreEqual("b1 / 1", Dump(genericRepos.ExecuteReadCommand(command)));
            Assert.AreEqual(1, entityRepos.DropQueryCount()); // Without paging, there is no need for two queries.

            command = new ReadCommandInfo {
                Filters = new[] { new FilterCriteria("1"), new FilterCriteria {
                                      Filter = "System.String", Value = "b"
                                  } }, ReadRecords = true, ReadTotalCount = true
            };
            Assert.AreEqual("b1 / 1", Dump(genericRepos.ExecuteReadCommand(command)));
            Assert.AreEqual(1, entityRepos.DropQueryCount()); // Without paging, there is no need for two queries.

            command = new ReadCommandInfo {
                Filters = new[] { new FilterCriteria("b") }, Top = 2, Skip = 2, OrderByProperties = new[] { new OrderByProperty {
                                                                                                                Property = "Name"
                                                                                                            } }, ReadRecords = true, ReadTotalCount = true
            };
            Assert.AreEqual("b3, b4 / 5", Dump(genericRepos.ExecuteReadCommand(command)));
            Assert.AreEqual(1, entityRepos.DropQueryCount()); // Enumerable filter will cause GenericRepository to materialize of the query, so it will be executed only once even though the paging is used.
        }
Exemplo n.º 2
0
        public void ReadCommand_Null()
        {
            var entityRepos  = new ImplicitReadCommandRepository();
            var genericRepos = NewRepos(entityRepos);

            var command = new ReadCommandInfo
            {
                Filters = new[] { new FilterCriteria {
                                      Property = "Data", Operation = "Equal", Value = null
                                  } },
                OrderByProperties = new[] { new OrderByProperty {
                                                Property = "Name"
                                            } },
                Top            = 3,
                Skip           = 3,
                ReadRecords    = true,
                ReadTotalCount = true,
            };

            Assert.AreEqual("b3, b4, b5 / 6", Dump(genericRepos.ExecuteReadCommand(command)));
        }
Exemplo n.º 3
0
        public void ReadCommand_OutsideInterface()
        {
            var entityRepos  = new ImplicitReadCommandRepository();
            var genericRepos = NewRepos(entityRepos);

            var command = new ReadCommandInfo
            {
                Filters = new[] { new FilterCriteria {
                                      Property = "Name", Operation = "StartsWith", Value = "b"
                                  } },
                OrderByProperties = new[] { new OrderByProperty {
                                                Property = "Data"
                                            } },
                Top            = 3,
                Skip           = 3,
                ReadRecords    = true,
                ReadTotalCount = true,
            };

            Assert.AreEqual("b4, b5 / 5", Dump(genericRepos.ExecuteReadCommand(command)));

            command = new ReadCommandInfo
            {
                Filters = new[] { new FilterCriteria {
                                      Property = "Data", Operation = "Equal", Value = "xxx"
                                  } },
                OrderByProperties = new[] { new OrderByProperty {
                                                Property = "Name"
                                            } },
                Top            = 3,
                Skip           = 3,
                ReadRecords    = true,
                ReadTotalCount = true,
            };
            Assert.AreEqual(" / 0", Dump(genericRepos.ExecuteReadCommand(command)));
        }