public List <Product> Filter(List <Product> productsToFilter) { MakeFilters(); Expression <Func <Product, bool> > Expression = Products => ((_orPredicates.Count() > 0 ? _orPredicates.Any(productsToFilter => productsToFilter(Products)) : true) && (_andPredicates.Count() > 0 ? _andPredicates.All(productsToFilter => productsToFilter(Products)) : true)); EnumerableQuery <Product> ProductsToFilterEnum = new EnumerableQuery <Product>(productsToFilter); var result = (from p in ProductsToFilterEnum.Where(Expression) select p).ToList(); return(result); }
public IEnumerable <Band> Search(BandSearchInformation bandSearchInformation, out int totalMatches) { using (var context = new MusicArchiveContext()) { IQueryable <Band> matches = new EnumerableQuery <Band>(context.Bands); if (!string.IsNullOrWhiteSpace(bandSearchInformation.BandName)) { matches = matches.Where(b => b.Name.Contains(bandSearchInformation.BandName)); } if (!string.IsNullOrWhiteSpace(bandSearchInformation.CountryOfOrigin)) { matches = matches.Where(band1 => band1.CountryOfOrgin == bandSearchInformation.CountryOfOrigin); } if (!string.IsNullOrWhiteSpace(bandSearchInformation.Genre)) { matches = matches.Where(band1 => band1.Genre == bandSearchInformation.Genre); } if (!string.IsNullOrWhiteSpace(bandSearchInformation.Label)) { //matches = matches.Where(band1 => band1.CurrentLabel == bandSearchInformation.Label); } if (!string.IsNullOrWhiteSpace(bandSearchInformation.YearOfFormation)) { matches = matches.Where(band1 => band1.FormedIn == bandSearchInformation.YearOfFormation); //TODO make this an actual date... } if (!string.IsNullOrWhiteSpace(bandSearchInformation.LyricalThemes)) { matches = matches.Where(band1 => band1.LyricalThemes == bandSearchInformation.LyricalThemes); } totalMatches = matches.Count(); return(matches.OrderBy(band => band.Name).Skip(bandSearchInformation.StartingRecordNumber).Take(bandSearchInformation.PageSize).ToList()); } }
public void IndexUrlNameTest(bool inContentAuthoringSite, string urlName) { //Setup the fakes and dummies var repositoryFake = A.Fake <IJobProfileCategoryRepository>(ops => ops.Strict()); var loggerFake = A.Fake <IApplicationLogger>(); var webAppContextFake = A.Fake <IWebAppContext>(ops => ops.Strict()); var dummyjobProfileCategories = new EnumerableQuery <JobProfileCategory>(new List <JobProfileCategory> { new JobProfileCategory { Description = nameof(JobProfileCategory.Description), Title = nameof(JobProfileCategory.Title), Url = nameof(JobProfileCategory.Url), Name = nameof(JobProfileCategory.Name) }, new JobProfileCategory { Description = nameof(JobProfileCategory.Description), Title = nameof(JobProfileCategory.Title), Url = urlName, Name = nameof(JobProfileCategory.Name) } }); var filterJpCategories = dummyjobProfileCategories.Where( jpCat => !jpCat.Url.Equals(urlName, StringComparison.InvariantCultureIgnoreCase)); // Set up calls A.CallTo(() => repositoryFake.GetJobProfileCategories()) .Returns(dummyjobProfileCategories); A.CallTo(() => webAppContextFake.IsContentAuthoringSite).Returns(inContentAuthoringSite); //Instantiate & Act var jobprofileController = new JobProfileCategoriesController(repositoryFake, webAppContextFake, loggerFake); //Act var indexUrlNameMethodCall = jobprofileController.WithCallTo(c => c.Index(urlName)); //Assert indexUrlNameMethodCall .ShouldRenderView("RelatedJobCategories") .WithModel <RelatedJobProfileCategoriesViewModel>(vm => { vm.IsContentAuthoring.Should().Be(webAppContextFake.IsContentAuthoringSite); vm.JobProfileCategories.Should().BeEquivalentTo(filterJpCategories); }) .AndNoModelErrors(); A.CallTo(() => repositoryFake.GetJobProfileCategories()).MustHaveHappened(); }
/// -- Region Parameters /// DECLARE @p0 NVarChar(1000) = 'M%' /// DECLARE @p1 NVarChar(1000) = '%1' /// -- EndRegion /// SELECT [t0].[Id], [t0].[Name] /// FROM [TestsTable] AS [t0] /// WHERE ([t0].[Name] LIKE @p0) AND ([t0].[Name] LIKE @p1) public void StartWith_And_EndWith() { // Arrange var source = new EnumerableQuery <Services>(new List <Services> { new Services { Name = "My Service 1" } }); // Act var result = source.Where(x => x.Name.StartsWith("M") && x.Name.EndsWith("1")); // Assert result.Should().BeEmpty(); }
public void WhereWithOverloadedToString() { // Arrange var translator = new WhereTranslator(_nameChanges); var queryable = new EnumerableQuery <EntityWithFields>(new List <EntityWithFields>()); var value = new EntityWithToString("My value"); 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); }
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); }
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 IOrderRepository PrepareTestOrderRepository() { var merchandises = new EnumerableQuery <Merchandise>(new List <Merchandise> { new Merchandise { ID = 1255, SubgroupID = 30, ImageName = "1255.jpg", Title = "Шпингалет автомат 100 мм латунь", Pack = 20, UnitMeasure = "шт", CostWhs1 = 30, CostWhs2 = 25, CostWhs3 = 20 }, new Merchandise { ID = 1257, SubgroupID = 30, ImageName = "1257.jpg", Title = "Шпингалет полукруглый 60 см хром", Pack = 60, UnitMeasure = "шт", CostWhs1 = 26, CostWhs2 = 22, CostWhs3 = 19 }, new Merchandise { ID = 1577, SubgroupID = 30, ImageName = "1577.jpg", Title = "Шпингалет полукруглый 100 см латунь", Pack = 40, UnitMeasure = "шт", CostWhs1 = 30, CostWhs2 = 24, CostWhs3 = 20 }, new Merchandise { ID = 1530, SubgroupID = 5, ImageName = "1530.jpg", Title = "Хомут (12-20 мм) нерж ЗЕТ", Pack = 100, UnitMeasure = "шт", CostWhs1 = 9, CostWhs2 = 7.5, CostWhs3 = 6 }, new Merchandise { ID = 1776, SubgroupID = 28, ImageName = "1776.jpg", Title = "Петля ПН-5 60 мм бел. цинк Н", Pack = 200, UnitMeasure = "шт", CostWhs1 = 10, CostWhs2 = 8.3, CostWhs3 = 6.1 }, }); var orderDetails = new EnumerableQuery <OrderDetail>(new List <OrderDetail> { new OrderDetail { ID = 1, OrderID = 1, GoodsID = 1255, Quantity = 1090, Comment = "Нужен только белый цвет" }, new OrderDetail { ID = 2, OrderID = 1, GoodsID = 1577, Quantity = 23, Comment = "Шпингалеты только без брака!!!" }, new OrderDetail { ID = 3, OrderID = 1, GoodsID = 1530, Quantity = 57, Comment = "пластиковые" }, new OrderDetail { ID = 4, OrderID = 1, GoodsID = 1776, Quantity = 100, Comment = "" }, new OrderDetail { ID = 5, OrderID = 3, GoodsID = 1255, Quantity = 10000, Comment = "" }, new OrderDetail { ID = 6, OrderID = 5, GoodsID = 1257, Quantity = 10, Comment = "" } }); var orders = new EnumerableQuery <Order>(new List <Order> { new Order { ID = 1, CustomerID = "9F8B3A4C-A2ED-4CD1-BD83-3739BCFBA5AA", Completed = false, Created = DateTime.Now, Details = orderDetails.Where(od => od.OrderID == 1).ToArray() }, new Order { ID = 3, CustomerID = "9F8B3A4C-A2ED-4CD1-BD83-3739BCFBA5AA", Completed = false, Created = DateTime.Now }, new Order { ID = 4, CustomerID = "9F8B3A4C-A2ED-4CD1-BD83-3739BCFBA5AA", Completed = true, Created = DateTime.Now }, new Order { ID = 2, CustomerID = "70FCF05A-ACC2-4CEB-A5D0-C19B40D6533E", Completed = true, Created = DateTime.Now, Details = orderDetails.Where(od => od.OrderID == 1).ToArray() }, new Order { ID = 5, CustomerID = "70FCF05A-ACC2-4CEB-A5D0-C19B40D6533E", Completed = false, Created = DateTime.Now } }); var customers = new EnumerableQuery <Customer>(new List <Customer>() { new Customer { ID = "9F8B3A4C-A2ED-4CD1-BD83-3739BCFBA5AA", Address = "г. Москва, Новокуркинское шоссе, 35-1", Company = "ЗАО Хозком", ContactName = "Сергей", EmailAddress = "*****@*****.**", PhoneNumber = "+79045634899", INN = "", Orders = orders.Where(o => o.CustomerID.Equals("9F8B3A4C-A2ED-4CD1-BD83-3739BCFBA5AA")).ToArray() }, new Customer { ID = "70FCF05A-ACC2-4CEB-A5D0-C19B40D6533E", Address = "г. Москва, Пятницкая улица, 11/2", Company = "ОАО Луна", ContactName = "Георгий", EmailAddress = "*****@*****.**", PhoneNumber = "+79155634190", INN = "", Orders = orders.Where(o => o.CustomerID.Equals("70FCF05A-ACC2-4CEB-A5D0-C19B40D6533E")).ToArray() }, new Customer { ID = "07E4E230-7F80-482D-9B1A-CB37C078A025", Address = "г. Москва, Новокузнецкая улица, 1/2", Company = "ОАО Мапс", ContactName = "Гоша", EmailAddress = "*****@*****.**", PhoneNumber = "+79055434109", INN = "" }, }); var mockSetDiscounts = Substitute.For <IDbSet <Discount> >().Initialise(discounts); var mockSetCustomers = Substitute.For <IDbSet <Customer> >().Initialise(customers); var mockSetOrders = Substitute.For <IDbSet <Order> >().Initialise(orders); var mockSetOrderDetails = Substitute.For <IDbSet <OrderDetail> >().Initialise(orderDetails); var mockSetMerchandises = Substitute.For <IDbSet <Merchandise> >().Initialise(merchandises); var mockDbContext = Substitute.For <IDbGeneralContext>(); mockDbContext.Discounts.Returns(mockSetDiscounts); mockDbContext.Customers.Returns(mockSetCustomers); mockDbContext.Orders.Returns(mockSetOrders); mockDbContext.OrderDetails.Returns(mockSetOrderDetails); mockDbContext.Merchandises.Returns(mockSetMerchandises); return (new OrderRepository() { Db = mockDbContext, OrderCostCalculation = new OrderCostCalculation() { Db = mockDbContext } }); }
private ICatalogRepository PrepareTestCatalogRepository() { var merchandises = new EnumerableQuery <Merchandise>(new List <Merchandise> { new Merchandise { ID = 1255, SubgroupID = 30, ImageName = "1255.jpg", Title = "Шпингалет автомат 100 мм латунь", Pack = 20, UnitMeasure = "шт", CostWhs1 = 30, CostWhs2 = 25, CostWhs3 = 20 }, new Merchandise { ID = 1257, SubgroupID = 30, ImageName = "1257.jpg", Title = "Шпингалет полукруглый 60 см хром", Pack = 60, UnitMeasure = "шт", CostWhs1 = 26, CostWhs2 = 22, CostWhs3 = 19 }, new Merchandise { ID = 1577, SubgroupID = 30, ImageName = "1577.jpg", Title = "Шпингалет полукруглый 100 см латунь", Pack = 40, UnitMeasure = "шт", CostWhs1 = 30, CostWhs2 = 24, CostWhs3 = 20 }, new Merchandise { ID = 1530, SubgroupID = 5, ImageName = "1530.jpg", Title = "Хомут (12-20 мм) нерж ЗЕТ", Pack = 100, UnitMeasure = "шт", CostWhs1 = 9, CostWhs2 = 7.5, CostWhs3 = 6 }, new Merchandise { ID = 1776, SubgroupID = 28, ImageName = "1776.jpg", Title = "Петля ПН-5 60 мм бел. цинк Н", Pack = 200, UnitMeasure = "шт", CostWhs1 = 10, CostWhs2 = 8.3, CostWhs3 = 6.1 }, }); var subgroups = new EnumerableQuery <Subgroup>(new List <Subgroup> { new Subgroup { ID = 5, GroupID = 5, Title = "(все хомуты)", Merchandises = merchandises.Where(m => m.SubgroupID == 5).ToArray() }, new Subgroup { ID = 28, GroupID = 6, Title = "Петли накладные", Merchandises = merchandises.Where(m => m.SubgroupID == 28).ToArray() }, new Subgroup { ID = 30, GroupID = 6, Title = "Шпингалеты", Merchandises = merchandises.Where(m => m.SubgroupID == 30).ToArray() }, new Subgroup { ID = 37, GroupID = 6, Title = "Упоры Дверные", Merchandises = merchandises.Where(m => m.SubgroupID == 37).ToArray() }, new Subgroup { ID = 7, GroupID = 22, Title = "(все хозтовары)", Merchandises = merchandises.Where(m => m.SubgroupID == 7).ToArray() } }); var groups = new EnumerableQuery <Group>(new List <Group> { new Group { ID = 5, Title = "Хомуты", Subgroups = subgroups.Where(s => s.GroupID == 5).ToArray() }, new Group { ID = 6, Title = "Фурнитура", Subgroups = subgroups.Where(s => s.GroupID == 6).ToArray() }, new Group { ID = 22, Title = "Хозтовары", Subgroups = subgroups.Where(s => s.GroupID == 22).ToArray() } }); var mockSetGroups = Substitute.For <IDbSet <Group> >().Initialise(groups); var mockSetSubgroups = Substitute.For <IDbSet <Subgroup> >().Initialise(subgroups); var mockSetMerchandises = Substitute.For <IDbSet <Merchandise> >().Initialise(merchandises); var mockDbContext = Substitute.For <IDbGeneralContext>(); mockDbContext.Groups.Returns(mockSetGroups); mockDbContext.Subgroups.Returns(mockSetSubgroups); mockDbContext.Merchandises.Returns(mockSetMerchandises); return(new CatalogRepository() { Db = mockDbContext }); }