public void Complex2()
        {
            var termA = new FilterTerm(WorkitemToDo);

            termA.Greater(5);

            var termB = new FilterTerm(WorkitemToDo);

            termB.Less(10);

            var termC = new FilterTerm(WorkitemToDo);

            termC.GreaterOrEqual(20);

            var termD = new FilterTerm(WorkitemToDo);

            termD.LessOrEqual(30);

            var and1 = new AndFilterTerm(termA, termB);
            var and2 = new AndFilterTerm(termC, termD);

            var o = new OrFilterTerm(and1, and2);

            Assert.AreEqual("((Workitem.ToDo>'5';Workitem.ToDo<'10')|(Workitem.ToDo>='20';Workitem.ToDo<='30'))",
                            o.Token);
        }
        public GroupFilterTerm GetFilter(IAssetType type)
        {
            var terms = new List <IFilterTerm>();

            foreach (var value in values)
            {
                var term = new FilterTerm(type.GetAttributeDefinition(Name));

                switch (value.Action)
                {
                case FilterValuesActions.Equal:
                    term.Equal(value.Value);
                    break;

                case FilterValuesActions.NotEqual:
                    term.NotEqual(value.Value);
                    break;

                case FilterValuesActions.Greater:
                    term.Greater(value.Value);
                    break;

                default:
                    throw new NotSupportedException();
                }

                terms.Add(term);
            }

            return(Operation == FilterActions.And ? (GroupFilterTerm) new AndFilterTerm(terms.ToArray()) : new OrFilterTerm(terms.ToArray()));
        }
Example #3
0
        public void QueryStoryByChangeDate()
        {
            const int millisecondOffset = 5;

            var storyAsset = CreateDisposableStory(InitialStoryName, "Scope:0");

            storyAsset = GetAssetsByOid(storyAsset.Oid.Momentless, attributesToQuery)[0];
            var changeDate = (DateTime)storyAsset.GetAttribute(changeDateDef).Value;

            if (changeDate.Millisecond < millisecondOffset)
            {
                Assert.Ignore("Querying items by date with high precision does not make sense because seconds number will be changed by offset");
            }

            var dateTerm = new FilterTerm(changeDateDef);

            dateTerm.Greater(changeDate.AddMilliseconds(-millisecondOffset));
            var stories = GetStoryAssets(dateTerm);

            Assert.IsTrue(stories.Any(x => x.Oid.Momentless.Equals(storyAsset.Oid.Momentless)));

            dateTerm = new FilterTerm(changeDateDef);
            dateTerm.Less(changeDate.AddMilliseconds(-millisecondOffset));
            stories = GetStoryAssets(dateTerm);
            Assert.IsFalse(stories.Any(x => x.Oid.Momentless.Equals(storyAsset.Oid.Momentless)));
        }
		public void SingleNestedTerm() {
			var f1 = new FilterTerm(WorkitemToDo);
			f1.Greater(5);
			var o1 = new OrFilterTerm(f1);
			var o2 = new OrFilterTerm();
			var a1 = new AndFilterTerm(o1, o2);
			var a2 = new AndFilterTerm(a1);

			Assert.AreEqual("Workitem.ToDo>'5'", a2.Token);
		}
        public void SingleNestedTerm()
        {
            var f1 = new FilterTerm(WorkitemToDo);

            f1.Greater(5);
            var o1 = new OrFilterTerm(f1);
            var o2 = new OrFilterTerm();
            var a1 = new AndFilterTerm(o1, o2);
            var a2 = new AndFilterTerm(a1);

            Assert.AreEqual("Workitem.ToDo>'5'", a2.Token);
        }
Example #6
0
        public void QueryStoryChangesWithInequalityFilter()
        {
            var storyAsset = CreateDisposableStory(InitialStoryName, "Scope:0");

            storyAsset = GetAssetsByOid(storyAsset.Oid.Momentless, attributesToQuery)[0];
            var moment1 = storyAsset.GetAttribute(momentDef).Value;

            storyAsset.SetAttributeValue(nameDef, ChangedStoryName);
            services.Save(storyAsset);

            storyAsset.SetAttributeValue(nameDef, FinalStoryName);
            services.Save(storyAsset);
            storyAsset = GetAssetsByOid(storyAsset.Oid.Momentless, attributesToQuery)[0];
            var moment3 = storyAsset.GetAttribute(momentDef).Value;

            var filter = new FilterTerm(momentDef);

            filter.GreaterOrEqual(moment1);
            var assets = GetAssetsByOid(storyAsset.Oid.Momentless, attributesToQuery, filter, true);

            Assert.AreEqual(3, assets.Count);
            Assert.IsTrue(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(InitialStoryName)));
            Assert.IsTrue(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(ChangedStoryName)));
            Assert.IsTrue(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(FinalStoryName)));

            filter = new FilterTerm(momentDef);
            filter.Greater(moment1);
            assets = GetAssetsByOid(storyAsset.Oid.Momentless, attributesToQuery, filter, true);
            Assert.AreEqual(2, assets.Count);
            Assert.IsFalse(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(InitialStoryName)));
            Assert.IsTrue(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(ChangedStoryName)));
            Assert.IsTrue(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(FinalStoryName)));

            var lessFilter = new FilterTerm(momentDef);

            lessFilter.Less(moment3);
            var greaterFilter = new FilterTerm(momentDef);

            greaterFilter.Greater(moment1);
            var groupFilter = new AndFilterTerm(lessFilter, greaterFilter);

            assets = GetAssetsByOid(storyAsset.Oid.Momentless, attributesToQuery, groupFilter, true);
            Assert.AreEqual(1, assets.Count);
            Assert.IsFalse(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(InitialStoryName)));
            Assert.IsTrue(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(ChangedStoryName)));
            Assert.IsFalse(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(FinalStoryName)));
        }
        public void DatePrecision()
        {
            var date = new DateTime(2012, 6, 21, 15, 17, 53, 504);
            var changeDateAttribute = new MockAttributeDefinition("ChangeDate");

            var query = new Query(new MockAssetType());

            query.Selection.Add(new MockAttributeDefinition("Name"));
            var filter = new FilterTerm(changeDateAttribute);

            filter.Greater(date);
            var builder = new QueryURLBuilder(query);

            query.Filter = filter;

            var queryString = builder.ToString();

            Assert.AreEqual("Data/Mock?sel=Mock.Name&where=Mock.ChangeDate>'2012-06-21T15%3a17%3a53.504'", queryString);
        }
		public void Complex2() {
			var termA = new FilterTerm(WorkitemToDo);
			termA.Greater(5);

			var termB = new FilterTerm(WorkitemToDo);
			termB.Less(10);

			var termC = new FilterTerm(WorkitemToDo);
			termC.GreaterOrEqual(20);

			var termD = new FilterTerm(WorkitemToDo);
			termD.LessOrEqual(30);

			var and1 = new AndFilterTerm(termA, termB);
			var and2 = new AndFilterTerm(termC, termD);

			var o = new OrFilterTerm(and1, and2);

			Assert.AreEqual("((Workitem.ToDo>'5';Workitem.ToDo<'10')|(Workitem.ToDo>='20';Workitem.ToDo<='30'))",
							o.Token);
		}
		public void QueryStoryChangesWithInequalityFilter() {
			var storyAsset = CreateDisposableStory(InitialStoryName, "Scope:0");

			storyAsset = GetAssetsByOid(storyAsset.Oid.Momentless, attributesToQuery)[0];
			var moment1 = storyAsset.GetAttribute(momentDef).Value;

			storyAsset.SetAttributeValue(nameDef, ChangedStoryName);
			services.Save(storyAsset);

			storyAsset.SetAttributeValue(nameDef, FinalStoryName);
			services.Save(storyAsset);
			storyAsset = GetAssetsByOid(storyAsset.Oid.Momentless, attributesToQuery)[0];
			var moment3 = storyAsset.GetAttribute(momentDef).Value;

			var filter = new FilterTerm(momentDef);
			filter.GreaterOrEqual(moment1);
			var assets = GetAssetsByOid(storyAsset.Oid.Momentless, attributesToQuery, filter, true);
			Assert.AreEqual(3, assets.Count);
			Assert.IsTrue(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(InitialStoryName)));
			Assert.IsTrue(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(ChangedStoryName)));
			Assert.IsTrue(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(FinalStoryName)));

			filter = new FilterTerm(momentDef);
			filter.Greater(moment1);
			assets = GetAssetsByOid(storyAsset.Oid.Momentless, attributesToQuery, filter, true);
			Assert.AreEqual(2, assets.Count);
			Assert.IsFalse(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(InitialStoryName)));
			Assert.IsTrue(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(ChangedStoryName)));
			Assert.IsTrue(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(FinalStoryName)));

			var lessFilter = new FilterTerm(momentDef);
			lessFilter.Less(moment3);
			var greaterFilter = new FilterTerm(momentDef);
			greaterFilter.Greater(moment1);
			var groupFilter = new AndFilterTerm(lessFilter, greaterFilter);
			assets = GetAssetsByOid(storyAsset.Oid.Momentless, attributesToQuery, groupFilter, true);
			Assert.AreEqual(1, assets.Count);
			Assert.IsFalse(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(InitialStoryName)));
			Assert.IsTrue(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(ChangedStoryName)));
			Assert.IsFalse(assets.Any(x => x.GetAttribute(nameDef).Value.Equals(FinalStoryName)));
		}
		public void QueryStoryByChangeDate() {
			const int millisecondOffset = 5;

			var storyAsset = CreateDisposableStory(InitialStoryName, "Scope:0");

			storyAsset = GetAssetsByOid(storyAsset.Oid.Momentless, attributesToQuery)[0];
			var changeDate = (DateTime) storyAsset.GetAttribute(changeDateDef).Value;

			if(changeDate.Millisecond < millisecondOffset) {
				Assert.Ignore("Querying items by date with high precision does not make sense because seconds number will be changed by offset");
			}

			var dateTerm = new FilterTerm(changeDateDef);
			dateTerm.Greater(changeDate.AddMilliseconds(-millisecondOffset));
			var stories = GetStoryAssets(dateTerm);
			Assert.IsTrue(stories.Any(x => x.Oid.Momentless.Equals(storyAsset.Oid.Momentless)));

			dateTerm = new FilterTerm(changeDateDef);
			dateTerm.Less(changeDate.AddMilliseconds(-millisecondOffset));
			stories = GetStoryAssets(dateTerm);
			Assert.IsFalse(stories.Any(x => x.Oid.Momentless.Equals(storyAsset.Oid.Momentless)));
		}
		public void DatePrecision() {
			var date = new DateTime(2012, 6, 21, 15, 17, 53, 504);
			var changeDateAttribute = new MockAttributeDefinition("ChangeDate");

			var query = new Query(new MockAssetType());
			query.Selection.Add(new MockAttributeDefinition("Name"));
			var filter = new FilterTerm(changeDateAttribute);
			filter.Greater(date);
			var builder = new QueryURLBuilder(query);
			query.Filter = filter;

			var queryString = builder.ToString();
			Assert.AreEqual("Data/Mock?sel=Mock.Name&where=Mock.ChangeDate>'2012-06-21T15%3a17%3a53.504'", queryString);
		}