public void DoPopularTagTest() { MockManager.Init(); Mock restBuilderMock = MockManager.Mock <CollectionBuilder <PopularTag> >(Constructor.NotMocked); // set the expectation. restBuilderMock.ExpectAndReturn("GetElement", MockElement(ResourceNs + ".HotTagGetList.xml")); var query = from tag in context.Tags where tag.Period == TagPeriod.Day && tag.Count == 6 orderby tag.Text ascending select tag; int count = query.Count(); // see if the expected and returned value are same. Assert.IsTrue(count == 6); PopularTag firstTag = query.First(); Assert.IsTrue(firstTag.Score == 4); PopularTag lastTag = query.Last(); Assert.IsTrue(lastTag.Score == 10); MockManager.Verify(); }
/// <summary> /// Get popular tags assigned to a room. /// </summary> public static List <PopularTag> GetPopularTags(int tagLimit = 50) { using (var session = SessionFactoryBuilder.Instance.SessionFactory.OpenSession()) { TagData tagAlias = null; PopularTag popularTagAlias = null; return(session.QueryOver <TagData>(() => tagAlias) .Where(x => x.RoomId > 0) .SelectList(list => list .SelectGroup(() => tagAlias.Text).WithAlias(() => popularTagAlias.Tag) .SelectCount(() => tagAlias.RoomId).WithAlias(() => popularTagAlias.Quantity) ) .OrderByAlias(() => popularTagAlias.Quantity).Desc .TransformUsing(Transformers.AliasToBean <PopularTag>()) .Take(tagLimit) .List <PopularTag>() as List <PopularTag>); } }