public void DictionaryField_NoTranslationItemExists_ReturnDefaultValue(string path, string defaultValue) { //Arrange this.dictionaryPhraseRepository.GetItem(path, defaultValue).Returns(x => null); //Act var result = SitecoreExtensions.DictionaryField(null, path, defaultValue); //Assert result.ToHtmlString().Should().Be(defaultValue); }
public void Dictionary_Call_ReturnTranslationByPath(string path, string defaultValue, string translate) { //Arrange this.dictionaryPhraseRepository.Get(path, defaultValue).Returns(translate); //Act var result = SitecoreExtensions.Dictionary(null, path, defaultValue); //Assert result.Should().Be(translate); }
public void DictionaryField_TranslationItemExists_ReturnFieldRenderer(string path, string defaultValue, Item translateItem, [Substitute] SitecoreHelper sitecoreHelper) { //Arrange this.dictionaryPhraseRepository.GetItem(path, defaultValue).Returns(x => translateItem); sitecoreHelper.Field(Arg.Any <string>(), Arg.Any <Item>()).Returns(x => new HtmlString($"fieldId:{x.Arg<string>()} itemId:{x.Arg<Item>().ID}")); //Act var result = SitecoreExtensions.DictionaryField(sitecoreHelper, path, defaultValue); //Assert result.ToHtmlString().Should().Be($"fieldId:{{DDACDD55-5B08-405F-9E58-04F09AED640A}} itemId:{translateItem.ID}"); }
private bool isDelayPost(string userIP) { bool isDelay = false; using (var db = Factory.DbEntities) { try { SqlParameter paramMaxComment = new SqlParameter("@maxcomment", SitecoreExtensions.Dictionary(sitecoreHelper, "/Feature/Maybank Blog/Max Comment", "3")); SqlParameter paramDelayTime = new SqlParameter("@delayTime", SitecoreExtensions.Dictionary(sitecoreHelper, "/Feature/Maybank Blog/Delay Time", "00:03")); SqlParameter paramUserIP = new SqlParameter("@userIP", userIP); isDelay = Convert.ToBoolean(db.Database.SqlQuery <int>("exec sp_DELAY_BLOG_POST @maxcomment, @delayTime, @userIP", paramMaxComment, paramDelayTime, paramUserIP).FirstOrDefault()); } catch (Exception ex) { ErrorWebservice(ex.Message.ToString()); } return(isDelay); } }
public ActionResult PostComment(FormCollection formData) { Sitecore.Data.Items.Item blogItem = Sitecore.Context.Database.GetItem(Sitecore.Feature.Library.Helper.Variables.MaybankBlogItem); bool IsUseCaptcha = ((CheckboxField)blogItem.Fields[Sitecore.Feature.Library.Templates.BaseField.Fields.IsUseCaptcha]).Checked; string _userIP = string.Empty; GetIpValue(out _userIP); BlogComment blogComment = new BlogComment() { ID = Guid.NewGuid(), PageID = Request.Form["pageId"], PageDisplayName = Request.Form["pageName"], Username = Request.Form["username"], Email = Request.Form["email"], Comment = Request.Form["blogcomment"], CommentDate = DateTime.Now, UserIP = _userIP, isApproved = false, ApprovedDate = null, isDelete = false, DeletedDate = null }; if (IsUseCaptcha && !IsReCaptchValid()) { return(ErrorWebservice(SitecoreExtensions.Dictionary(sitecoreHelper, "/Feature/Maybank Blog/Invalid Captcha Error Message", "Google reCaptcha validation failed"))); } if (!isDelayPost(_userIP)) { this.Repository.PostComment(blogComment); } else { return(ErrorWebservice(SitecoreExtensions.Dictionary(sitecoreHelper, "/Feature/Maybank Blog/Excessive Request", "Excessive Request Attempts Detected"))); } return(Json(SuccessResponse(), JsonRequestBehavior.AllowGet)); }
public override void Process(HttpRequestArgs args) { if (Context.Database == null || Constants.SitesToIgnore.Contains(Context.Site.Name)) { return; } //Check if the context language (supplied by the URL/user) is in the list of available languages Language language = LanguageManager.GetLanguages(Context.Database).FirstOrDefault(x => x.Name == Context.Language.Name); if (language != null) { return; } //If the language is not available, redirect to the site default language 404 page for a graceful failure Context.Language = Language.Parse(Context.Site.Language); string notFoundPath = SitecoreExtensions.GetNotFoundPath(args.RequestUrl.LocalPath); HttpContext.Current.Response.Redirect(notFoundPath); HttpContext.Current.Response.Flush(); args.AbortPipeline(); }
public ActionResult SessionExpired() { return(ErrorWebservice(SitecoreExtensions.Dictionary(sitecoreHelper, SESSION_EXPIRED_DICTIONARY_PATH, "Sesi Anda telah habis, silahkan refresh halaman Anda!"))); }