public void Process_ShouldNotAdd_DataTabIndexAttribute_WhenTabIndexNull() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object); // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.IsFalse(_tagHelperOutputStub.Attributes.ContainsName("data-tabindex")); }
public void Process_ShouldThrow_ArgumentNullException() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object); // Act // Assert Assert.Throws <ArgumentNullException>(() => scriptTagHelper.Process(_contextStub, null)); }
public void Process_ShouldReady_FromSettings_OnlyOnce() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object); // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert _settingsMock.Verify(mock => mock.CurrentValue, Times.Once); }
public void Process_ShouldChangeTagTo_DivTag() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object); // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.AreEqual("div", _tagHelperOutputStub.TagName); }
public void Process_ShouldNotAdd_DataErrorCallbackAttribute_WhenErrorCallbackNullOrEmpty() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object); // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.IsFalse(_tagHelperOutputStub.Attributes.ContainsName("data-error-callback")); }
public void Process_ShouldAdd_SiteKeyAttribute() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object); // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.IsTrue(_tagHelperOutputStub.Attributes.ContainsName("data-sitekey")); Assert.AreEqual(SiteKey, _tagHelperOutputStub.Attributes["data-sitekey"].Value.ToString()); }
public void Process_ShouldAdd_RecaptchaClass() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object); // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.IsTrue(_tagHelperOutputStub.Attributes.ContainsName("class")); Assert.AreEqual("g-recaptcha", _tagHelperOutputStub.Attributes["class"].Value); }
public void Process_ShouldAdd_DataSizeAttribute() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object); // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.IsTrue(_tagHelperOutputStub.Attributes.ContainsName("data-size")); Assert.AreEqual(Size.Normal.ToString().ToLowerInvariant(), _tagHelperOutputStub.Attributes["data-size"].Value.ToString()); }
public void Process_ShouldChange_TagModeTo_StartTagAndEndTag() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object); _tagHelperOutputStub.TagMode = TagMode.SelfClosing; // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.AreEqual(TagMode.StartTagAndEndTag, _tagHelperOutputStub.TagMode); }
public void Process_ShouldOverrideExisting_SiteKeyAttribute() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object); _tagHelperOutputStub.Attributes.Add("data-sitekey", "false-key"); // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.AreEqual(1, _tagHelperOutputStub.Attributes.Count(attribute => attribute.Name == "data-sitekey")); Assert.AreEqual(SiteKey, _tagHelperOutputStub.Attributes["data-sitekey"].Value.ToString()); }
public void Process_ShouldAdd_DataErrorCallbackAttribute() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object) { ErrorCallback = "myCallback" }; // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.IsTrue(_tagHelperOutputStub.Attributes.ContainsName("data-error-callback")); Assert.AreEqual("myCallback", _tagHelperOutputStub.Attributes["data-error-callback"].Value.ToString()); }
public void Process_ShouldAdd_DataTabindexAttribute() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object) { TabIndex = 2 }; // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.IsTrue(_tagHelperOutputStub.Attributes.ContainsName("data-tabindex")); Assert.AreEqual(2, (int)_tagHelperOutputStub.Attributes["data-tabindex"].Value); }
public void Process_ShouldOverrideExisting_DataErrorCallbackAttribute() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object) { ErrorCallback = "myCallback" }; _tagHelperOutputStub.Attributes.Add("data-error-callback", "fake-callback"); // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.AreEqual(1, _tagHelperOutputStub.Attributes.Count(attribute => attribute.Name == "data-error-callback")); Assert.AreEqual("myCallback", _tagHelperOutputStub.Attributes["data-error-callback"].Value.ToString()); }
public void Process_ShouldAdd_RecaptchaClassAnd_KeepExistingClasses() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object); _tagHelperOutputStub.Attributes.Add("class", "container text-center"); // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); var classes = _tagHelperOutputStub.Attributes["class"].Value.ToString().Split(" ", StringSplitOptions.RemoveEmptyEntries); // Assert Assert.AreEqual(3, classes.Length); Assert.IsTrue(classes.Contains("g-recaptcha")); Assert.IsTrue(classes.Contains("text-center")); Assert.IsTrue(classes.Contains("container")); }
public void Process_ShouldOverrideExisting_DataTabIndexAttribute() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object) { TabIndex = 3 }; _tagHelperOutputStub.Attributes.Add("data-tabindex", "1"); // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.AreEqual(1, _tagHelperOutputStub.Attributes.Count(attribute => attribute.Name == "data-tabindex")); Assert.AreEqual(3, (int)_tagHelperOutputStub.Attributes["data-tabindex"].Value); }
public void Process_ShouldOverrideExisting_DataThemeAttribute() { // Arrange var scriptTagHelper = new RecaptchaTagHelper(_settingsMock.Object, _optionsMock.Object) { Theme = Theme.Dark }; _tagHelperOutputStub.Attributes.Add("data-theme", "light"); // Act scriptTagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.AreEqual(1, _tagHelperOutputStub.Attributes.Count(attribute => attribute.Name == "data-theme")); Assert.AreEqual(Theme.Dark.ToString().ToLowerInvariant(), _tagHelperOutputStub.Attributes["data-theme"].Value.ToString()); }
private TagHelperOutput ProcessTagHelper(RecaptchaService service, TagHelperAttributeList attributes, Action <RecaptchaTagHelper> config = null) { var tagHelper = new RecaptchaTagHelper(service); config?.Invoke(tagHelper); var tagHelperContext = new TagHelperContext( allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>(), uniqueId: "test"); var output = new TagHelperOutput( tagName: "doesntmatter", attributes: attributes, getChildContentAsync: (useCachedResult, encoder) => { return(Task.FromResult <TagHelperContent>(new DefaultTagHelperContent())); }); tagHelper.Process(tagHelperContext, output); return(output); }