Ejemplo n.º 1
0
 public void LocalText_TryGet_DoesntThrowIfNoLocalTextProvider()
 {
     using (new MunqContext())
     {
         LocalText.TryGet("Dummy");
     }
 }
Ejemplo n.º 2
0
        public void LocalText_TryGet_ReturnsTranslationFromRegistry()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();
                A.CallTo(() => registry.TryGet(A <string> ._, A <string> ._))
                .ReturnsLazily((string l, string k) => l + ":" + k);

                Dependency.Resolve <IDependencyRegistrar>().RegisterInstance(registry);

                string translation1 = LocalText.TryGet("Translation1").ToString();
                string translation2 = LocalText.TryGet("Translation2").ToString();
                string uiCulture    = Thread.CurrentThread.CurrentUICulture.Name;

                Assert.Equal(uiCulture + ":Translation1", translation1);
                Assert.Equal(uiCulture + ":Translation2", translation2);

                A.CallTo(() => registry.TryGet(A <string> ._, A <string> ._))
                .MustHaveHappened(Repeated.Exactly.Twice);

                A.CallTo(() => registry.TryGet(uiCulture, "Translation1"))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry.TryGet(uiCulture, "Translation2"))
                .MustHaveHappened(Repeated.Exactly.Once);
            }
        }
Ejemplo n.º 3
0
        public void LocalText_TryGet_UsesCurrentUICulture()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();
                Dependency.Resolve <IDependencyRegistrar>().RegisterInstance(registry);

                var oldCulture = Thread.CurrentThread.CurrentUICulture;
                try
                {
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo("tr-TR");
                    LocalText.TryGet("Dummy");

                    Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
                    LocalText.TryGet("Dummy");
                }
                finally
                {
                    Thread.CurrentThread.CurrentUICulture = oldCulture;
                }

                A.CallTo(() => registry.TryGet(A <string> ._, A <string> ._))
                .MustHaveHappened(Repeated.Exactly.Twice);

                A.CallTo(() => registry.TryGet("tr-TR", "Dummy"))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry.TryGet("en-GB", "Dummy"))
                .MustHaveHappened(Repeated.Exactly.Once);
            }
        }
Ejemplo n.º 4
0
        private ReportColumn FromPropertyItem(PropertyItem item, Field field)
        {
            var result = new ReportColumn();

            result.Name  = item.Name;
            result.Title = item.Title ?? item.Name;
            if (result.Title != null)
            {
                result.Title = LocalText.TryGet(result.Title) ?? result.Title;
            }

            if (item.Width != null)
            {
                result.Width = item.Width;
            }

            if (!string.IsNullOrWhiteSpace(item.DisplayFormat))
            {
                result.Format = item.DisplayFormat;
            }
            else
            {
                var dtf = field as DateTimeField;
                if (!ReferenceEquals(null, dtf) &&
                    dtf.DateTimeKind != DateTimeKind.Unspecified)
                {
                    result.Format = "dd/MM/yyyy HH:mm";
                }
                else if (!ReferenceEquals(null, dtf))
                {
                    result.Format = "dd/MM/yyyy";
                }
            }

            var enumField = field as IEnumTypeField;

            if (enumField != null && enumField.EnumType != null)
            {
                result.Decorator = new EnumDecorator(enumField.EnumType);
            }

            if (!ReferenceEquals(null, field))
            {
                if (result.Title == null)
                {
                    result.Title = field.Title;
                }

                if (result.Width == null && field is StringField && field.Size != 0)
                {
                    result.Width = field.Size;
                }
            }

            result.DataType = !ReferenceEquals(null, field) ? field.ValueType : null;

            return(result);
        }
Ejemplo n.º 5
0
        public void LocalText_TryGet_ReturnsNullIfNoLocalTextProvider()
        {
            using (new MunqContext())
            {
                Assert.Null(LocalText.TryGet("Dummy"));

                Assert.Null(LocalText.TryGet(null));

                Assert.Null(LocalText.TryGet(String.Empty));
            }
        }
Ejemplo n.º 6
0
        public void LocalText_TryGet_UsesRegisteredLocalTextRegistry()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();
                Dependency.Resolve <IDependencyRegistrar>().RegisterInstance(registry);

                LocalText.TryGet("Dummy");

                A.CallTo(() => registry.TryGet(A <string> ._, A <string> ._))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry.TryGet(A <string> ._, "Dummy"))
                .MustHaveHappened(Repeated.Exactly.Once);
            }
        }
Ejemplo n.º 7
0
        public static string GetReportCategoryTitle(string key)
        {
            var title = LocalText.TryGet("Report.Category." + key.Replace("/", "."));

            if (title == null)
            {
                key = key ?? "";
                var idx = key.LastIndexOf('/');
                if (idx >= 0 && idx < key.Length - 1)
                {
                    key = key.Substring(idx + 1);
                }
                return(key);
            }

            return(title);
        }
Ejemplo n.º 8
0
        #pragma warning restore 1998
#line 3 "D:\Users\tamir\Source\Repos\SereneApp\SereneApp.Web\Views\Shared\LeftNavigation.cshtml"

        public HtmlString renderItem(Serenity.Navigation.NavigationItem item, int depth, int[] path)
        {
            var isactive = true;

            for (var i = 0; i <= depth; i++)
            {
                if (path[i] != Model.ActivePath[i])
                {
                    isactive = false;
                    break;
                }
            }

            var klass = (isactive ? "active" : "") + (item.Children.IsEmptyOrNull() ? "" : " treeview");

            if (!string.IsNullOrEmpty(item.ItemClass))
            {
                klass = (klass + " " + item.ItemClass).Trim();
            }
            var icon       = (item.IconClass ?? (item.Children.Count > 0 ? "icon-layers" : (depth == 0 ? "icon-link" : "fa-circle-o")));
            var title      = (LocalText.TryGet("Navigation." + item.FullPath) ?? item.Title);
            var sectionUrl = (item.Url ?? "javascript:;");
            var target     = item.Target; if (target != null)
            {
                target += " target=" + target;
            }

            var sb = new System.Text.StringBuilder();

            sb.Append("<li class='" + klass + "'><a href='" + HtmlEncoder.Encode(sectionUrl) + "' " + target + ">" +
                      "<i class='nav-icon fa " + icon + "'></i><span>" + HtmlEncoder.Encode(title) + "</span>" + (!item.Children.IsEmptyOrNull() ? "<i class='fa fa-angle-left pull-right'></i>" : "") + "</a>");

            if (item.Children.Count > 0)
            {
                sb.Append("<ul class='treeview-menu'>");
                path[depth + 1] = 0;
                foreach (var child in item.Children)
                {
                    sb.Append(renderItem(child, depth + 1, path).ToString());
                }
                sb.Append("</ul>");
            }
            sb.Append("</li>");
            path[depth]++;
            return(new HtmlString(sb.ToString()));
        }
        internal static void ValidateUniqueConstraint(ISaveRequestHandler handler, IEnumerable <Field> fields,
                                                      string errorMessage = null, BaseCriteria groupCriteria = null)
        {
            if (handler.IsUpdate && !fields.Any(x => x.IndexCompare(handler.Old, handler.Row) != 0))
            {
                return;
            }

            var criteria = groupCriteria ?? Criteria.Empty;

            foreach (var field in fields)
            {
                if (field.IsNull(handler.Row))
                {
                    criteria &= field.IsNull();
                }
                else
                {
                    criteria &= field == new ValueCriteria(field.AsObject(handler.Row));
                }
            }

            var idField = (Field)((IIdRow)handler.Row).IdField;

            if (handler.IsUpdate)
            {
                criteria &= (Field)idField != new ValueCriteria(idField.AsObject(handler.Old));
            }

            var row = handler.Row.CreateNew();

            if (new SqlQuery()
                .Dialect(handler.Connection.GetDialect())
                .From(row)
                .Select("1")
                .Where(criteria)
                .Exists(handler.UnitOfWork.Connection))
            {
                throw new ValidationError("UniqueViolation",
                                          String.Join(", ", fields.Select(x => x.PropertyName ?? x.Name)),
                                          String.Format(!string.IsNullOrEmpty(errorMessage) ?
                                                        (LocalText.TryGet(errorMessage) ?? errorMessage) :
                                                        LocalText.Get("Validation.UniqueConstraint"),
                                                        String.Join(", ", fields.Select(x => x.Title))));
            }
        }
Ejemplo n.º 10
0
        public static string FormatEnum(Type enumType, object value)
        {
            if (value == null)
            {
                return(String.Empty);
            }

            if (enumType != null &&
                enumType.IsEnum &&
                System.Enum.GetName(enumType, value) != null)
            {
                var typeName = enumType.Name;
                var enumName = System.Enum.GetName(enumType, value);
                var key      = "Enums." + typeName + "." + enumName;
                var text     = LocalText.TryGet(key);
                if (text == null)
                {
                    var memInfo = enumType.GetMember(enumName);
                    if (memInfo != null && memInfo.Length == 1)
                    {
                        var attributes = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
                        if (attributes.Length > 0)
                        {
                            text = ((DescriptionAttribute)attributes[0]).Description;
                            LocalText.Add(new List <LocalText.Entry>
                            {
                                new LocalText.Entry(LocalText.DefaultLanguageID, key, text)
                            }, false);
                        }
                    }
                }

                return(text ?? enumName);
            }
            else
            {
                return(value.ToString());
            }
        }
Ejemplo n.º 11
0
        public static List <string[]> GetEnumOptionList(Type enumType, string enumKey)
        {
            if (enumType == null)
            {
                throw new ArgumentNullException("enumType");
            }

            if (!enumType.IsEnum &&
                !enumType.IsSubclassOf(typeof(DataEnum)))
            {
                throw new ArgumentOutOfRangeException("enumType");
            }

            var list = new List <string[]>();

            if (enumType.IsEnum)
            {
                foreach (var p in System.Enum.GetValues(enumType))
                {
                    string key     = System.Enum.GetName(enumType, p);
                    string textKey = "Enums." + enumKey + "." + key;
                    string text    = LocalText.TryGet(textKey) ?? textKey;
                    list.Add(new string[] { Convert.ToInt32(p).ToInvariant(), text });
                }
            }
            else
            {
                foreach (var p in DataEnumCache.EnumType(enumKey).InDisplayOrder)
                {
                    string key     = p.ValueKey;
                    string textKey = "Enums." + enumKey + "." + key;
                    string text    = LocalText.TryGet(textKey) ?? textKey;
                    list.Add(new string[] { p.ValueId.ToInvariant(), text });
                }
            }

            return(list);
        }
Ejemplo n.º 12
0
        public void LocalText_TryGet_ReturnsNullIfNoTranslationIsFound()
        {
            using (new MunqContext())
            {
                const string key = "Db.MissingTable.MissingField";

                var registry = A.Fake <ILocalTextRegistry>();
                A.CallTo(() => registry.TryGet(A <string> ._, A <string> ._))
                .Returns(null);

                Dependency.Resolve <IDependencyRegistrar>().RegisterInstance(registry);

                var translation = LocalText.TryGet(key);

                Assert.Null(translation);

                A.CallTo(() => registry.TryGet(A <string> ._, A <string> ._))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry.TryGet(A <string> ._, key))
                .MustHaveHappened(Repeated.Exactly.Once);
            }
        }
Ejemplo n.º 13
0
        protected virtual void ValidateUniqueConstraint(IEnumerable <Field> fields,
                                                        string errorMessage = null, BaseCriteria groupCriteria = null)
        {
            if (IsUpdate && !fields.Any(x => x.IndexCompare(Old, Row) != 0))
            {
                return;
            }

            var criteria = groupCriteria ?? Criteria.Empty;

            foreach (var field in fields)
            {
                if (field.IsNull(Row))
                {
                    criteria &= field.IsNull();
                }
                else
                {
                    criteria &= field == new ValueCriteria(field.AsObject(Row));
                }
            }

            if (IsUpdate)
            {
                criteria &= (Field)Row.IdField != Row.IdField[Old].Value;
            }

            if (Connection.Exists <TRow>(criteria))
            {
                throw new ValidationError("UniqueViolation",
                                          String.Join(", ", fields.Select(x => x.PropertyName ?? x.Name)),
                                          String.Format(!string.IsNullOrEmpty(errorMessage) ?
                                                        (LocalText.TryGet(errorMessage) ?? errorMessage) :
                                                        LocalText.Get("Validation.UniqueViolation"),
                                                        String.Join(", ", fields.Select(x => x.Title))));
            }
        }
Ejemplo n.º 14
0
 public void LocalText_TryGet_ReturnsNullIfKeyIsEmpty()
 {
     Assert.Null(LocalText.TryGet(String.Empty));
 }
Ejemplo n.º 15
0
 public static string GetEntitySingular(string table)
 {
     return(LocalText.TryGet("Db." + table + ".EntitySingular") ?? table);
 }
Ejemplo n.º 16
0
 public static string ToYesNo(this bool?inputValue)
 {
     return(inputValue == true?LocalText.TryGet("Dialogs.YesButton") ?? "Yes" : LocalText.TryGet("Dialogs.NoButton") ?? "No");
 }
Ejemplo n.º 17
0
 public void LocalText_TryGet_ReturnsNullIfKeyIsNull()
 {
     Assert.Null(LocalText.TryGet(null));
 }