public void TestStartsWithFilter() { StartsWithFilter v1 = new StartsWithFilter(ConnectorAttributeBuilder.Build("foo", "bar")); StartsWithFilter v2 = (StartsWithFilter)CloneObject(v1); Assert.AreEqual(v1.GetAttribute(), v2.GetAttribute()); }
/// <summary> /// /// </summary> /// <param name="p"></param> /// <param name="filter"></param> /// <returns></returns> public string VisitStartsWithFilter(Hashtable p, StartsWithFilter filter) { var name = filter.GetName(); var name2 = name as String; if (p.ContainsKey(name)) { name2 = p[name] as String; } return(string.Format("{0} -like \"{1}{2}\"", name2, filter.GetValue(), "*")); }
public void ReturnFalseIfStringDoesNotStartWithValue() { var e = new SystemEvent { Message = " Start of Message" }; var extendedProperties = new FakeExtendedProperties { { "property", "Message" }, { "value", "Start" } }; var filter = new StartsWithFilter(extendedProperties, Enumerable.Empty <ICreateFilterExpressions>()); Assert.False(Filter.Compile(filter).Invoke(e)); }
public void AlwaysCaseInsensitive() { var e = new SystemEvent { Message = "START of Message" }; var extendedProperties = new FakeExtendedProperties { { "property", "Message" }, { "value", "Start" } }; var filter = new StartsWithFilter(extendedProperties, Enumerable.Empty <ICreateFilterExpressions>()); Assert.True(Filter.Compile(filter).Invoke(e)); }
public void CanHaveNullValue() { var e = new SystemEvent { Message = "Start of Message" }; var extendedProperties = new FakeExtendedProperties { { "property", "Message" }, { "value", null } }; var filter = new StartsWithFilter(extendedProperties, Enumerable.Empty <ICreateFilterExpressions>()); Assert.True(Filter.Compile(filter).Invoke(e)); }
private IFilter CreateFilter(OperatorType operators, string propertyName, string propertyValue) { IFilter filter = null; switch (operators) { case OperatorType.eq: filter = new EqualToFilter(propertyName, propertyValue); break; case OperatorType.ne: filter = new NotEqualToFilter(propertyName, propertyValue); break; case OperatorType.startswith: filter = new StartsWithFilter(propertyName, propertyValue); break; case OperatorType.endswith: filter = new EndsWithFilter(propertyName, propertyValue); break; case OperatorType.substringof: filter = new SubstringFilter(propertyName, propertyValue); break; /* currently not supported * case OperatorType.lt: * filter = new LessThanFilter(propertyName, propertyValue); * break; * case OperatorType.le: * filter = new LessThanOrEqualFilter(propertyName, propertyValue); * break; * case OperatorType.gt: * filter = new GreaterThanFilter(propertyName, propertyValue); * break; * case OperatorType.ge: * filter = new GreaterThanOrEqualFilter(propertyName, propertyValue); * break; */ } return(filter); }
public static IEnumerable <Models.Item> GetShareFileItems(ShareFileDriveInfo driveInfo, string path, string[] select = null, string[] expand = null) { Client.Requests.IQuery <Models.ODataFeed <Models.Item> > query = null; if (!string.IsNullOrEmpty(path)) { // this regex matches all supported powershell path syntaxes: // drive-qualified - users:/username // provider-qualified - membership::users:/username // provider-internal - users:/username var match = Regex.Match(path, @"(?:membership::)?(?:\w+:[\\/])?(?<path>.+)$", RegexOptions.IgnoreCase); if (match.Success) { string sfPath = match.Groups["path"].Value; sfPath = sfPath.Replace('\\', '/'); if (!sfPath.StartsWith("/")) { sfPath = "/" + sfPath; } if (sfPath.IndexOf('*') > 0) { var starIndex = sfPath.LastIndexOf('*'); var parentIdx = sfPath.LastIndexOf('/'); if (parentIdx >= 0) { var sfPathParent = parentIdx > 0 ? sfPath.Substring(0, parentIdx) : "/"; var sfPathFile = sfPath.Substring(parentIdx + 1, starIndex - parentIdx - 1); var sfItem = (driveInfo.RootUri != null ? driveInfo.Client.Items.ByPath(driveInfo.RootUri, sfPathParent) : driveInfo.Client.Items.ByPath(sfPathParent)).Select("Id").Execute(); var filter = new StartsWithFilter("Name", sfPathFile, true); query = driveInfo.Client.Items.GetChildren(sfItem.url).Filter(filter); } } } } if (query != null) { var feed = ExecuteQuery <Models.ODataFeed <Models.Item> >(query, select, expand); return(feed.Feed); } else { return(null); } }
protected override String CreateStartsWithExpression(StartsWithFilter filter, Boolean not) { String[] attrNames = GetLdapNamesForAttribute(filter.GetAttribute()); if (attrNames == null) { return(null); } StringBuilder builder = new StringBuilder(); if (not) { builder.Append("(!"); } if (attrNames.Length == 1) { builder.Append('('); builder.Append(attrNames[0]); builder.Append('='); GetLdapFilterValue(builder, attrNames[0], filter.GetValue()); builder.Append("*)"); } else { builder.Append("(|"); foreach (String attrName in attrNames) { builder.Append('('); builder.Append(attrName); builder.Append('='); GetLdapFilterValue(builder, attrName, filter.GetValue()); builder.Append("*)"); } builder.Append(')'); } if (not) { builder.Append(')'); } return(builder.ToString()); }
public void EnsureImplicitAndFilter() { // Arrange var client = this.GetShareFileClient(true); var query = client.Items.GetChildren(client.Items.GetAlias("fileId")); // Act var endsWithFilter = new EndsWithFilter("Property", "value"); var startsWithFilter = new StartsWithFilter("Property", "value"); query = query.Filter(endsWithFilter).Filter(startsWithFilter); var odataQuery = query as Query <ODataFeed <Item> >; var filter = odataQuery.GetFilter(); // Assert filter.Should().BeOfType <AndFilter>(); (filter as AndFilter).Left.Should().Be(endsWithFilter); (filter as AndFilter).Right.Should().Be(startsWithFilter); }
protected override Filter CreateStartsWithExpression(StartsWithFilter filter, bool not) { return(not ? FilterBuilder.Not(filter) : filter); }
public void StartsWithFilter(bool isEqual) { var filter = new StartsWithFilter("Name", "ShareFile", isEqual); filter.ToString().Should().Be("startswith(Name, 'ShareFile') eq " + isEqual.ToLowerString()); }
public Dictionary <string, object> VisitStartsWithFilter(Hashtable p, StartsWithFilter filter) { return(CreateMap("STARTSWITH", filter.GetName(), filter.GetValue())); }
public void NotCompositeExpression() { var filter = new StartsWithFilter(new FakeExtendedProperties(), Enumerable.Empty <ICreateFilterExpressions>()); Assert.False(filter.CompositeExpression); }
protected override String CreateStartsWithExpression(StartsWithFilter filter, bool not) { String rv = "( STARTS-WITH " + filter.GetName() + " " + filter.GetValue() + " )"; return(Not(rv, not)); }
protected override IDictionary <String, Object> CreateStartsWithExpression(StartsWithFilter filter, Boolean not) { return(CreateFilter("STARTSWITH", filter, not)); }
public string VisitStartsWithFilter(Hashtable p, StartsWithFilter filter) { throw new NotImplementedException(); }