Esempio n. 1
0
        /// <summary>
        /// Extracts label, partition key and identifier from the object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="element"></param>
        /// <param name="serializer"></param>
        /// <param name="id"></param>
        /// <param name="label"></param>
        /// <param name="pk"></param>
        /// <returns></returns>
        private static JObject ToJElement <T>(this T element, JsonSerializer serializer,
                                              out string id, out string label, out string pk)
        {
            var jelement = JObject.FromObject(element, serializer);

            id = jelement.GetValueOrDefault(DocumentProperties.IdKey,
                                            () => Guid.NewGuid().ToString());

            pk = jelement.GetValueOrDefault(DocumentProperties.PartitionKey,
                                            () => Guid.NewGuid().ToString());

            label = jelement.GetValueOrDefault(DocumentProperties.LabelKey,
                                               () => LabelCache.GetOrAdd(typeof(T), t => {
                var tattr = typeof(T).GetCustomAttribute <TypeNameAttribute>(true);
                if (tattr != null && tattr.Name != null)
                {
                    return(tattr.Name);
                }
                var lattr = typeof(T).GetCustomAttribute <LabelAttribute>(true);
                if (lattr != null && lattr.Name != null)
                {
                    return(lattr.Name);
                }
                return(typeof(T).Name.Substring(0, 1).ToLower() +
                       typeof(T).Name.Substring(1));
            }));
            return(jelement);
        }
        /// <inheritdoc />
        protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
        {
            var element = attributeBag.GetAdapter<Element>();
            if (element == null)
                throw new WatiNException("This constraint class can only be used to compare against an element");

            var cache = (LabelCache)context.GetData(this);
            if (cache == null)
            {
                cache = new LabelCache(labelText);
                context.SetData(this, cache);
            }

            return cache.IsMatch(element);
        }
Esempio n. 3
0
        /// <inheritdoc />
        protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
        {
            var element = attributeBag.GetAdapter <Element>();

            if (element == null)
            {
                throw new WatiNException("This constraint class can only be used to compare against an element");
            }

            var cache = (LabelCache)context.GetData(this);

            if (cache == null)
            {
                cache = new LabelCache(labelText);
                context.SetData(this, cache);
            }

            return(cache.IsMatch(element));
        }
Esempio n. 4
0
            protected override Func <Label> Given()
            {
                LabelCache.Reset();

                Queue <List <Label> > resultQueue = new Queue <List <Label> >();

                var label = new Label()
                {
                    ID    = 1,
                    Name  = "Bug",
                    Color = "Red"
                };

                var withValues = new List <Label>()
                {
                    label
                };

                var withoutValues = new List <Label>();

                resultQueue.Enqueue(withValues);
                resultQueue.Enqueue(withoutValues);

                var repository = new Mock <ICardRepository>();

                repository
                .Setup(r => r.FindAllLabels())
                .Returns(() => resultQueue.Dequeue());

                repository
                .Setup(r => r.DeleteLabel(It.Is <Label>(l => l.Name == "Bug")))
                .Returns(label);

                var factory = new Mock <DbFactory>();

                factory.Protected()
                .Setup <ICardRepository>("OnCreateDb")
                .Returns(repository.Object);

                new DbFactory(factory.Object);

                return(() => Label.Delete("bug"));
            }
Esempio n. 5
0
        public static NewsListModel BuildNews(DASEntities db)
        {
            NewsListModel model = new NewsListModel();


            int languageId = (int)HttpContext.Current.Session["lngId"];

            model.NewsList = db.News.Where(l => l.LanguageId == languageId && l.Archive == false).Select(n => new NewsModel()
            {
                NewsId = n.NewsId, Name = n.Name, Text = n.Text, Year = n.Year, Ord = n.Ord, Archive = n.Archive, LanguageId = n.LanguageId
            }).OrderByDescending(l => l.Year).ThenByDescending(l => l.Ord).ToList();

            IList <int> pomArch = db.News.Include("Archive").Where(l => l.LanguageId == languageId && l.Archive == true).Select(k => k.Archives.FirstOrDefault().ArchiveId).Distinct().ToList();

            string archiveLbl = LabelCache.GetLabel("Home", "lblArchive");
            string newsLbl    = LabelCache.GetLabel("Home", "lblNovosti");

            var list = db.Archives.OrderByDescending(l => l.Year).ToList();

            model.ArchiveList = new List <ArchiveModel>();
            foreach (var item in pomArch)
            {
                Archive temp = list.OrderByDescending(m => m.Year).FirstOrDefault(b => b.ArchiveId == item);
                model.ArchiveList.Add(new ArchiveModel()
                {
                    ArchiveId = temp.ArchiveId, Name = archiveLbl + " " + temp.Year
                });
            }

            model.ArchiveList.Add(new ArchiveModel()
            {
                ArchiveId = 0, Name = newsLbl
            });
            model.ArchiveList       = model.ArchiveList.OrderByDescending(m => m.ArchiveId).ToList();
            model.SelectedArchiveId = 0;

            return(model);
        }
Esempio n. 6
0
 public void ShouldCacheIsReset()
 {
     LabelCache.GetLabel("Red").Should().Be(null);
 }
Esempio n. 7
0
 public static string INIGroupLabel(string viewId, string elementId)
 {
     return(LabelCache.GetLabel(viewId, elementId));
 }
Esempio n. 8
0
 // TODO: label extractor
 public static string INIGroupLabel(this HtmlHelper helper, string viewId, string elementId)
 {
     return(LabelCache.GetLabel(viewId, elementId));
 }