public async Task<JsonResult> GetCustomers(string query, bool validateOnly)
        {
            if (validateOnly)
            {
                var emptyQueryable = new EnumerableQuery<Customer>(new Customer[0]);
                try
                {
                    emptyQueryable.Where(query);
                    return Json(new { Valid = true });
                }
                catch (ParseException ex)
                {
                    return Json(new { Valid = false, ex.Message });
                }
            }

            var service = new CustomerDataService();
            var result = await service.GetAllCustomersAsync();
            IQueryable<Customer> queryableResult = result.AsQueryable();
            if (!string.IsNullOrWhiteSpace(query))
            {
                queryableResult = queryableResult.Where(query);
            }

            return Json(queryableResult.ToArray());
        }
Example #2
0
        public IQueryable<MetaEntry> Get()
        {
            var list = _serializer.Load<List<MetaEntry>>(@"query/metas.json");

            var result = new EnumerableQuery<MetaEntry>(list);

            return result;
        }
        public void GetClusterCoordinator_returns_the_expected_coordinator()
        {
            var coordinators = new EnumerableQuery<ClusterCoordinator>(new[]
                                                                       {
                                                                           new ClusterCoordinator {Id = _notCoordinatorId},
                                                                           new ClusterCoordinator {Id = _coordinatorId},
                                                                       });
            _dataService.Setup(x => x.ClusterCoordinators).Returns(coordinators);

            var clusterCoordinator = _clusterCoordinatorService.GetCoordinator(_coordinatorId);

            Assert.AreEqual(_coordinatorId, clusterCoordinator.Id);
        }
        public void ClusterCoordinatorGetAllCoordinatorsForDisplayReturnsExpectedData()
        {
            // Arrange
            var coordinators = new EnumerableQuery<ClusterCoordinator>(new[]
                                                                       {
                                                                           new ClusterCoordinator
                                                                           {
                                                                               Id = _coordinatorId,
                                                                               PersonId = _person1.Id,
                                                                               ClusterId = _cluster1.Id,
                                                                               DisasterId = _disaster1.Id,
                                                                               Person = _person1,
                                                                               Cluster = _cluster1,
                                                                               Disaster = _disaster1
                                                                           },
                                                                           new ClusterCoordinator
                                                                           {
                                                                               Id = _notCoordinatorId,
                                                                               PersonId = _person2.Id,
                                                                               ClusterId = _cluster2.Id,
                                                                               DisasterId = _disaster1.Id,
                                                                               Person = _person2,
                                                                               Cluster = _cluster2,
                                                                               Disaster = _disaster1
                                                                           }
                                                                       });
            _dataService.Setup(x => x.ClusterCoordinators).Returns(coordinators);
            IList<Person> allPersonsForDisplay;

            // Act
            var clusterCoordinators = _clusterCoordinatorService.GetAllCoordinatorsForDisplay(_disaster1.Id,
                out allPersonsForDisplay).ToList();

            // Assert
            Assert.IsNotNull(clusterCoordinators);
            Assert.IsNotNull(allPersonsForDisplay);
            Assert.AreEqual(2, clusterCoordinators.Count());
            Assert.AreEqual(2, allPersonsForDisplay.Count());
            const string errorMsg = "Could not find the coordinator with the ID of ";
            var firstCoordinator = clusterCoordinators.FirstOrDefault(cc => cc.Id == _coordinatorId);
            Assert.IsNotNull(firstCoordinator, errorMsg + _coordinatorId);
            var secondCoordinator = clusterCoordinators.FirstOrDefault(cc => cc.Id == _notCoordinatorId);
            Assert.IsNotNull(secondCoordinator, errorMsg + _notCoordinatorId);
            Assert.AreEqual(_person1.Id, firstCoordinator.PersonId);
            Assert.AreEqual(_person2.Id, secondCoordinator.PersonId);
            const string personErrorMsg = "Could not find person with the ID of ";
            var firstPerson = allPersonsForDisplay.FirstOrDefault(x => x.Id == _person1.Id);
            Assert.IsNotNull(firstPerson, personErrorMsg + _person1.Id);
            var secondPerson = allPersonsForDisplay.FirstOrDefault(x => x.Id == _person2.Id);
            Assert.IsNotNull(secondPerson, personErrorMsg + _person2.Id);
        }
        IQueryable IQueryProvider.CreateQuery(System.Linq.Expressions.Expression expression)
        {
            if (expression == null)
            {
                throw System.Linq.Error.ArgumentNull("expression");
            }
            Type type = TypeHelper.FindGenericType(typeof(IQueryable <>), expression.Type);

            if (type == null)
            {
                throw System.Linq.Error.ArgumentNotValid("expression");
            }
            return(EnumerableQuery.Create(type.GetGenericArguments()[0], expression));
        }
        public void GetClusterCoordinators_return_only_the_ClusterCoordinators_for_the_specified_disaster()
        {
            var coordinators = new EnumerableQuery<ClusterCoordinator>(new[]
                                                                       {
                                                                           new ClusterCoordinator {DisasterId = _disasterId},
                                                                           new ClusterCoordinator {DisasterId = _disasterId},
                                                                           new ClusterCoordinator {DisasterId = _notDisasterId},
                                                                           new ClusterCoordinator {DisasterId = _notDisasterId},
                                                                       });
            _dataService.Setup(x => x.ClusterCoordinators).Returns(coordinators);

            var clusterCoordinators = _clusterCoordinatorService.GetAllCoordinators(_disasterId);

            Assert.IsTrue(clusterCoordinators.All(cc => cc.DisasterId == _disasterId));
        }
        internal override Expression VisitConstant(ConstantExpression c)
        {
            EnumerableQuery query = c.Value as EnumerableQuery;

            if (query == null)
            {
                return(c);
            }
            if (query.Enumerable != null)
            {
                Type publicType = GetPublicType(query.Enumerable.GetType());
                return(Expression.Constant(query.Enumerable, publicType));
            }
            return(this.Visit(query.Expression));
        }
Example #8
0
        internal override Expression VisitConstant(ConstantExpression c)
        {
            EnumerableQuery sq = c.Value as EnumerableQuery;

            if (sq != null)
            {
                if (sq.Enumerable != null)
                {
                    Type t = GetPublicType(sq.Enumerable.GetType());
                    return(Expression.Constant(sq.Enumerable, t));
                }
                return(this.Visit(sq.Expression));
            }
            return(c);
        }
        protected internal override Expression VisitConstant(ConstantExpression c)
        {
            EnumerableQuery sq = c.Value as EnumerableQuery;

            if (sq != null)
            {
                if (sq.Enumerable != null)
                {
                    Type t = GetPublicType(sq.Enumerable.GetType());
                    return(Expression.Constant(sq.Enumerable, t));
                }
                Expression exp = sq.Expression;
                if (exp != c)
                {
                    return(Visit(exp));
                }
            }
            return(c);
        }
Example #10
0
        public void Can_get_selected_category()
        {
            Mock<IProductRepository> productRepositoryStub = new Mock<IProductRepository>();

            IQueryable<Product> testProducts = new EnumerableQuery<Product>(
                new List<Product>
                {
                    new Product {ProductId = 1, Name = "P1", Category = "Golf"},
                    new Product {ProductId = 2, Name = "P2", Category = "Swimming"},
                });

            productRepositoryStub.Setup(repo => repo.Products)
                .Returns(testProducts);

            var controller = new NavController(productRepositoryStub.Object);

            string categoryToSelect = "Swimming";

            PartialViewResult view = controller.Menu(categoryToSelect);

            string selectedCagegory = view.ViewBag.SelectedCategory;

            selectedCagegory.ShouldBe(categoryToSelect);
        }
Example #11
0
        /// <summary>
        /// Возвращает только близких родственников человека: Папа, мама, сестра, брат
        /// </summary>
        public static Dictionary<Person, KindOfRelative> GetImmediateRelatives(int id)
        {
            var relatives = new Dictionary<Person, KindOfRelative>();
            using (var db = new PersonContext())
            {

                IQueryable<Relative> personRelatives;
                try
                {
                    personRelatives = db.Relatives.Where(r => r.PersonId == id);
                }
                catch (Exception)
                {
                    personRelatives = new EnumerableQuery<Relative>(new List<Relative>());
                }
                foreach (var relative in personRelatives)
                {
                    var myRelative = db.Persons.FirstOrDefault(p => p.Id == relative.RelativeOfPersonId);
                    if (myRelative != null)
                    {
                        relatives.Add(myRelative, ConvertTo.KindOfRelative(relative.KindOfRelative));
                    }
                }
            }
            return relatives;
        }
        public ActionResult glassSearchSubstring(GlassSearchModel[] glassTitle)
        {
            IQueryable<GlassSearchModel> moviePack = new EnumerableQuery<GlassSearchModel>(movieRepo.getGlassMovieBySubstring(glassTitle[0].title));

            return Json(moviePack);
        }
        public void GetCoordinatorForUnassignReturnsExpectedData()
        {
            var coordinators = new EnumerableQuery<ClusterCoordinator>(new[]
                                                                       {
                                                                           new ClusterCoordinator
                                                                           {
                                                                               Id = _coordinatorId,
                                                                               PersonId = _person1.Id,
                                                                               ClusterId = _cluster1.Id,
                                                                               DisasterId = _disaster1.Id,
                                                                               Person = _person1,
                                                                               Cluster = _cluster1,
                                                                               Disaster = _disaster1
                                                                           },
                                                                           new ClusterCoordinator
                                                                           {
                                                                               Id = _notCoordinatorId,
                                                                               PersonId = _person2.Id,
                                                                               ClusterId = _cluster2.Id,
                                                                               DisasterId = _disaster1.Id,
                                                                               Person = _person2,
                                                                               Cluster = _cluster2,
                                                                               Disaster = _disaster1
                                                                           }
                                                                       });
            _dataService.Setup(x => x.ClusterCoordinators).Returns(coordinators);

            var coordinator = _clusterCoordinatorService.GetCoordinatorFullyLoaded(_coordinatorId);

            Assert.IsNotNull(coordinator);
            Assert.AreEqual(_coordinatorId, coordinator.Id);
            Assert.AreEqual(_person1.Id, coordinator.PersonId);
            Assert.AreEqual(_cluster1.Id, coordinator.ClusterId);
            Assert.AreEqual(_disaster1.Id, coordinator.DisasterId);
            Assert.IsNotNull(coordinator.Person);
            Assert.IsNotNull(coordinator.Disaster);
            Assert.IsNotNull(coordinator.Cluster);
            Assert.AreEqual(_person1.FullName, coordinator.Person.FullName);
            Assert.AreEqual(_cluster1.Name, coordinator.Cluster.Name);
            Assert.AreEqual(_disaster1.Name, coordinator.Disaster.Name);
        }
        public void GetAllCoordinatorsForClusterTest()
        {
            // Arrange
            var coordinators = new EnumerableQuery<ClusterCoordinator>(new[]
                                                                       {
                                                                           new ClusterCoordinator
                                                                           {
                                                                               Id = _coordinatorId,
                                                                               PersonId = _person1.Id,
                                                                               ClusterId = _cluster1.Id,
                                                                               DisasterId = _disaster1.Id,
                                                                               Person = _person1,
                                                                               Cluster = _cluster1,
                                                                               Disaster = _disaster1
                                                                           },
                                                                           new ClusterCoordinator
                                                                           {
                                                                               Id = _notCoordinatorId,
                                                                               PersonId = _person2.Id,
                                                                               ClusterId = _cluster2.Id,
                                                                               DisasterId = _disaster1.Id,
                                                                               Person = _person2,
                                                                               Cluster = _cluster2,
                                                                               Disaster = _disaster1
                                                                           }
                                                                       });
            _dataService.Setup(x => x.ClusterCoordinators).Returns(coordinators);

            // Act
            var clusterCoordinators = _clusterCoordinatorService.GetAllCoordinatorsForCluster(2).ToList();

            // Assert
            Assert.IsNotNull(clusterCoordinators);
            Assert.AreEqual(1, clusterCoordinators.Count());
            const string ErrorMsg = "Could not find the coordinator with the ID of ";
            var firstCoordinator = clusterCoordinators.FirstOrDefault(cc => cc.Id == _coordinatorId);
            Assert.IsNotNull(firstCoordinator, ErrorMsg + _coordinatorId);
            Assert.AreEqual(_person1.Id, firstCoordinator.PersonId);
        }
        public DesignMoneyDataSource()
        {
            List<TransactionType> transactionTypes = new List<TransactionType>
                                                         {
                                                             new TransactionType
                                                                 {
                                                                     Name = "For transport",
                                                                     CreatedAt = DateTime.Now
                                                                 },
                                                              new TransactionType
                                                                  {
                                                                      Name = "For food",
                                                                      CreatedAt = DateTime.Now
                                                                  }
                                                         };

            List<BurndownType> burndownTypes = new List<BurndownType>
                {
                    new BurndownType
                        {
                            Id = 1,
                            Name = "USD",
                            CreatedAt = DateTime.Now
                        },
                    new BurndownType
                        {
                            Id = 2,
                            Name = "EUR",
                            CreatedAt = DateTime.Now
                        }
                };

            List<Burndown> burndowns = new List<Burndown>
                {
                    new Burndown
                        {
                            Id = 1,
                            StartDate = DateTime.Today,
                            EndDate = DateTime.Today.AddMonths(1),
                            MoneyOnStart = 1000,
                            Name = "My money",
                            BurndownType = burndownTypes.First()
                        },
                    new Burndown
                        {
                            Id = 2,
                            StartDate = DateTime.Today,
                            EndDate = DateTime.Today.AddMonths(1),
                            MoneyOnStart = 1000,
                            Name = "My money 2",
                            BurndownType = burndownTypes.Last()
                        }
                };

            List<Transaction> transactions = new List<Transaction>
                {
                    new Transaction
                        {
                            Id = 1,
                            Amount = 100,
                            Burndown = burndowns.First(),
                            CreatedAt = DateTime.Now.AddDays(1),
                            TransactionType =  transactionTypes.First()
                        },
                    new Transaction
                        {
                            Id = 2,
                            Amount = 100,
                            Burndown = burndowns.First(),
                            CreatedAt = DateTime.Now.AddDays(15),
                            TransactionType = transactionTypes.Last()
                        },
                };

            Burndowns = new EnumerableQuery<Burndown>(burndowns);
            BurndownTypes = new EnumerableQuery<BurndownType>(burndownTypes);
            Transactions = new EnumerableQuery<Transaction>(transactions);
            TransactionTypes = new EnumerableQuery<TransactionType>(transactionTypes);
        }
Example #16
0
        public void WhereWithNullableDateTime()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            var queryable = new EnumerableQuery<EntityWithFields>(new List<EntityWithFields>());
            var value = new DateTime(1980, 1, 1);
            Expression<Func<IQueryable<EntityWithFields>>> query = () => queryable.Where(p => p.NullableDateTime < value);
            var translation = new TranslationResult();

            // Act
            translator.Translate((MethodCallExpression)query.Body, translation);

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.Equal("NullableDateTime lt datetime'1980-01-01T00:00:00'", translation.TableQuery.FilterString);
        }
        private void FillGridView()
        {
            var data = _dbProductRepository.GetAll();

            if (!data.Any())
                data =
                    new EnumerableQuery<Product>(new[] {new Product {Id = -1, Name = "0", Category = "0", Price = 0}});

            _gridViewProductManagementManager.Fill(gvTable, data);
        }
Example #18
0
        public void WhereWithNullableDouble()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            var queryable = new EnumerableQuery<EntityWithFields>(new List<EntityWithFields>());
            const double value = .3;
            Expression<Func<IQueryable<EntityWithFields>>> query = () => queryable.Where(p => p.NullableDouble > value);
            var translation = new TranslationResult();

            // Act
            translator.Translate((MethodCallExpression)query.Body, translation);

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.Equal("NullableDouble gt .3", translation.TableQuery.FilterString);
        }
Example #19
0
        public void WhereWithEnumartionConstantValue()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            var queryable = new EnumerableQuery<EntityWithFields>(new List<EntityWithFields>());

            const Countries value = Countries.Germany;

            Expression<Func<IQueryable<EntityWithFields>>> query = () => queryable.Where(p => p.String == value.ToString());
            var translation = new TranslationResult();

            // Act
            translator.Translate((MethodCallExpression)query.Body, translation);

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.Equal(string.Format("String eq '{0}'", value), translation.TableQuery.FilterString);
        }