public void Process_ShouldThrow_ArgumentNullException() { // Arrange var scriptTagHelper = new RecaptchaV3TagHelper(_settingsMock.Object, _tagHelperComponentManagerMock.Object); // Act // Assert Assert.Throws <ArgumentNullException>(() => scriptTagHelper.Process(_contextStub, null)); }
public void Process_ShouldChangeTag_ToButtonTag() { // Arrange var tagHelper = new RecaptchaV3TagHelper(_settingsMock.Object, _tagHelperComponentManagerMock.Object) { Callback = "submit", Action = "submit" }; // Act tagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.AreEqual("button", _tagHelperOutputStub.TagName); }
public void Process_ShouldAdd_DataActionAttribute() { // Arrange var tagHelper = new RecaptchaV3TagHelper(_settingsMock.Object, _tagHelperComponentManagerMock.Object) { Callback = "myCallback", Action = "submit" }; // Act tagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.IsTrue(_tagHelperOutputStub.Attributes.ContainsName("data-action")); Assert.AreEqual("submit", _tagHelperOutputStub.Attributes["data-action"].Value.ToString()); }
public void Process_ShouldAdd_RecaptchaClass() { // Arrange var tagHelper = new RecaptchaV3TagHelper(_settingsMock.Object, _tagHelperComponentManagerMock.Object) { Callback = "submit", Action = "submit" }; // Act tagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.IsTrue(_tagHelperOutputStub.Attributes.ContainsName("class")); Assert.AreEqual("g-recaptcha", _tagHelperOutputStub.Attributes["class"].Value); }
public void Process_ShouldAdd_CallbackScriptTagHelperComponent_WhenCallbackIsNullOrEmpty() { // Arrange var tag = new RecaptchaV3TagHelper(_settingsMock.Object, _tagHelperComponentManagerMock.Object) { Callback = null, FormId = "formId", Action = "submit" }; // Act tag.Process(_contextStub, _tagHelperOutputStub); // Assert _tagHelperComponentCollectionMock.Verify(); }
public void Process_ShouldChange_TagModeTo_StartTagAndEndTag() { // Arrange var tagHelper = new RecaptchaV3TagHelper(_settingsMock.Object, _tagHelperComponentManagerMock.Object) { Callback = "submit", Action = "submit" }; _tagHelperOutputStub.TagMode = TagMode.SelfClosing; // Act tagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.AreEqual(TagMode.StartTagAndEndTag, _tagHelperOutputStub.TagMode); }
public void Process_ShouldSet_CallbackToDefaultCallback_WhenCallbackIsNullOrEmpty() { // Arrange var formId = $"formId"; var tag = new RecaptchaV3TagHelper(_settingsMock.Object, _tagHelperComponentManagerMock.Object) { Callback = null, FormId = formId, Action = "submit" }; // Act tag.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.AreEqual(tag.Callback, $"submit{formId}"); }
public void Process_ShouldOverrideExisting_DataActionAttribute() { // Arrange var tagHelper = new RecaptchaV3TagHelper(_settingsMock.Object, _tagHelperComponentManagerMock.Object) { Callback = "myCallback", Action = "submit" }; _tagHelperOutputStub.Attributes.Add("data-action", "fake-action"); // Act tagHelper.Process(_contextStub, _tagHelperOutputStub); // Assert Assert.AreEqual(1, _tagHelperOutputStub.Attributes.Count(attribute => attribute.Name == "data-action")); Assert.AreEqual("submit", _tagHelperOutputStub.Attributes["data-action"].Value.ToString()); }
public void Process_ShouldAdd_RecaptchaClassAnd_KeepExistingClasses() { // Arrange var tagHelper = new RecaptchaV3TagHelper(_settingsMock.Object, _tagHelperComponentManagerMock.Object) { Callback = "submit", Action = "submit" }; _tagHelperOutputStub.Attributes.Add("class", "container text-center"); // Act tagHelper.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_ShouldThrow_InvalidOperationException_WhenActionIsNullOrEmpty() { // Arrange var nullCallbackTagHelper = new RecaptchaV3TagHelper(_settingsMock.Object, _tagHelperComponentManagerMock.Object) { FormId = "formId", Action = null }; var emptyCallbackTagHelper = new RecaptchaV3TagHelper(_settingsMock.Object, _tagHelperComponentManagerMock.Object) { FormId = "formId", Action = String.Empty }; // Act // Assert Assert.Throws <InvalidOperationException>(() => nullCallbackTagHelper.Process(_contextStub, _tagHelperOutputStub)); Assert.Throws <InvalidOperationException>(() => emptyCallbackTagHelper.Process(_contextStub, _tagHelperOutputStub)); }