コード例 #1
0
ファイル: SmartViewTest.cs プロジェクト: yaneshtyagi/2day
        public void Rules_2_block_2_or_and()
        {
            var handler = SmartViewHandler.FromString("(Priority Is Star OR Title BeginsWith e) AND (Note EndsWith a)");

            handler.AssertContent(2, SmartViewMatchType.All);

            handler.AssertRule<SmartViewPriorityRule>(
                0, 0, 2,
                SmartViewMatchType.Any,
                SmartViewField.Priority,
                SmartViewFilter.Is,
                r => r.Value == TaskPriority.Star);
            handler.AssertRule<SmartViewStringRule>(
                0, 1, 2,
                SmartViewMatchType.Any,
                SmartViewField.Title,
                SmartViewFilter.BeginsWith,
                r => r.Value == "e");
            handler.AssertRule<SmartViewStringRule>(
                1, 0, 1,
                SmartViewMatchType.Any,
                SmartViewField.Note,
                SmartViewFilter.EndsWith,
                r => r.Value == "a");
        }
コード例 #2
0
ファイル: SmartViewTest.cs プロジェクト: yaneshtyagi/2day
        public void Rules_1_block_1()
        {
            var handler = SmartViewHandler.FromString("(Priority Is Star)");

            handler.AssertContent(1, SmartViewMatchType.Any);

            handler.AssertRule<SmartViewPriorityRule>(
                0, 0, 1,
                SmartViewMatchType.Any,
                SmartViewField.Priority,
                SmartViewFilter.Is,
                r => r.Value == TaskPriority.Star);
        }
コード例 #3
0
ファイル: SmartViewTest.cs プロジェクト: yaneshtyagi/2day
        public void ContextIs_With_Space()
        {
            var handler = SmartViewHandler.FromString("(Context Is context 1 with special name)");

            handler.AssertContent(1, SmartViewMatchType.Any);

            handler.AssertRule<SmartViewContextRule>(
                0, 0, 1,
                SmartViewMatchType.Any,
                SmartViewField.Context,
                SmartViewFilter.Is,
                r => r.Value == "context 1 with special name");
        }
コード例 #4
0
ファイル: SmartViewTest.cs プロジェクト: yaneshtyagi/2day
        public void FolderIs_With_Spaces()
        {
            var handler = SmartViewHandler.FromString("(Folder Is folder 1 with special name)");

            handler.AssertContent(1, SmartViewMatchType.Any);

            handler.AssertRule<SmartViewFolderRule>(
                0, 0, 1,
                SmartViewMatchType.Any,
                SmartViewField.Folder,
                SmartViewFilter.Is,
                r => r.Value == "folder 1 with special name");
        }
コード例 #5
0
        protected async void LoadStringAsync(string content)
        {
            Exception exception = null;

            try
            {
                var handler = SmartViewHandler.FromString(content);
                foreach (var block in handler.Blocks)
                {
                    var blockViewModel = new SmartViewBlockViewModel(this);

                    foreach (var rule in block.Rules)
                    {
                        var ruleViewModel = new SmartViewRuleViewModel(blockViewModel)
                        {
                            SelectedField  = rule.Field,
                            SelectedFilter = rule.Filter,
                            Value          = this.CreateValueViewModel(rule.Filter, rule.Field, rule.Value)
                        };

                        blockViewModel.Rules.Add(ruleViewModel);
                    }
                    if (block.Match == SmartViewMatchType.All)
                    {
                        blockViewModel.MatchAnd = true;
                    }
                    else
                    {
                        blockViewModel.MatchOr = true;
                    }

                    this.blocks.Add(blockViewModel);
                }
                this.matchType = handler.Match;
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            if (exception != null)
            {
                await this.messageBoxService.ShowAsync(StringResources.Message_Warning, string.Format(StringResources.SmartView_MessageCannotLoadFormat, exception));
            }
        }
コード例 #6
0
ファイル: SmartViewTest.cs プロジェクト: yaneshtyagi/2day
        public static T AssertRule<T>(this SmartViewHandler handler, int block, int rule, int ruleCount, SmartViewMatchType type, SmartViewField field, SmartViewFilter filter, Func<T, bool> checkRule)
            where T : SmartViewRule
        {
            SmartViewBlockRule smartViewBlockRule = handler.Blocks[block];

            Assert.AreEqual(ruleCount, smartViewBlockRule.Rules.Count);
            Assert.AreEqual(type, smartViewBlockRule.Match);            

            SmartViewRule smartViewRule = smartViewBlockRule.Rules[rule];

            Assert.AreEqual(field, smartViewRule.Field);
            Assert.AreEqual(filter, smartViewRule.Filter);

            SmartViewRule item = smartViewRule;
            Assert.IsTrue(item is T);

            Assert.IsTrue(checkRule((T) item));

            return (T) item;
        }
コード例 #7
0
ファイル: SmartViewTest.cs プロジェクト: yaneshtyagi/2day
        public void Custom1()
        {
            var handler = SmartViewHandler.FromString("(Due DoesNotExist 0) AND (Context IsNot @context)");

            handler.AssertContent(2, SmartViewMatchType.All);

            handler.AssertRule<SmartViewDateRule>(
                0, 0, 1,
                SmartViewMatchType.Any,
                SmartViewField.Due,
                SmartViewFilter.DoesNotExist,
                r => !r.Value.Date.HasValue);

            handler.AssertRule<SmartViewContextRule>(
                1, 0, 1,
                SmartViewMatchType.Any,
                SmartViewField.Context,
                SmartViewFilter.IsNot,
                r => r.Value == "@context");
        }
コード例 #8
0
ファイル: SmartViewTest.cs プロジェクト: yaneshtyagi/2day
        public void Rules_1_block_2()
        {
            var handler = SmartViewHandler.FromString("(Priority Is Star) AND (Due WasInTheLast 120)");

            handler.AssertContent(2, SmartViewMatchType.All);
            
            handler.AssertRule<SmartViewPriorityRule>(
                0, 0, 1,
                SmartViewMatchType.Any, 
                SmartViewField.Priority, 
                SmartViewFilter.Is, 
                r => r.Value == TaskPriority.Star);

            handler.AssertRule<SmartViewDateRule>(
                1, 0, 1,
                SmartViewMatchType.Any, 
                SmartViewField.Due, 
                SmartViewFilter.WasInTheLast, 
                r => r.Value.Days == 120);
        }
コード例 #9
0
ファイル: SmartViewTest.cs プロジェクト: yaneshtyagi/2day
 public void Invalid4()
 {
     var handler = SmartViewHandler.FromString("(Priority Is Star OR Title BeginsWith e AND Title BeginsWith f) AND (Note EndsWith a)");
 }
コード例 #10
0
ファイル: SmartViewTest.cs プロジェクト: yaneshtyagi/2day
 public void Invalid3()
 {
     var handler = SmartViewHandler.FromString("(Priority Is Star) AND");
 }
コード例 #11
0
ファイル: SmartViewTest.cs プロジェクト: yaneshtyagi/2day
 public void Invalid2()
 {
     var handler = SmartViewHandler.FromString("Priority Is Star)");
 }
コード例 #12
0
ファイル: SmartViewTest.cs プロジェクト: yaneshtyagi/2day
 public static void AssertContent(this SmartViewHandler handler, int blockCount,SmartViewMatchType type)
 {
     Assert.AreEqual(blockCount, handler.Blocks.Count);
     Assert.AreEqual(type, handler.Match);            
 }
コード例 #13
0
ファイル: SmartViewTest.cs プロジェクト: yaneshtyagi/2day
 public void Empty()
 {
     var handler = SmartViewHandler.FromString(string.Empty);
 }