public void ValidateInvalidBusinessIds(string businessId) { MockWebContext ctx = new MockWebContext(); ctx.ActionArguments.Add("code", businessId); var actExeContext = ctx.CreateActionExecutingContext(); ValidateRegExAttribute attr = new ValidateRegExAttribute("code", @"^[0-9]{7}-[0-9]{1}$"); attr.OnActionExecuting(actExeContext); actExeContext.HttpContext.Response.StatusCode.Should().Be((int)HttpStatusCode.BadRequest); }
public void ValidateValidBusinessIds(string businessId) { MockWebContext ctx = new MockWebContext(); ctx.ActionArguments.Add("code", businessId); var actExeContext = ctx.CreateActionExecutingContext(); ValidateRegExAttribute attr = new ValidateRegExAttribute("code", @"^[0-9]{7}-[0-9]{1}$"); attr.OnActionExecuting(actExeContext); // if everything is ok the status is not changed so default 0 value is the expected value and not http 200 actExeContext.HttpContext.Response.StatusCode.Should().Be(0); }
public void ShouldHandleKeyNameNotFound() { // the attribute should handle cases that the key is not found instead of code causing KeyNotFoundException // caller has no idea what key is missing // attribute implementation skips null values so it should also skip validation if the key is not found? // either way the Exception should be handled and return correct message and status code MockWebContext ctx = new MockWebContext(); ctx.ActionArguments.Add("code", "1234567-8"); var actExeContext = ctx.CreateActionExecutingContext(); ValidateRegExAttribute attr = new ValidateRegExAttribute("notfoundkeyname", @"^[0-9]{7}-[0-9]{1}$"); attr.OnActionExecuting(actExeContext); // if everything is ok the status is not changed so default 0 value is the expected value and not http 200 actExeContext.HttpContext.Response.StatusCode.Should().Be((int)HttpStatusCode.BadRequest); }