public void will_throw_if_CAPTCHA_validator_is_null() { var attribute = new ValidateSpamPreventionAttribute(); Assert.Throws <ArgumentNullException>(() => attribute.Authorize( new Mock <HttpContextBase>().Object, new ModelStateDictionary(), null)); }
public void will_throw_if_model_state_is_null() { var attribute = new ValidateSpamPreventionAttribute(); Assert.Throws <ArgumentNullException>(() => attribute.Authorize( new Mock <HttpContextBase>().Object, null, new Mock <ICaptchaValidator>().Object)); }
public void will_throw_if_HTTP_context_is_null() { var attribute = new ValidateSpamPreventionAttribute(); Assert.Throws <ArgumentNullException>(() => attribute.Authorize( null, new ModelStateDictionary(), new Mock <ICaptchaValidator>().Object)); }
public void will_consider_nocaptcha_invalid_when_response_is_missing() { var stubHttpContext = CreateHttpContext(noCaptchaChallenge: "1234"); var modelState = new ModelStateDictionary(); var attribute = new ValidateSpamPreventionAttribute(); attribute.Authorize( stubHttpContext.Object, modelState, new Mock <ICaptchaValidator>().Object); Assert.True(modelState.ContainsKey(Const.ModelStateKey)); }
public void will_add_a_model_state_error_when_both_the_nocaptcha_and_captcha_response_is_invalid() { var stubHttpContext = CreateHttpContext(); var modelState = new ModelStateDictionary(); var attribute = new ValidateSpamPreventionAttribute(); attribute.Authorize( stubHttpContext.Object, modelState, new Mock <ICaptchaValidator>().Object); Assert.True(modelState.ContainsKey(Const.ModelStateKey)); }
public void will_not_add_a_model_state_error_when_the_nocaptcha_response_is_valid() { var stubHttpContext = CreateHttpContext( noCaptchaChallenge: "1234", noCaptchaResponse: "4321"); var modelState = new ModelStateDictionary(); var attribute = new ValidateSpamPreventionAttribute(); attribute.Authorize( stubHttpContext.Object, modelState, new Mock <ICaptchaValidator>().Object); Assert.False(modelState.ContainsKey(Const.ModelStateKey)); }
public void will_not_add_a_model_state_error_when_the_nocaptcha_response_is_invalid_but_the_captcha_response_is_valid() { var stubHttpContext = CreateHttpContext(); var modelState = new ModelStateDictionary(); var stubCaptchaValiator = new Mock <ICaptchaValidator>(); stubCaptchaValiator.Setup(stub => stub.Validate(It.IsAny <HttpContextBase>())).Returns(true); var attribute = new ValidateSpamPreventionAttribute(); attribute.Authorize( stubHttpContext.Object, modelState, stubCaptchaValiator.Object); Assert.False(modelState.ContainsKey(Const.ModelStateKey)); }